@seleniumhq/code-export-javascript-mocha 3.17.2 → 3.17.4

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 DELETED
@@ -1,959 +0,0 @@
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
- // Licensed to the Software Freedom Conservancy (SFC) under one
17
- // or more contributor license agreements. See the NOTICE file
18
- // distributed with this work for additional information
19
- // regarding copyright ownership. The SFC licenses this file
20
- // to you under the Apache License, Version 2.0 (the
21
- // "License"); you may not use this file except in compliance
22
- // with the License. You may obtain a copy of the License at
23
- //
24
- // http://www.apache.org/licenses/LICENSE-2.0
25
- //
26
- // Unless required by applicable law or agreed to in writing,
27
- // software distributed under the License is distributed on an
28
- // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
29
- // KIND, either express or implied. See the License for the
30
- // specific language governing permissions and limitations
31
- // 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
131
- };
132
- exports.emitters = emitters;
133
-
134
- _sideUtils.codeExport.register.preprocessors(emitters);
135
-
136
- function register(command, emitter) {
137
- _sideUtils.codeExport.register.emitter({
138
- command,
139
- emitter,
140
- emitters
141
- });
142
- }
143
-
144
- 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];
153
- }
154
-
155
- function variableLookup(varName) {
156
- return `vars["${varName}"]`;
157
- }
158
-
159
- function variableSetter(varName, value) {
160
- return varName ? `vars["${varName}"] = ${value}` : '';
161
- }
162
-
163
- function emitWaitForWindow() {
164
- const generateMethodDeclaration = name => {
165
- return {
166
- body: `async function ${name}(timeout = 2) {`,
167
- terminatingKeyword: '}'
168
- };
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
-
200
- async function emitNewWindowHandling(command, emittedCommand) {
201
- return Promise.resolve(`vars["windowHandles"] = await driver.getAllWindowHandles()\n${await emittedCommand}\nvars["${command.windowHandleName}"] = await waitForWindow(${command.windowTimeout})`);
202
- }
203
-
204
- function emitAssert(varName, value) {
205
- return Promise.resolve(`assert(vars["${varName}"].toString() == "${value}")`);
206
- }
207
-
208
- function emitAssertAlert(alertText) {
209
- return Promise.resolve(`assert(await driver.switchTo().alert().getText() == "${alertText}")`);
210
- }
211
-
212
- 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
-
234
- 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
-
253
- function emitChooseCancelOnNextConfirmation() {
254
- return Promise.resolve(`await driver.switchTo().alert().dismiss()`);
255
- }
256
-
257
- function emitChooseOkOnNextConfirmation() {
258
- return Promise.resolve(`await driver.switchTo().alert().accept()`);
259
- }
260
-
261
- async function emitClick(target) {
262
- return Promise.resolve(`await driver.findElement(${await _location.default.emit(target)}).click()`);
263
- }
264
-
265
- async function emitClose() {
266
- return Promise.resolve(`await driver.close()`);
267
- }
268
-
269
- function generateExpressionScript(script) {
270
- return `await driver.executeScript("return (${script.script})"${generateScriptArguments(script)})`;
271
- }
272
-
273
- function generateScriptArguments(script) {
274
- return `${script.argv.length ? ', ' : ''}${script.argv.map(varName => `vars["${varName}"]`).join(',')}`;
275
- }
276
-
277
- function emitControlFlowDo() {
278
- return Promise.resolve({
279
- commands: [{
280
- level: 0,
281
- statement: 'do {'
282
- }],
283
- endingLevelAdjustment: 1
284
- });
285
- }
286
-
287
- function emitControlFlowElse() {
288
- return Promise.resolve({
289
- commands: [{
290
- level: 0,
291
- statement: '} else {'
292
- }],
293
- startingLevelAdjustment: -1,
294
- endingLevelAdjustment: +1
295
- });
296
- }
297
-
298
- 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
-
309
- function emitControlFlowEnd() {
310
- return Promise.resolve({
311
- commands: [{
312
- level: 0,
313
- statement: `}`
314
- }],
315
- startingLevelAdjustment: -1
316
- });
317
- }
318
-
319
- function emitControlFlowIf(script) {
320
- return Promise.resolve({
321
- commands: [{
322
- level: 0,
323
- statement: `if (!!${generateExpressionScript(script)}) {`
324
- }],
325
- endingLevelAdjustment: 1
326
- });
327
- }
328
-
329
- 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
-
344
- function emitControlFlowRepeatIf(script) {
345
- return Promise.resolve({
346
- commands: [{
347
- level: 0,
348
- statement: `} while(!!${generateExpressionScript(script)})`
349
- }],
350
- startingLevelAdjustment: -1
351
- });
352
- }
353
-
354
- 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
-
368
- function emitControlFlowWhile(script) {
369
- return Promise.resolve({
370
- commands: [{
371
- level: 0,
372
- statement: `while(!!${generateExpressionScript(script)}) {`
373
- }],
374
- endingLevelAdjustment: 1
375
- });
376
- }
377
-
378
- 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
-
397
- 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
-
419
- async function emitEcho(message) {
420
- const _message = message.startsWith('vars[') ? message : `"${message}"`;
421
-
422
- return Promise.resolve(`console.log(${_message})`);
423
- }
424
-
425
- 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
-
444
- 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));
448
- }
449
-
450
- 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));
453
- }
454
-
455
- 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
-
474
- 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
-
493
- 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
-
512
- 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
-
531
- function emitOpen(target) {
532
- const url = /^(file|http|https):\/\//.test(target) ? `"${target}"` : `"${global.baseUrl}${target}"`;
533
- return Promise.resolve(`await driver.get(${url})`);
534
- }
535
-
536
- 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
-
546
- async function emitRun(testName) {
547
- return Promise.resolve(`${_sideUtils.codeExport.parsers.sanitizeName(testName)}()`);
548
- }
549
-
550
- async function emitRunScript(script) {
551
- return Promise.resolve(`await driver.executeScript("${script.script}${generateScriptArguments(script)}")`);
552
- }
553
-
554
- async function emitSetWindowSize(size) {
555
- const [width, height] = size.split('x');
556
- return Promise.resolve(`await driver.manage().window().setRect({ width: ${width}, height: ${height} })`);
557
- }
558
-
559
- 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
-
578
- 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
- }
600
- }
601
-
602
- 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
- });
623
- }
624
- } else {
625
- return Promise.reject(new Error('Can only emit `select window` using handles'));
626
- }
627
- }
628
-
629
- 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}"`;
646
- }
647
- }
648
- }
649
-
650
- async function emitSendKeys(target, value) {
651
- return Promise.resolve(`await driver.findElement(${await _location.default.emit(target)}).sendKeys(${generateSendKeysInput(value)})`);
652
- }
653
-
654
- function emitSetSpeed() {
655
- return Promise.resolve('console.log("`set speed` is a no-op in code export, use `pause` instead")');
656
- }
657
-
658
- async function emitStore(value, varName) {
659
- return Promise.resolve(variableSetter(varName, `"${value}"`));
660
- }
661
-
662
- 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
-
684
- async function emitStoreJson(json, varName) {
685
- return Promise.resolve(variableSetter(varName, `JSON.parse('${json}')`));
686
- }
687
-
688
- async function emitStoreText(locator, varName) {
689
- const result = `await driver.findElement(${await _location.default.emit(locator)}).getText()`;
690
- return Promise.resolve(variableSetter(varName, result));
691
- }
692
-
693
- async function emitStoreTitle(_, varName) {
694
- return Promise.resolve(variableSetter(varName, 'await driver.getTitle()'));
695
- }
696
-
697
- 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));
700
- }
701
-
702
- async function emitStoreWindowHandle(varName) {
703
- return Promise.resolve(variableSetter(varName, 'await driver.getWindowHandle()'));
704
- }
705
-
706
- async function emitStoreXpathCount(locator, varName) {
707
- const result = `await driver.findElements(${await _location.default.emit(locator)}).length`;
708
- return Promise.resolve(variableSetter(varName, result));
709
- }
710
-
711
- 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.")`);
713
- }
714
-
715
- async function emitType(target, value) {
716
- return Promise.resolve(`await driver.findElement(${await _location.default.emit(target)}).sendKeys(${generateSendKeysInput(value)})`);
717
- }
718
-
719
- 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
-
738
- async function emitVerifyChecked(locator) {
739
- return Promise.resolve(`assert(await driver.findElement(${await _location.default.emit(locator)}).isSelected())`);
740
- }
741
-
742
- 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
-
761
- 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
-
780
- 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
-
799
- async function emitVerifyNotChecked(locator) {
800
- return Promise.resolve(`assert(!await driver.findElement(${await _location.default.emit(locator)}).isSelected())`);
801
- }
802
-
803
- 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
-
822
- 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
-
841
- 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
-
860
- 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
-
885
- 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
-
895
- 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
-
914
- async function emitVerifyTitle(title) {
915
- return Promise.resolve(`assert(await driver.getTitle() == "${title}")`);
916
- }
917
-
918
- function skip() {
919
- return Promise.resolve(undefined);
920
- }
921
-
922
- async function emitWaitForElementPresent(locator, timeout) {
923
- return Promise.resolve(`await driver.wait(until.elementLocated(${await _location.default.emit(locator)}), ${Math.floor(timeout)})`);
924
- }
925
-
926
- 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)})`);
928
- }
929
-
930
- 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)})`);
932
- }
933
-
934
- 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)})`);
936
- }
937
-
938
- 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)})`);
940
- }
941
-
942
- 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)})`);
944
- }
945
-
946
- 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
- }
958
- };
959
- exports.default = _default;