@seleniumhq/code-export-javascript-mocha 3.17.2 → 4.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/command.js CHANGED
@@ -1,18 +1,4 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = exports.emitters = void 0;
7
-
8
- var _sideUtils = require("@seleniumhq/side-utils");
9
-
10
- var _location = _interopRequireDefault(require("./location"));
11
-
12
- var _selection = _interopRequireDefault(require("./selection"));
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
2
  // Licensed to the Software Freedom Conservancy (SFC) under one
17
3
  // or more contributor license agreements. See the NOTICE file
18
4
  // distributed with this work for additional information
@@ -29,931 +15,771 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
29
15
  // KIND, either express or implied. See the License for the
30
16
  // specific language governing permissions and limitations
31
17
  // under the License.
32
- const emitters = {
33
- addSelection: emitSelect,
34
- answerOnNextPrompt: skip,
35
- assert: emitAssert,
36
- assertAlert: emitAssertAlert,
37
- assertChecked: emitVerifyChecked,
38
- assertConfirmation: emitAssertAlert,
39
- assertEditable: emitVerifyEditable,
40
- assertElementPresent: emitVerifyElementPresent,
41
- assertElementNotPresent: emitVerifyElementNotPresent,
42
- assertNotChecked: emitVerifyNotChecked,
43
- assertNotEditable: emitVerifyNotEditable,
44
- assertNotSelectedValue: emitVerifyNotSelectedValue,
45
- assertNotText: emitVerifyNotText,
46
- assertPrompt: emitAssertAlert,
47
- assertSelectedLabel: emitVerifySelectedLabel,
48
- assertSelectedValue: emitVerifyValue,
49
- assertValue: emitVerifyValue,
50
- assertText: emitVerifyText,
51
- assertTitle: emitVerifyTitle,
52
- check: emitCheck,
53
- chooseCancelOnNextConfirmation: skip,
54
- chooseCancelOnNextPrompt: skip,
55
- chooseOkOnNextConfirmation: skip,
56
- click: emitClick,
57
- clickAt: emitClick,
58
- close: emitClose,
59
- debugger: skip,
60
- do: emitControlFlowDo,
61
- doubleClick: emitDoubleClick,
62
- doubleClickAt: emitDoubleClick,
63
- dragAndDropToObject: emitDragAndDrop,
64
- echo: emitEcho,
65
- editContent: emitEditContent,
66
- else: emitControlFlowElse,
67
- elseIf: emitControlFlowElseIf,
68
- end: emitControlFlowEnd,
69
- executeScript: emitExecuteScript,
70
- executeAsyncScript: emitExecuteAsyncScript,
71
- forEach: emitControlFlowForEach,
72
- if: emitControlFlowIf,
73
- mouseDown: emitMouseDown,
74
- mouseDownAt: emitMouseDown,
75
- mouseMove: emitMouseMove,
76
- mouseMoveAt: emitMouseMove,
77
- mouseOver: emitMouseMove,
78
- mouseOut: emitMouseOut,
79
- mouseUp: emitMouseUp,
80
- mouseUpAt: emitMouseUp,
81
- open: emitOpen,
82
- pause: emitPause,
83
- removeSelection: emitSelect,
84
- repeatIf: emitControlFlowRepeatIf,
85
- run: emitRun,
86
- runScript: emitRunScript,
87
- select: emitSelect,
88
- selectFrame: emitSelectFrame,
89
- selectWindow: emitSelectWindow,
90
- sendKeys: emitSendKeys,
91
- setSpeed: emitSetSpeed,
92
- setWindowSize: emitSetWindowSize,
93
- store: emitStore,
94
- storeAttribute: emitStoreAttribute,
95
- storeJson: emitStoreJson,
96
- storeText: emitStoreText,
97
- storeTitle: emitStoreTitle,
98
- storeValue: emitStoreValue,
99
- storeWindowHandle: emitStoreWindowHandle,
100
- storeXpathCount: emitStoreXpathCount,
101
- submit: emitSubmit,
102
- times: emitControlFlowTimes,
103
- type: emitType,
104
- uncheck: emitUncheck,
105
- verify: emitAssert,
106
- verifyChecked: emitVerifyChecked,
107
- verifyEditable: emitVerifyEditable,
108
- verifyElementPresent: emitVerifyElementPresent,
109
- verifyElementNotPresent: emitVerifyElementNotPresent,
110
- verifyNotChecked: emitVerifyNotChecked,
111
- verifyNotEditable: emitVerifyNotEditable,
112
- verifyNotSelectedValue: emitVerifyNotSelectedValue,
113
- verifyNotText: emitVerifyNotText,
114
- verifySelectedLabel: emitVerifySelectedLabel,
115
- verifySelectedValue: emitVerifyValue,
116
- verifyText: emitVerifyText,
117
- verifyTitle: emitVerifyTitle,
118
- verifyValue: emitVerifyValue,
119
- waitForElementEditable: emitWaitForElementEditable,
120
- waitForElementPresent: emitWaitForElementPresent,
121
- waitForElementVisible: emitWaitForElementVisible,
122
- waitForElementNotEditable: emitWaitForElementNotEditable,
123
- waitForElementNotPresent: emitWaitForElementNotPresent,
124
- waitForElementNotVisible: emitWaitForElementNotVisible,
125
- webdriverAnswerOnVisiblePrompt: emitAnswerOnNextPrompt,
126
- waitForText: emitWaitForText,
127
- webdriverChooseCancelOnVisibleConfirmation: emitChooseCancelOnNextConfirmation,
128
- webdriverChooseCancelOnVisiblePrompt: emitChooseCancelOnNextConfirmation,
129
- webdriverChooseOkOnVisibleConfirmation: emitChooseOkOnNextConfirmation,
130
- while: emitControlFlowWhile
18
+ var __importDefault = (this && this.__importDefault) || function (mod) {
19
+ return (mod && mod.__esModule) ? mod : { "default": mod };
131
20
  };
132
- exports.emitters = emitters;
133
-
134
- _sideUtils.codeExport.register.preprocessors(emitters);
135
-
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.emitters = void 0;
23
+ const side_code_export_1 = require("@seleniumhq/side-code-export");
24
+ const location_1 = __importDefault(require("./location"));
25
+ const selection_1 = __importDefault(require("./selection"));
26
+ exports.emitters = {
27
+ addSelection: emitSelect,
28
+ answerOnNextPrompt: skip,
29
+ assert: emitAssert,
30
+ assertAlert: emitAssertAlert,
31
+ assertChecked: emitVerifyChecked,
32
+ assertConfirmation: emitAssertAlert,
33
+ assertEditable: emitVerifyEditable,
34
+ assertElementPresent: emitVerifyElementPresent,
35
+ assertElementNotPresent: emitVerifyElementNotPresent,
36
+ assertNotChecked: emitVerifyNotChecked,
37
+ assertNotEditable: emitVerifyNotEditable,
38
+ assertNotSelectedValue: emitVerifyNotSelectedValue,
39
+ assertNotText: emitVerifyNotText,
40
+ assertPrompt: emitAssertAlert,
41
+ assertSelectedLabel: emitVerifySelectedLabel,
42
+ assertSelectedValue: emitVerifyValue,
43
+ assertValue: emitVerifyValue,
44
+ assertText: emitVerifyText,
45
+ assertTitle: emitVerifyTitle,
46
+ check: emitCheck,
47
+ chooseCancelOnNextConfirmation: skip,
48
+ chooseCancelOnNextPrompt: skip,
49
+ chooseOkOnNextConfirmation: skip,
50
+ click: emitClick,
51
+ clickAt: emitClick,
52
+ close: emitClose,
53
+ debugger: skip,
54
+ do: emitControlFlowDo,
55
+ doubleClick: emitDoubleClick,
56
+ doubleClickAt: emitDoubleClick,
57
+ dragAndDropToObject: emitDragAndDrop,
58
+ echo: emitEcho,
59
+ editContent: emitEditContent,
60
+ else: emitControlFlowElse,
61
+ elseIf: emitControlFlowElseIf,
62
+ end: emitControlFlowEnd,
63
+ executeScript: emitExecuteScript,
64
+ executeAsyncScript: emitExecuteAsyncScript,
65
+ forEach: emitControlFlowForEach,
66
+ if: emitControlFlowIf,
67
+ mouseDown: emitMouseDown,
68
+ mouseDownAt: emitMouseDown,
69
+ mouseMove: emitMouseMove,
70
+ mouseMoveAt: emitMouseMove,
71
+ mouseOver: emitMouseMove,
72
+ mouseOut: emitMouseOut,
73
+ mouseUp: emitMouseUp,
74
+ mouseUpAt: emitMouseUp,
75
+ open: emitOpen,
76
+ pause: emitPause,
77
+ removeSelection: emitSelect,
78
+ repeatIf: emitControlFlowRepeatIf,
79
+ run: emitRun,
80
+ runScript: emitRunScript,
81
+ select: emitSelect,
82
+ selectFrame: emitSelectFrame,
83
+ selectWindow: emitSelectWindow,
84
+ sendKeys: emitSendKeys,
85
+ setSpeed: emitSetSpeed,
86
+ setWindowSize: emitSetWindowSize,
87
+ store: emitStore,
88
+ storeAttribute: emitStoreAttribute,
89
+ storeJson: emitStoreJson,
90
+ storeText: emitStoreText,
91
+ storeTitle: emitStoreTitle,
92
+ storeValue: emitStoreValue,
93
+ storeWindowHandle: emitStoreWindowHandle,
94
+ storeXpathCount: emitStoreXpathCount,
95
+ submit: emitSubmit,
96
+ times: emitControlFlowTimes,
97
+ type: emitType,
98
+ uncheck: emitUncheck,
99
+ verify: emitAssert,
100
+ verifyChecked: emitVerifyChecked,
101
+ verifyEditable: emitVerifyEditable,
102
+ verifyElementPresent: emitVerifyElementPresent,
103
+ verifyElementNotPresent: emitVerifyElementNotPresent,
104
+ verifyNotChecked: emitVerifyNotChecked,
105
+ verifyNotEditable: emitVerifyNotEditable,
106
+ verifyNotSelectedValue: emitVerifyNotSelectedValue,
107
+ verifyNotText: emitVerifyNotText,
108
+ verifySelectedLabel: emitVerifySelectedLabel,
109
+ verifySelectedValue: emitVerifyValue,
110
+ verifyText: emitVerifyText,
111
+ verifyTitle: emitVerifyTitle,
112
+ verifyValue: emitVerifyValue,
113
+ waitForElementEditable: emitWaitForElementEditable,
114
+ waitForElementPresent: emitWaitForElementPresent,
115
+ waitForElementVisible: emitWaitForElementVisible,
116
+ waitForElementNotEditable: emitWaitForElementNotEditable,
117
+ waitForElementNotPresent: emitWaitForElementNotPresent,
118
+ waitForElementNotVisible: emitWaitForElementNotVisible,
119
+ webdriverAnswerOnVisiblePrompt: emitAnswerOnNextPrompt,
120
+ waitForText: emitWaitForText,
121
+ webdriverChooseCancelOnVisibleConfirmation: emitChooseCancelOnNextConfirmation,
122
+ webdriverChooseCancelOnVisiblePrompt: emitChooseCancelOnNextConfirmation,
123
+ webdriverChooseOkOnVisibleConfirmation: emitChooseOkOnNextConfirmation,
124
+ while: emitControlFlowWhile,
125
+ };
126
+ side_code_export_1.codeExport.register.preprocessors(exports.emitters);
136
127
  function register(command, emitter) {
137
- _sideUtils.codeExport.register.emitter({
138
- command,
139
- emitter,
140
- emitters
141
- });
128
+ side_code_export_1.codeExport.register.emitter({ command, emitter, emitters: exports.emitters });
142
129
  }
143
-
144
130
  function emit(command) {
145
- return _sideUtils.codeExport.emit.command(command, emitters[command.command], {
146
- variableLookup,
147
- emitNewWindowHandling
148
- });
149
- }
150
-
151
- function canEmit(commandName) {
152
- return !!emitters[commandName];
131
+ return side_code_export_1.codeExport.emit.command(command, exports.emitters[command.command], {
132
+ variableLookup,
133
+ emitNewWindowHandling,
134
+ });
153
135
  }
154
-
155
136
  function variableLookup(varName) {
156
- return `vars["${varName}"]`;
137
+ return `vars["${varName}"]`;
157
138
  }
158
-
159
139
  function variableSetter(varName, value) {
160
- return varName ? `vars["${varName}"] = ${value}` : '';
140
+ return varName ? `vars["${varName}"] = ${value}` : '';
161
141
  }
162
-
163
142
  function emitWaitForWindow() {
164
- const generateMethodDeclaration = name => {
165
- return {
166
- body: `async function ${name}(timeout = 2) {`,
167
- terminatingKeyword: '}'
143
+ const generateMethodDeclaration = (name) => {
144
+ return {
145
+ body: `async function ${name}(timeout = 2) {`,
146
+ terminatingKeyword: '}',
147
+ };
168
148
  };
169
- };
170
-
171
- const commands = [{
172
- level: 0,
173
- statement: 'await driver.sleep(timeout)'
174
- }, {
175
- level: 0,
176
- statement: 'const handlesThen = vars["windowHandles"]'
177
- }, {
178
- level: 0,
179
- statement: 'const handlesNow = await driver.getAllWindowHandles()'
180
- }, {
181
- level: 0,
182
- statement: 'if (handlesNow.length > handlesThen.length) {'
183
- }, {
184
- level: 1,
185
- statement: 'return handlesNow.find(handle => (!handlesThen.includes(handle)))'
186
- }, {
187
- level: 0,
188
- statement: '}'
189
- }, {
190
- level: 0,
191
- statement: 'throw new Error("New window did not appear before timeout")'
192
- }];
193
- return Promise.resolve({
194
- name: 'waitForWindow',
195
- commands,
196
- generateMethodDeclaration
197
- });
198
- }
199
-
149
+ const commands = [
150
+ { level: 0, statement: 'await driver.sleep(timeout)' },
151
+ { level: 0, statement: 'const handlesThen = vars["windowHandles"]' },
152
+ {
153
+ level: 0,
154
+ statement: 'const handlesNow = await driver.getAllWindowHandles()',
155
+ },
156
+ { level: 0, statement: 'if (handlesNow.length > handlesThen.length) {' },
157
+ {
158
+ level: 1,
159
+ statement: 'return handlesNow.find(handle => (!handlesThen.includes(handle)))',
160
+ },
161
+ { level: 0, statement: '}' },
162
+ {
163
+ level: 0,
164
+ statement: 'throw new Error("New window did not appear before timeout")',
165
+ },
166
+ ];
167
+ return Promise.resolve({
168
+ name: 'waitForWindow',
169
+ commands,
170
+ generateMethodDeclaration,
171
+ });
172
+ }
200
173
  async function emitNewWindowHandling(command, emittedCommand) {
201
- return Promise.resolve(`vars["windowHandles"] = await driver.getAllWindowHandles()\n${await emittedCommand}\nvars["${command.windowHandleName}"] = await waitForWindow(${command.windowTimeout})`);
174
+ return Promise.resolve(`vars["windowHandles"] = await driver.getAllWindowHandles()\n${await emittedCommand}\nvars["${command.windowHandleName}"] = await waitForWindow(${command.windowTimeout})`);
202
175
  }
203
-
204
176
  function emitAssert(varName, value) {
205
- return Promise.resolve(`assert(vars["${varName}"].toString() == "${value}")`);
177
+ return Promise.resolve(`assert(vars["${varName}"].toString() == "${value}")`);
206
178
  }
207
-
208
179
  function emitAssertAlert(alertText) {
209
- return Promise.resolve(`assert(await driver.switchTo().alert().getText() == "${alertText}")`);
180
+ return Promise.resolve(`assert(await driver.switchTo().alert().getText() == "${alertText}")`);
210
181
  }
211
-
212
182
  function emitAnswerOnNextPrompt(textToSend) {
213
- const commands = [{
214
- level: 0,
215
- statement: `{`
216
- }, {
217
- level: 1,
218
- statement: 'const alert = await driver.switchTo().alert()'
219
- }, {
220
- level: 1,
221
- statement: `await alert.sendKeys("${textToSend}")`
222
- }, {
223
- level: 1,
224
- statement: 'await alert.accept()'
225
- }, {
226
- level: 0,
227
- statement: `}`
228
- }];
229
- return Promise.resolve({
230
- commands
231
- });
232
- }
233
-
183
+ const commands = [
184
+ { level: 0, statement: `{` },
185
+ { level: 1, statement: 'const alert = await driver.switchTo().alert()' },
186
+ { level: 1, statement: `await alert.sendKeys("${textToSend}")` },
187
+ { level: 1, statement: 'await alert.accept()' },
188
+ { level: 0, statement: `}` },
189
+ ];
190
+ return Promise.resolve({ commands });
191
+ }
234
192
  async function emitCheck(locator) {
235
- const commands = [{
236
- level: 0,
237
- statement: `{`
238
- }, {
239
- level: 1,
240
- statement: `const element = await driver.findElement(${await _location.default.emit(locator)})`
241
- }, {
242
- level: 1,
243
- statement: 'if (!(await element.isSelected())) await element.click()'
244
- }, {
245
- level: 0,
246
- statement: `}`
247
- }];
248
- return Promise.resolve({
249
- commands
250
- });
251
- }
252
-
193
+ const commands = [
194
+ {
195
+ level: 0,
196
+ statement: `{`,
197
+ },
198
+ {
199
+ level: 1,
200
+ statement: `const element = await driver.findElement(${await location_1.default.emit(locator)})`,
201
+ },
202
+ {
203
+ level: 1,
204
+ statement: 'if (!(await element.isSelected())) await element.click()',
205
+ },
206
+ {
207
+ level: 0,
208
+ statement: `}`,
209
+ },
210
+ ];
211
+ return Promise.resolve({ commands });
212
+ }
253
213
  function emitChooseCancelOnNextConfirmation() {
254
- return Promise.resolve(`await driver.switchTo().alert().dismiss()`);
214
+ return Promise.resolve(`await driver.switchTo().alert().dismiss()`);
255
215
  }
256
-
257
216
  function emitChooseOkOnNextConfirmation() {
258
- return Promise.resolve(`await driver.switchTo().alert().accept()`);
217
+ return Promise.resolve(`await driver.switchTo().alert().accept()`);
259
218
  }
260
-
261
219
  async function emitClick(target) {
262
- return Promise.resolve(`await driver.findElement(${await _location.default.emit(target)}).click()`);
220
+ return Promise.resolve(`await driver.findElement(${await location_1.default.emit(target)}).click()`);
263
221
  }
264
-
265
222
  async function emitClose() {
266
- return Promise.resolve(`await driver.close()`);
223
+ return Promise.resolve(`await driver.close()`);
267
224
  }
268
-
269
225
  function generateExpressionScript(script) {
270
- return `await driver.executeScript("return (${script.script})"${generateScriptArguments(script)})`;
226
+ return `await driver.executeScript("return (${script.script})"${generateScriptArguments(script)})`;
271
227
  }
272
-
273
228
  function generateScriptArguments(script) {
274
- return `${script.argv.length ? ', ' : ''}${script.argv.map(varName => `vars["${varName}"]`).join(',')}`;
229
+ return `${script.argv.length ? ', ' : ''}${script.argv
230
+ .map((varName) => `vars["${varName}"]`)
231
+ .join(',')}`;
275
232
  }
276
-
277
233
  function emitControlFlowDo() {
278
- return Promise.resolve({
279
- commands: [{
280
- level: 0,
281
- statement: 'do {'
282
- }],
283
- endingLevelAdjustment: 1
284
- });
285
- }
286
-
234
+ return Promise.resolve({
235
+ commands: [{ level: 0, statement: 'do {' }],
236
+ endingLevelAdjustment: 1,
237
+ });
238
+ }
287
239
  function emitControlFlowElse() {
288
- return Promise.resolve({
289
- commands: [{
290
- level: 0,
291
- statement: '} else {'
292
- }],
293
- startingLevelAdjustment: -1,
294
- endingLevelAdjustment: +1
295
- });
296
- }
297
-
240
+ return Promise.resolve({
241
+ commands: [{ level: 0, statement: '} else {' }],
242
+ startingLevelAdjustment: -1,
243
+ endingLevelAdjustment: +1,
244
+ });
245
+ }
298
246
  function emitControlFlowElseIf(script) {
299
- return Promise.resolve({
300
- commands: [{
301
- level: 0,
302
- statement: `} else if (!!${generateExpressionScript(script)}) {`
303
- }],
304
- startingLevelAdjustment: -1,
305
- endingLevelAdjustment: +1
306
- });
307
- }
308
-
247
+ return Promise.resolve({
248
+ commands: [
249
+ {
250
+ level: 0,
251
+ statement: `} else if (!!${generateExpressionScript(script)}) {`,
252
+ },
253
+ ],
254
+ startingLevelAdjustment: -1,
255
+ endingLevelAdjustment: +1,
256
+ });
257
+ }
309
258
  function emitControlFlowEnd() {
310
- return Promise.resolve({
311
- commands: [{
312
- level: 0,
313
- statement: `}`
314
- }],
315
- startingLevelAdjustment: -1
316
- });
317
- }
318
-
259
+ return Promise.resolve({
260
+ commands: [{ level: 0, statement: `}` }],
261
+ startingLevelAdjustment: -1,
262
+ });
263
+ }
319
264
  function emitControlFlowIf(script) {
320
- return Promise.resolve({
321
- commands: [{
322
- level: 0,
323
- statement: `if (!!${generateExpressionScript(script)}) {`
324
- }],
325
- endingLevelAdjustment: 1
326
- });
327
- }
328
-
265
+ return Promise.resolve({
266
+ commands: [
267
+ { level: 0, statement: `if (!!${generateExpressionScript(script)}) {` },
268
+ ],
269
+ endingLevelAdjustment: 1,
270
+ });
271
+ }
329
272
  function emitControlFlowForEach(collectionVarName, iteratorVarName) {
330
- return Promise.resolve({
331
- commands: [{
332
- level: 0,
333
- statement: `const collection = vars["${collectionVarName}"]`
334
- }, {
335
- level: 0,
336
- statement: `for (let i = 0; i < collection.length - 1; i++) {`
337
- }, {
338
- level: 1,
339
- statement: `vars["${iteratorVarName}"] = vars["${collectionVarName}"][i]`
340
- }]
341
- });
342
- }
343
-
273
+ return Promise.resolve({
274
+ commands: [
275
+ {
276
+ level: 0,
277
+ statement: `const collection = vars["${collectionVarName}"]`,
278
+ },
279
+ {
280
+ level: 0,
281
+ statement: `for (let i = 0; i < collection.length - 1; i++) {`,
282
+ },
283
+ {
284
+ level: 1,
285
+ statement: `vars["${iteratorVarName}"] = vars["${collectionVarName}"][i]`,
286
+ },
287
+ ],
288
+ });
289
+ }
344
290
  function emitControlFlowRepeatIf(script) {
345
- return Promise.resolve({
346
- commands: [{
347
- level: 0,
348
- statement: `} while(!!${generateExpressionScript(script)})`
349
- }],
350
- startingLevelAdjustment: -1
351
- });
352
- }
353
-
291
+ return Promise.resolve({
292
+ commands: [
293
+ {
294
+ level: 0,
295
+ statement: `} while(!!${generateExpressionScript(script)})`,
296
+ },
297
+ ],
298
+ startingLevelAdjustment: -1,
299
+ });
300
+ }
354
301
  function emitControlFlowTimes(target) {
355
- const commands = [{
356
- level: 0,
357
- statement: `const times = ${target}`
358
- }, {
359
- level: 0,
360
- statement: `for(let i = 0; i < times; i++) {`
361
- }];
362
- return Promise.resolve({
363
- commands,
364
- endingLevelAdjustment: 1
365
- });
366
- }
367
-
302
+ const commands = [
303
+ {
304
+ level: 0,
305
+ statement: `const times = ${target}`,
306
+ },
307
+ {
308
+ level: 0,
309
+ statement: `for(let i = 0; i < times; i++) {`,
310
+ },
311
+ ];
312
+ return Promise.resolve({ commands, endingLevelAdjustment: 1 });
313
+ }
368
314
  function emitControlFlowWhile(script) {
369
- return Promise.resolve({
370
- commands: [{
371
- level: 0,
372
- statement: `while(!!${generateExpressionScript(script)}) {`
373
- }],
374
- endingLevelAdjustment: 1
375
- });
376
- }
377
-
315
+ return Promise.resolve({
316
+ commands: [
317
+ { level: 0, statement: `while(!!${generateExpressionScript(script)}) {` },
318
+ ],
319
+ endingLevelAdjustment: 1,
320
+ });
321
+ }
378
322
  async function emitDoubleClick(target) {
379
- const commands = [{
380
- level: 0,
381
- statement: `{`
382
- }, {
383
- level: 1,
384
- statement: `const element = await driver.findElement(${await _location.default.emit(target)})`
385
- }, {
386
- level: 1,
387
- statement: 'await driver.actions({ bridge: true}).doubleClick(element).perform()'
388
- }, {
389
- level: 0,
390
- statement: `}`
391
- }];
392
- return Promise.resolve({
393
- commands
394
- });
395
- }
396
-
323
+ const commands = [
324
+ { level: 0, statement: `{` },
325
+ {
326
+ level: 1,
327
+ statement: `const element = await driver.findElement(${await location_1.default.emit(target)})`,
328
+ },
329
+ {
330
+ level: 1,
331
+ statement: 'await driver.actions({ bridge: true}).doubleClick(element).perform()',
332
+ },
333
+ { level: 0, statement: `}` },
334
+ ];
335
+ return Promise.resolve({ commands });
336
+ }
397
337
  async function emitDragAndDrop(dragged, dropped) {
398
- const commands = [{
399
- level: 0,
400
- statement: `{`
401
- }, {
402
- level: 1,
403
- statement: `const dragged = await driver.findElement(${await _location.default.emit(dragged)})`
404
- }, {
405
- level: 1,
406
- statement: `const dropped = await driver.findElement(${await _location.default.emit(dropped)})`
407
- }, {
408
- level: 1,
409
- statement: 'await driver.actions({ bridge: true }).dragAndDrop(dragged, dropped).perform()'
410
- }, {
411
- level: 0,
412
- statement: `}`
413
- }];
414
- return Promise.resolve({
415
- commands
416
- });
417
- }
418
-
338
+ const commands = [
339
+ { level: 0, statement: `{` },
340
+ {
341
+ level: 1,
342
+ statement: `const dragged = await driver.findElement(${await location_1.default.emit(dragged)})`,
343
+ },
344
+ {
345
+ level: 1,
346
+ statement: `const dropped = await driver.findElement(${await location_1.default.emit(dropped)})`,
347
+ },
348
+ {
349
+ level: 1,
350
+ statement: 'await driver.actions({ bridge: true }).dragAndDrop(dragged, dropped).perform()',
351
+ },
352
+ { level: 0, statement: `}` },
353
+ ];
354
+ return Promise.resolve({ commands });
355
+ }
419
356
  async function emitEcho(message) {
420
- const _message = message.startsWith('vars[') ? message : `"${message}"`;
421
-
422
- return Promise.resolve(`console.log(${_message})`);
357
+ const _message = message.startsWith('vars[') ? message : `"${message}"`;
358
+ return Promise.resolve(`console.log(${_message})`);
423
359
  }
424
-
425
360
  async function emitEditContent(locator, content) {
426
- const commands = [{
427
- level: 0,
428
- statement: `{`
429
- }, {
430
- level: 1,
431
- statement: `const element = await driver.findElement(${await _location.default.emit(locator)})`
432
- }, {
433
- level: 1,
434
- statement: `await driver.executeScript("if(arguments[0].contentEditable === 'true') {arguments[0].innerText = '${content}'}", element)`
435
- }, {
436
- level: 0,
437
- statement: `}`
438
- }];
439
- return Promise.resolve({
440
- commands
441
- });
442
- }
443
-
361
+ const commands = [
362
+ { level: 0, statement: `{` },
363
+ {
364
+ level: 1,
365
+ statement: `const element = await driver.findElement(${await location_1.default.emit(locator)})`,
366
+ },
367
+ {
368
+ level: 1,
369
+ statement: `await driver.executeScript("if(arguments[0].contentEditable === 'true') {arguments[0].innerText = '${content}'}", element)`,
370
+ },
371
+ { level: 0, statement: `}` },
372
+ ];
373
+ return Promise.resolve({ commands });
374
+ }
444
375
  async function emitExecuteScript(script, varName) {
445
- const scriptString = script.script.replace(/`/g, '\\`');
446
- const result = `await driver.executeScript("${scriptString}"${generateScriptArguments(script)})`;
447
- return Promise.resolve(variableSetter(varName, result));
376
+ const scriptString = script.script.replace(/`/g, '\\`');
377
+ const result = `await driver.executeScript("${scriptString}"${generateScriptArguments(script)})`;
378
+ return Promise.resolve(variableSetter(varName, result));
448
379
  }
449
-
450
380
  async function emitExecuteAsyncScript(script, varName) {
451
- const result = `await driver.executeAsyncScript("var callback = arguments[arguments.length - 1];${script.script}.then(callback).catch(callback);${generateScriptArguments(script)}")`;
452
- return Promise.resolve(variableSetter(varName, result));
381
+ const result = `await driver.executeAsyncScript("var callback = arguments[arguments.length - 1];${script.script}.then(callback).catch(callback);${generateScriptArguments(script)}")`;
382
+ return Promise.resolve(variableSetter(varName, result));
453
383
  }
454
-
455
384
  async function emitMouseDown(locator) {
456
- const commands = [{
457
- level: 0,
458
- statement: `{`
459
- }, {
460
- level: 1,
461
- statement: `const element = await driver.findElement(${await _location.default.emit(locator)})`
462
- }, {
463
- level: 1,
464
- statement: 'await driver.actions({ bridge: true }).moveToElement(element).clickAndHold().perform()'
465
- }, {
466
- level: 0,
467
- statement: `}`
468
- }];
469
- return Promise.resolve({
470
- commands
471
- });
472
- }
473
-
385
+ const commands = [
386
+ { level: 0, statement: `{` },
387
+ {
388
+ level: 1,
389
+ statement: `const element = await driver.findElement(${await location_1.default.emit(locator)})`,
390
+ },
391
+ {
392
+ level: 1,
393
+ statement: 'await driver.actions({ bridge: true }).moveToElement(element).clickAndHold().perform()',
394
+ },
395
+ { level: 0, statement: `}` },
396
+ ];
397
+ return Promise.resolve({ commands });
398
+ }
474
399
  async function emitMouseMove(locator) {
475
- const commands = [{
476
- level: 0,
477
- statement: `{`
478
- }, {
479
- level: 1,
480
- statement: `const element = await driver.findElement(${await _location.default.emit(locator)})`
481
- }, {
482
- level: 1,
483
- statement: 'await driver.actions({ bridge: true }).moveToElement(element).perform()'
484
- }, {
485
- level: 0,
486
- statement: `}`
487
- }];
488
- return Promise.resolve({
489
- commands
490
- });
491
- }
492
-
400
+ const commands = [
401
+ { level: 0, statement: `{` },
402
+ {
403
+ level: 1,
404
+ statement: `const element = await driver.findElement(${await location_1.default.emit(locator)})`,
405
+ },
406
+ {
407
+ level: 1,
408
+ statement: 'await driver.actions({ bridge: true }).moveToElement(element).perform()',
409
+ },
410
+ { level: 0, statement: `}` },
411
+ ];
412
+ return Promise.resolve({ commands });
413
+ }
493
414
  async function emitMouseOut() {
494
- const commands = [{
495
- level: 0,
496
- statement: `{`
497
- }, {
498
- level: 1,
499
- statement: `const element = await driver.findElement(By.CSS_SELECTOR, "body")`
500
- }, {
501
- level: 1,
502
- statement: 'await driver.actions({ bridge: true }).moveToElement(element, 0, 0).perform()'
503
- }, {
504
- level: 0,
505
- statement: `}`
506
- }];
507
- return Promise.resolve({
508
- commands
509
- });
510
- }
511
-
415
+ const commands = [
416
+ { level: 0, statement: `{` },
417
+ {
418
+ level: 1,
419
+ statement: `const element = await driver.findElement(By.CSS_SELECTOR, "body")`,
420
+ },
421
+ {
422
+ level: 1,
423
+ statement: 'await driver.actions({ bridge: true }).moveToElement(element, 0, 0).perform()',
424
+ },
425
+ { level: 0, statement: `}` },
426
+ ];
427
+ return Promise.resolve({ commands });
428
+ }
512
429
  async function emitMouseUp(locator) {
513
- const commands = [{
514
- level: 0,
515
- statement: `{`
516
- }, {
517
- level: 1,
518
- statement: `const element = await driver.findElement(${await _location.default.emit(locator)})`
519
- }, {
520
- level: 1,
521
- statement: 'await driver.actions({ bridge: true }).moveToElement(element).release().perform()'
522
- }, {
523
- level: 0,
524
- statement: `}`
525
- }];
526
- return Promise.resolve({
527
- commands
528
- });
529
- }
530
-
430
+ const commands = [
431
+ { level: 0, statement: `{` },
432
+ {
433
+ level: 1,
434
+ statement: `const element = await driver.findElement(${await location_1.default.emit(locator)})`,
435
+ },
436
+ {
437
+ level: 1,
438
+ statement: 'await driver.actions({ bridge: true }).moveToElement(element).release().perform()',
439
+ },
440
+ { level: 0, statement: `}` },
441
+ ];
442
+ return Promise.resolve({ commands });
443
+ }
531
444
  function emitOpen(target) {
532
- const url = /^(file|http|https):\/\//.test(target) ? `"${target}"` : `"${global.baseUrl}${target}"`;
533
- return Promise.resolve(`await driver.get(${url})`);
445
+ const url = /^(file|http|https):\/\//.test(target)
446
+ ? `"${target}"`
447
+ : // @ts-expect-error globals yuck
448
+ `"${global.baseUrl}${target}"`;
449
+ return Promise.resolve(`await driver.get(${url})`);
534
450
  }
535
-
536
451
  async function emitPause(time) {
537
- const commands = [{
538
- level: 0,
539
- statement: `await driver.sleep(${time})`
540
- }];
541
- return Promise.resolve({
542
- commands
543
- });
544
- }
545
-
452
+ const commands = [{ level: 0, statement: `await driver.sleep(${time})` }];
453
+ return Promise.resolve({ commands });
454
+ }
546
455
  async function emitRun(testName) {
547
- return Promise.resolve(`${_sideUtils.codeExport.parsers.sanitizeName(testName)}()`);
456
+ return Promise.resolve(`${side_code_export_1.codeExport.parsers.sanitizeName(testName)}()`);
548
457
  }
549
-
550
458
  async function emitRunScript(script) {
551
- return Promise.resolve(`await driver.executeScript("${script.script}${generateScriptArguments(script)}")`);
459
+ return Promise.resolve(`await driver.executeScript("${script.script}${generateScriptArguments(script)}")`);
552
460
  }
553
-
554
461
  async function emitSetWindowSize(size) {
555
- const [width, height] = size.split('x');
556
- return Promise.resolve(`await driver.manage().window().setRect({ width: ${width}, height: ${height} })`);
462
+ const [width, height] = size.split('x');
463
+ return Promise.resolve(`await driver.manage().window().setRect({ width: ${width}, height: ${height} })`);
557
464
  }
558
-
559
465
  async function emitSelect(selectElement, option) {
560
- const commands = [{
561
- level: 0,
562
- statement: `{`
563
- }, {
564
- level: 1,
565
- statement: `const dropdown = await driver.findElement(${await _location.default.emit(selectElement)})`
566
- }, {
567
- level: 1,
568
- statement: `await dropdown.findElement(${await _selection.default.emit(option)}).click()`
569
- }, {
570
- level: 0,
571
- statement: `}`
572
- }];
573
- return Promise.resolve({
574
- commands
575
- });
576
- }
577
-
466
+ const commands = [
467
+ { level: 0, statement: `{` },
468
+ {
469
+ level: 1,
470
+ statement: `const dropdown = await driver.findElement(${await location_1.default.emit(selectElement)})`,
471
+ },
472
+ {
473
+ level: 1,
474
+ statement: `await dropdown.findElement(${await selection_1.default.emit(option)}).click()`,
475
+ },
476
+ { level: 0, statement: `}` },
477
+ ];
478
+ return Promise.resolve({ commands });
479
+ }
578
480
  async function emitSelectFrame(frameLocation) {
579
- if (frameLocation === 'relative=top' || frameLocation === 'relative=parent') {
580
- return Promise.resolve('await driver.switchTo().defaultContent()');
581
- } else if (/^index=/.test(frameLocation)) {
582
- return Promise.resolve(`await driver.switchTo().frame(${Math.floor(frameLocation.split('index=')[1])})`);
583
- } else {
584
- return Promise.resolve({
585
- commands: [{
586
- level: 0,
587
- statement: `{`
588
- }, {
589
- level: 0,
590
- statement: `const element = await driver.findElement(${await _location.default.emit(frameLocation)})`
591
- }, {
592
- level: 0,
593
- statement: 'await driver.switchTo().frame(element)'
594
- }, {
595
- level: 0,
596
- statement: `}`
597
- }]
598
- });
599
- }
481
+ if (frameLocation === 'relative=top' || frameLocation === 'relative=parent') {
482
+ return Promise.resolve('await driver.switchTo().defaultContent()');
483
+ }
484
+ else if (/^index=/.test(frameLocation)) {
485
+ return Promise.resolve(`await driver.switchTo().frame(${Math.floor(Number(frameLocation.split('index=')?.[1]))})`);
486
+ }
487
+ else {
488
+ return Promise.resolve({
489
+ commands: [
490
+ { level: 0, statement: `{` },
491
+ {
492
+ level: 0,
493
+ statement: `const element = await driver.findElement(${await location_1.default.emit(frameLocation)})`,
494
+ },
495
+ { level: 0, statement: 'await driver.switchTo().frame(element)' },
496
+ { level: 0, statement: `}` },
497
+ ],
498
+ });
499
+ }
600
500
  }
601
-
602
501
  async function emitSelectWindow(windowLocation) {
603
- if (/^handle=/.test(windowLocation)) {
604
- return Promise.resolve(`await driver.switchTo().window(${windowLocation.split('handle=')[1]})`);
605
- } else if (/^name=/.test(windowLocation)) {
606
- return Promise.resolve(`await driver.switchTo().window("${windowLocation.split('name=')[1]}")`);
607
- } else if (/^win_ser_/.test(windowLocation)) {
608
- if (windowLocation === 'win_ser_local') {
609
- return Promise.resolve({
610
- commands: [{
611
- level: 0,
612
- statement: 'await driver.switchTo().window(await driver.getAllWindowHandles()[0])'
613
- }]
614
- });
615
- } else {
616
- const index = parseInt(windowLocation.substr('win_ser_'.length));
617
- return Promise.resolve({
618
- commands: [{
619
- level: 0,
620
- statement: `await driver.switchTo().window(await driver.getAllWindowHandles()[${index}])`
621
- }]
622
- });
502
+ if (/^handle=/.test(windowLocation)) {
503
+ return Promise.resolve(`await driver.switchTo().window(${windowLocation.split('handle=')[1]})`);
504
+ }
505
+ else if (/^name=/.test(windowLocation)) {
506
+ return Promise.resolve(`await driver.switchTo().window("${windowLocation.split('name=')[1]}")`);
507
+ }
508
+ else if (/^win_ser_/.test(windowLocation)) {
509
+ if (windowLocation === 'win_ser_local') {
510
+ return Promise.resolve({
511
+ commands: [
512
+ {
513
+ level: 0,
514
+ statement: 'await driver.switchTo().window(await driver.getAllWindowHandles()[0])',
515
+ },
516
+ ],
517
+ });
518
+ }
519
+ else {
520
+ const index = parseInt(windowLocation.substr('win_ser_'.length));
521
+ return Promise.resolve({
522
+ commands: [
523
+ {
524
+ level: 0,
525
+ statement: `await driver.switchTo().window(await driver.getAllWindowHandles()[${index}])`,
526
+ },
527
+ ],
528
+ });
529
+ }
530
+ }
531
+ else {
532
+ return Promise.reject(new Error('Can only emit `select window` using handles'));
623
533
  }
624
- } else {
625
- return Promise.reject(new Error('Can only emit `select window` using handles'));
626
- }
627
534
  }
628
-
629
535
  function generateSendKeysInput(value) {
630
- if (typeof value === 'object') {
631
- return value.map(s => {
632
- if (s.startsWith('vars[')) {
633
- return s;
634
- } else if (s.startsWith('Key[')) {
635
- const key = s.match(/\['(.*)'\]/)[1];
636
- return `Key.${key}`;
637
- } else {
638
- return `"${s}"`;
639
- }
640
- }).join(', ');
641
- } else {
642
- if (value.startsWith('vars[')) {
643
- return value;
644
- } else {
645
- return `"${value}"`;
536
+ if (typeof value === 'object') {
537
+ return value
538
+ .map((s) => {
539
+ if (s.startsWith('vars[')) {
540
+ return s;
541
+ }
542
+ else if (s.startsWith('Key[')) {
543
+ const key = s.match(/\['(.*)'\]/)?.[1];
544
+ return `Key.${key}`;
545
+ }
546
+ else {
547
+ return `"${s}"`;
548
+ }
549
+ })
550
+ .join(', ');
551
+ }
552
+ else {
553
+ if (value.startsWith('vars[')) {
554
+ return value;
555
+ }
556
+ else {
557
+ return `"${value}"`;
558
+ }
646
559
  }
647
- }
648
560
  }
649
-
650
561
  async function emitSendKeys(target, value) {
651
- return Promise.resolve(`await driver.findElement(${await _location.default.emit(target)}).sendKeys(${generateSendKeysInput(value)})`);
562
+ return Promise.resolve(`await driver.findElement(${await location_1.default.emit(target)}).sendKeys(${generateSendKeysInput(value)})`);
652
563
  }
653
-
654
564
  function emitSetSpeed() {
655
- return Promise.resolve('console.log("`set speed` is a no-op in code export, use `pause` instead")');
565
+ return Promise.resolve('console.log("`set speed` is a no-op in code export, use `pause` instead")');
656
566
  }
657
-
658
567
  async function emitStore(value, varName) {
659
- return Promise.resolve(variableSetter(varName, `"${value}"`));
568
+ return Promise.resolve(variableSetter(varName, `"${value}"`));
660
569
  }
661
-
662
570
  async function emitStoreAttribute(locator, varName) {
663
- const attributePos = locator.lastIndexOf('@');
664
- const elementLocator = locator.slice(0, attributePos);
665
- const attributeName = locator.slice(attributePos + 1);
666
- const commands = [{
667
- level: 0,
668
- statement: `{`
669
- }, {
670
- level: 1,
671
- statement: `const attribute = await driver.findElement(${await _location.default.emit(elementLocator)}).getAttribute("${attributeName}")`
672
- }, {
673
- level: 1,
674
- statement: `${variableSetter(varName, 'attribute')}`
675
- }, {
676
- level: 0,
677
- statement: `}`
678
- }];
679
- return Promise.resolve({
680
- commands
681
- });
682
- }
683
-
571
+ const attributePos = locator.lastIndexOf('@');
572
+ const elementLocator = locator.slice(0, attributePos);
573
+ const attributeName = locator.slice(attributePos + 1);
574
+ const commands = [
575
+ { level: 0, statement: `{` },
576
+ {
577
+ level: 1,
578
+ statement: `const attribute = await driver.findElement(${await location_1.default.emit(elementLocator)}).getAttribute("${attributeName}")`,
579
+ },
580
+ { level: 1, statement: `${variableSetter(varName, 'attribute')}` },
581
+ { level: 0, statement: `}` },
582
+ ];
583
+ return Promise.resolve({ commands });
584
+ }
684
585
  async function emitStoreJson(json, varName) {
685
- return Promise.resolve(variableSetter(varName, `JSON.parse('${json}')`));
586
+ return Promise.resolve(variableSetter(varName, `JSON.parse('${json}')`));
686
587
  }
687
-
688
588
  async function emitStoreText(locator, varName) {
689
- const result = `await driver.findElement(${await _location.default.emit(locator)}).getText()`;
690
- return Promise.resolve(variableSetter(varName, result));
589
+ const result = `await driver.findElement(${await location_1.default.emit(locator)}).getText()`;
590
+ return Promise.resolve(variableSetter(varName, result));
691
591
  }
692
-
693
592
  async function emitStoreTitle(_, varName) {
694
- return Promise.resolve(variableSetter(varName, 'await driver.getTitle()'));
593
+ return Promise.resolve(variableSetter(varName, 'await driver.getTitle()'));
695
594
  }
696
-
697
595
  async function emitStoreValue(locator, varName) {
698
- const result = `await driver.findElement(${await _location.default.emit(locator)}).getAttribute("value")`;
699
- return Promise.resolve(variableSetter(varName, result));
596
+ const result = `await driver.findElement(${await location_1.default.emit(locator)}).getAttribute("value")`;
597
+ return Promise.resolve(variableSetter(varName, result));
700
598
  }
701
-
702
599
  async function emitStoreWindowHandle(varName) {
703
- return Promise.resolve(variableSetter(varName, 'await driver.getWindowHandle()'));
600
+ return Promise.resolve(variableSetter(varName, 'await driver.getWindowHandle()'));
704
601
  }
705
-
706
602
  async function emitStoreXpathCount(locator, varName) {
707
- const result = `await driver.findElements(${await _location.default.emit(locator)}).length`;
708
- return Promise.resolve(variableSetter(varName, result));
603
+ const result = `await driver.findElements(${await location_1.default.emit(locator)}).length`;
604
+ return Promise.resolve(variableSetter(varName, result));
709
605
  }
710
-
711
606
  async function emitSubmit(_locator) {
712
- return Promise.resolve(`raise Exception("\`submit\` is not a supported command in Selenium Webdriver. Please re-record the step in the IDE.")`);
607
+ return Promise.resolve(`raise Exception("\`submit\` is not a supported command in Selenium Webdriver. Please re-record the step in the IDE.")`);
713
608
  }
714
-
715
609
  async function emitType(target, value) {
716
- return Promise.resolve(`await driver.findElement(${await _location.default.emit(target)}).sendKeys(${generateSendKeysInput(value)})`);
610
+ return Promise.resolve(`await driver.findElement(${await location_1.default.emit(target)}).sendKeys(${generateSendKeysInput(value)})`);
717
611
  }
718
-
719
612
  async function emitUncheck(locator) {
720
- const commands = [{
721
- level: 0,
722
- statement: `{`
723
- }, {
724
- level: 1,
725
- statement: `const element = await driver.findElement(${await _location.default.emit(locator)})`
726
- }, {
727
- level: 1,
728
- statement: 'if (await element.isSelected()) await element.click()'
729
- }, {
730
- level: 0,
731
- statement: `}`
732
- }];
733
- return Promise.resolve({
734
- commands
735
- });
736
- }
737
-
613
+ const commands = [
614
+ { level: 0, statement: `{` },
615
+ {
616
+ level: 1,
617
+ statement: `const element = await driver.findElement(${await location_1.default.emit(locator)})`,
618
+ },
619
+ {
620
+ level: 1,
621
+ statement: 'if (await element.isSelected()) await element.click()',
622
+ },
623
+ { level: 0, statement: `}` },
624
+ ];
625
+ return Promise.resolve({ commands });
626
+ }
738
627
  async function emitVerifyChecked(locator) {
739
- return Promise.resolve(`assert(await driver.findElement(${await _location.default.emit(locator)}).isSelected())`);
628
+ return Promise.resolve(`assert(await driver.findElement(${await location_1.default.emit(locator)}).isSelected())`);
740
629
  }
741
-
742
630
  async function emitVerifyEditable(locator) {
743
- const commands = [{
744
- level: 0,
745
- statement: `{`
746
- }, {
747
- level: 1,
748
- statement: `const element = await driver.findElement(${await _location.default.emit(locator)})`
749
- }, {
750
- level: 1,
751
- statement: 'assert(await element.isEnabled())'
752
- }, {
753
- level: 0,
754
- statement: `}`
755
- }];
756
- return Promise.resolve({
757
- commands
758
- });
759
- }
760
-
631
+ const commands = [
632
+ { level: 0, statement: `{` },
633
+ {
634
+ level: 1,
635
+ statement: `const element = await driver.findElement(${await location_1.default.emit(locator)})`,
636
+ },
637
+ { level: 1, statement: 'assert(await element.isEnabled())' },
638
+ { level: 0, statement: `}` },
639
+ ];
640
+ return Promise.resolve({ commands });
641
+ }
761
642
  async function emitVerifyElementPresent(locator) {
762
- const commands = [{
763
- level: 0,
764
- statement: `{`
765
- }, {
766
- level: 1,
767
- statement: `const elements = await driver.findElements(${await _location.default.emit(locator)})`
768
- }, {
769
- level: 1,
770
- statement: 'assert(elements.length)'
771
- }, {
772
- level: 0,
773
- statement: `}`
774
- }];
775
- return Promise.resolve({
776
- commands
777
- });
778
- }
779
-
643
+ const commands = [
644
+ { level: 0, statement: `{` },
645
+ {
646
+ level: 1,
647
+ statement: `const elements = await driver.findElements(${await location_1.default.emit(locator)})`,
648
+ },
649
+ { level: 1, statement: 'assert(elements.length)' },
650
+ { level: 0, statement: `}` },
651
+ ];
652
+ return Promise.resolve({ commands });
653
+ }
780
654
  async function emitVerifyElementNotPresent(locator) {
781
- const commands = [{
782
- level: 0,
783
- statement: `{`
784
- }, {
785
- level: 1,
786
- statement: `const elements = await driver.findElements(${await _location.default.emit(locator)})`
787
- }, {
788
- level: 1,
789
- statement: 'assert(!elements.length)'
790
- }, {
791
- level: 0,
792
- statement: `}`
793
- }];
794
- return Promise.resolve({
795
- commands
796
- });
797
- }
798
-
655
+ const commands = [
656
+ { level: 0, statement: `{` },
657
+ {
658
+ level: 1,
659
+ statement: `const elements = await driver.findElements(${await location_1.default.emit(locator)})`,
660
+ },
661
+ { level: 1, statement: 'assert(!elements.length)' },
662
+ { level: 0, statement: `}` },
663
+ ];
664
+ return Promise.resolve({ commands });
665
+ }
799
666
  async function emitVerifyNotChecked(locator) {
800
- return Promise.resolve(`assert(!await driver.findElement(${await _location.default.emit(locator)}).isSelected())`);
667
+ return Promise.resolve(`assert(!await driver.findElement(${await location_1.default.emit(locator)}).isSelected())`);
801
668
  }
802
-
803
669
  async function emitVerifyNotEditable(locator) {
804
- const commands = [{
805
- level: 0,
806
- statement: `{`
807
- }, {
808
- level: 1,
809
- statement: `const element = await driver.findElement(${await _location.default.emit(locator)})`
810
- }, {
811
- level: 1,
812
- statement: 'assert(!await element.isEnabled())'
813
- }, {
814
- level: 0,
815
- statement: `}`
816
- }];
817
- return Promise.resolve({
818
- commands
819
- });
820
- }
821
-
670
+ const commands = [
671
+ { level: 0, statement: `{` },
672
+ {
673
+ level: 1,
674
+ statement: `const element = await driver.findElement(${await location_1.default.emit(locator)})`,
675
+ },
676
+ { level: 1, statement: 'assert(!await element.isEnabled())' },
677
+ { level: 0, statement: `}` },
678
+ ];
679
+ return Promise.resolve({ commands });
680
+ }
822
681
  async function emitVerifyNotSelectedValue(locator, expectedValue) {
823
- const commands = [{
824
- level: 0,
825
- statement: `{`
826
- }, {
827
- level: 1,
828
- statement: `const value = await driver.findElement(${await _location.default.emit(locator)}).getAttribute("value")`
829
- }, {
830
- level: 1,
831
- statement: `assert(value !== "${_sideUtils.codeExport.emit.text(expectedValue)}")`
832
- }, {
833
- level: 0,
834
- statement: `}`
835
- }];
836
- return Promise.resolve({
837
- commands
838
- });
839
- }
840
-
682
+ const commands = [
683
+ { level: 0, statement: `{` },
684
+ {
685
+ level: 1,
686
+ statement: `const value = await driver.findElement(${await location_1.default.emit(locator)}).getAttribute("value")`,
687
+ },
688
+ {
689
+ level: 1,
690
+ statement: `assert(value !== "${side_code_export_1.codeExport.emit.text(expectedValue)}")`,
691
+ },
692
+ { level: 0, statement: `}` },
693
+ ];
694
+ return Promise.resolve({ commands });
695
+ }
841
696
  async function emitVerifyNotText(locator, text) {
842
- const commands = [{
843
- level: 0,
844
- statement: `{`
845
- }, {
846
- level: 1,
847
- statement: `const text = await driver.findElement(${await _location.default.emit(locator)}).getText()`
848
- }, {
849
- level: 1,
850
- statement: `assert(text !== "${_sideUtils.codeExport.emit.text(text)}")`
851
- }, {
852
- level: 0,
853
- statement: `}`
854
- }];
855
- return Promise.resolve({
856
- commands
857
- });
858
- }
859
-
697
+ const commands = [
698
+ { level: 0, statement: `{` },
699
+ {
700
+ level: 1,
701
+ statement: `const text = await driver.findElement(${await location_1.default.emit(locator)}).getText()`,
702
+ },
703
+ { level: 1, statement: `assert(text !== "${side_code_export_1.codeExport.emit.text(text)}")` },
704
+ { level: 0, statement: `}` },
705
+ ];
706
+ return Promise.resolve({ commands });
707
+ }
860
708
  async function emitVerifySelectedLabel(locator, labelValue) {
861
- const commands = [{
862
- level: 0,
863
- statement: `{`
864
- }, {
865
- level: 1,
866
- statement: `const element = await driver.findElement(${await _location.default.emit(locator)})`
867
- }, {
868
- level: 1,
869
- statement: 'const locator = `option[@value=\'${await element.getAttribute("value")}\']`'
870
- }, {
871
- level: 1,
872
- statement: 'const selectedText = await element.findElement(By.xpath(locator)).getText()'
873
- }, {
874
- level: 1,
875
- statement: `assert(selectedText == "${labelValue}")`
876
- }, {
877
- level: 0,
878
- statement: `}`
879
- }];
880
- return Promise.resolve({
881
- commands
882
- });
883
- }
884
-
709
+ const commands = [
710
+ { level: 0, statement: `{` },
711
+ {
712
+ level: 1,
713
+ statement: `const element = await driver.findElement(${await location_1.default.emit(locator)})`,
714
+ },
715
+ {
716
+ level: 1,
717
+ statement: 'const locator = `option[@value=\'${await element.getAttribute("value")}\']`',
718
+ },
719
+ {
720
+ level: 1,
721
+ statement: 'const selectedText = await element.findElement(By.xpath(locator)).getText()',
722
+ },
723
+ { level: 1, statement: `assert(selectedText == "${labelValue}")` },
724
+ { level: 0, statement: `}` },
725
+ ];
726
+ return Promise.resolve({
727
+ commands,
728
+ });
729
+ }
885
730
  async function emitVerifyText(locator, text) {
886
- const commands = [{
887
- level: 0,
888
- statement: `assert(await driver.findElement(${await _location.default.emit(locator)}).getText() == "${_sideUtils.codeExport.emit.text(text)}")`
889
- }];
890
- return Promise.resolve({
891
- commands
892
- });
893
- }
894
-
731
+ const commands = [
732
+ {
733
+ level: 0,
734
+ statement: `assert(await driver.findElement(${await location_1.default.emit(locator)}).getText() == "${side_code_export_1.codeExport.emit.text(text)}")`,
735
+ },
736
+ ];
737
+ return Promise.resolve({ commands });
738
+ }
895
739
  async function emitVerifyValue(locator, value) {
896
- const commands = [{
897
- level: 0,
898
- statement: `{`
899
- }, {
900
- level: 1,
901
- statement: `const value = await driver.findElement(${await _location.default.emit(locator)}).getAttribute("value")`
902
- }, {
903
- level: 1,
904
- statement: `assert(value == "${value}")`
905
- }, {
906
- level: 0,
907
- statement: `}`
908
- }];
909
- return Promise.resolve({
910
- commands
911
- });
912
- }
913
-
740
+ const commands = [
741
+ { level: 0, statement: `{` },
742
+ {
743
+ level: 1,
744
+ statement: `const value = await driver.findElement(${await location_1.default.emit(locator)}).getAttribute("value")`,
745
+ },
746
+ { level: 1, statement: `assert(value == "${value}")` },
747
+ { level: 0, statement: `}` },
748
+ ];
749
+ return Promise.resolve({ commands });
750
+ }
914
751
  async function emitVerifyTitle(title) {
915
- return Promise.resolve(`assert(await driver.getTitle() == "${title}")`);
752
+ return Promise.resolve(`assert(await driver.getTitle() == "${title}")`);
916
753
  }
917
-
918
754
  function skip() {
919
- return Promise.resolve(undefined);
755
+ return Promise.resolve('');
920
756
  }
921
-
922
757
  async function emitWaitForElementPresent(locator, timeout) {
923
- return Promise.resolve(`await driver.wait(until.elementLocated(${await _location.default.emit(locator)}), ${Math.floor(timeout)})`);
758
+ return Promise.resolve(`await driver.wait(until.elementLocated(${await location_1.default.emit(locator)}), ${Math.floor(timeout)})`);
924
759
  }
925
-
926
760
  async function emitWaitForElementNotPresent(locator, timeout) {
927
- return Promise.resolve(`await driver.wait(until.stalenessOf(await driver.findElement(${await _location.default.emit(locator)})), ${Math.floor(timeout)})`);
761
+ return Promise.resolve(`await driver.wait(until.stalenessOf(await driver.findElement(${await location_1.default.emit(locator)})), ${Math.floor(timeout)})`);
928
762
  }
929
-
930
763
  async function emitWaitForElementVisible(locator, timeout) {
931
- return Promise.resolve(`await driver.wait(until.elementIsVisible(await driver.findElement(${await _location.default.emit(locator)})), ${Math.floor(timeout)})`);
764
+ return Promise.resolve(`await driver.wait(until.elementIsVisible(await driver.findElement(${await location_1.default.emit(locator)})), ${Math.floor(timeout)})`);
932
765
  }
933
-
934
766
  async function emitWaitForElementNotVisible(locator, timeout) {
935
- return Promise.resolve(`await driver.wait(until.elementIsNotVisible(await driver.findElement(${await _location.default.emit(locator)})), ${Math.floor(timeout)})`);
767
+ return Promise.resolve(`await driver.wait(until.elementIsNotVisible(await driver.findElement(${await location_1.default.emit(locator)})), ${Math.floor(timeout)})`);
936
768
  }
937
-
938
769
  async function emitWaitForElementEditable(locator, timeout) {
939
- return Promise.resolve(`await driver.wait(until.elementIsEnabled(await driver.findElement(${await _location.default.emit(locator)})), ${Math.floor(timeout)})`);
770
+ return Promise.resolve(`await driver.wait(until.elementIsEnabled(await driver.findElement(${await location_1.default.emit(locator)})), ${Math.floor(timeout)})`);
940
771
  }
941
-
942
772
  async function emitWaitForElementNotEditable(locator, timeout) {
943
- return Promise.resolve(`await driver.wait(until.elementIsDisabled(await driver.findElement(${await _location.default.emit(locator)})), ${Math.floor(timeout)})`);
773
+ return Promise.resolve(`await driver.wait(until.elementIsDisabled(await driver.findElement(${await location_1.default.emit(locator)})), ${Math.floor(timeout)})`);
944
774
  }
945
-
946
775
  async function emitWaitForText(locator, text) {
947
- const timeout = 30000;
948
- return Promise.resolve(`await driver.wait(until.elementTextIs(await driver.findElement(${await _location.default.emit(locator)}), '${text}'), ${Math.floor(timeout)})`);
949
- }
950
-
951
- var _default = {
952
- canEmit,
953
- emit,
954
- register,
955
- extras: {
956
- emitWaitForWindow
957
- }
776
+ const timeout = 30000;
777
+ return Promise.resolve(`await driver.wait(until.elementTextIs(await driver.findElement(${await location_1.default.emit(locator)}), '${text}'), ${Math.floor(timeout)})`);
778
+ }
779
+ exports.default = {
780
+ emit,
781
+ emitters: exports.emitters,
782
+ extras: { emitNewWindowHandling, emitWaitForWindow },
783
+ register,
958
784
  };
959
- exports.default = _default;
785
+ //# sourceMappingURL=command.js.map