-
Notifications
You must be signed in to change notification settings - Fork 0
/
browserstack-mocha-export.mjs
79 lines (68 loc) · 2.26 KB
/
browserstack-mocha-export.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import codeExport from '@seleniumhq/code-export-javascript-mocha';
import { codeExport as exporter } from '@seleniumhq/side-utils'
var emitters = codeExport.opts.emitter.emitters
async function emitSetWindowSize(size) {
const [width, height] = size.split('x');
return Promise.resolve(`
if(!(await driver.getCapabilities()).get("device") && !(await driver.getCapabilities()).get("deviceName"))
{await driver.manage().window().setRect({width: ${width}, height: ${height}})}
`);
}
emitters['setWindowSize'] = emitSetWindowSize;
function beforeEach() {
const params = {
startingSyntax: ({ capabilities, gridUrl } = {}) => ({
commands: [
{ level: 0, statement: 'beforeEach(async function() {' },
{
level: 1,
statement: `driver = await new Builder()
.withCapabilities(${JSON.stringify(capabilities)})
.usingServer('${gridUrl}')
.build()`,
},
{
level: 1, statement: `if(process.env.BS_A11Y_TEST_RUN_ID)
{await driver.sleep(3000);}`
},
{ level: 1, statement: 'vars = {}' },
],
}),
endingSyntax: {
commands: [{ level: 0, statement: '})' }],
},
}
return params
}
codeExport.opts.hooks.beforeEach = new exporter.hook(beforeEach())
function declareVariables() {
const params = {
startingSyntax: {
commands: [
{
level: 0,
statement: `this.timeout(process.env.testTimeout)`,
},
{
level: 0,
statement: `let driver`,
},
{
level: 0,
statement: 'let vars',
},
],
},
}
return params
}
codeExport.opts.hooks.declareVariables = new exporter.hook(declareVariables())
function generateTestDeclaration(name) {
return `it('${name}', async function() {`
}
codeExport.opts.generateTestDeclaration = generateTestDeclaration
function generateSuiteDeclaration(name) {
return `describe('TestCase', function() {`
}
codeExport.opts.generateSuiteDeclaration = generateSuiteDeclaration
export default codeExport