@seleniumhq/code-export-csharp-commons 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,1135 +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: emitVerifySelectedValue,
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: emitVerifySelectedValue,
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
- waitForText: emitWaitForText,
126
- webDriverAnswerOnVisiblePrompt: emitAnswerOnNextPrompt,
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}"].ToString()`;
157
- }
158
-
159
- function variableSetter(varName, value) {
160
- return varName ? `vars["${varName}"] = ${value};` : '';
161
- }
162
-
163
- function emitWaitForWindow() {
164
- const generateMethodDeclaration = name => {
165
- return `public string ${name}(int timeout) {`;
166
- };
167
-
168
- const commands = [{
169
- level: 0,
170
- statement: 'try {'
171
- }, {
172
- level: 1,
173
- statement: 'Thread.Sleep(timeout);'
174
- }, {
175
- level: 0,
176
- statement: '} catch(Exception e) {'
177
- }, {
178
- level: 1,
179
- statement: 'Console.WriteLine("{0} Exception caught.", e);'
180
- }, {
181
- level: 0,
182
- statement: '}'
183
- }, {
184
- level: 0,
185
- statement: 'var whNow = ((IReadOnlyCollection<object>)driver.WindowHandles).ToList();'
186
- }, {
187
- level: 0,
188
- statement: 'var whThen = ((IReadOnlyCollection<object>)vars["WindowHandles"]).ToList();'
189
- }, {
190
- level: 0,
191
- statement: 'if (whNow.Count > whThen.Count) {'
192
- }, {
193
- level: 1,
194
- statement: 'return whNow.Except(whThen).First().ToString();'
195
- }, {
196
- level: 0,
197
- statement: '} else {'
198
- }, {
199
- level: 1,
200
- statement: 'return whNow.First().ToString();'
201
- }, {
202
- level: 0,
203
- statement: '}'
204
- }];
205
- return Promise.resolve({
206
- name: 'waitForWindow',
207
- commands,
208
- generateMethodDeclaration
209
- });
210
- }
211
-
212
- async function emitNewWindowHandling(command, emittedCommand) {
213
- return Promise.resolve(`vars["WindowHandles"] = driver.WindowHandles;\n${await emittedCommand}\nvars["${command.windowHandleName}"] = waitForWindow(${command.windowTimeout});`);
214
- }
215
-
216
- function emitAssert(varName, value) {
217
- const _value = value === 'true' || value === 'false' ? _sideUtils.codeExport.parsers.capitalize(value) : value;
218
-
219
- return Promise.resolve(`Assert.That(vars["${varName}"].ToString(), Is.EqualTo("${_value}"));`);
220
- }
221
-
222
- function emitAssertAlert(alertText) {
223
- return Promise.resolve(`Assert.That(driver.SwitchTo().Alert().Text, Is.EqualTo("${alertText}"));`);
224
- }
225
-
226
- function emitAnswerOnNextPrompt(textToSend) {
227
- const commands = [{
228
- level: 0,
229
- statement: '{'
230
- }, {
231
- level: 1,
232
- statement: 'var Alert = driver.SwitchTo().Alert();'
233
- }, {
234
- level: 1,
235
- statement: `Alert.SendKeys("${textToSend}")`
236
- }, {
237
- level: 1,
238
- statement: 'Alert.Accept();'
239
- }, {
240
- level: 0,
241
- statement: '}'
242
- }];
243
- return Promise.resolve({
244
- commands
245
- });
246
- }
247
-
248
- async function emitCheck(locator) {
249
- const commands = [{
250
- level: 0,
251
- statement: '{'
252
- }, {
253
- level: 1,
254
- statement: `var element = driver.FindElement(${await _location.default.emit(locator)});`
255
- }, {
256
- level: 1,
257
- statement: 'if (!element.Selected) {'
258
- }, {
259
- level: 2,
260
- statement: 'element.Click();'
261
- }, {
262
- level: 1,
263
- statement: '}'
264
- }, {
265
- level: 0,
266
- statement: '}'
267
- }];
268
- return Promise.resolve({
269
- commands
270
- });
271
- }
272
-
273
- function emitChooseCancelOnNextConfirmation() {
274
- return Promise.resolve(`driver.SwitchTo().Alert().Dismiss();`);
275
- }
276
-
277
- function emitChooseOkOnNextConfirmation() {
278
- return Promise.resolve(`driver.SwitchTo().Alert().Accept();`);
279
- }
280
-
281
- async function emitClick(target) {
282
- return Promise.resolve(`driver.FindElement(${await _location.default.emit(target)}).Click();`);
283
- }
284
-
285
- async function emitClose() {
286
- return Promise.resolve(`driver.Close();`);
287
- }
288
-
289
- function generateExpressionScript(script) {
290
- const scriptString = script.script.replace(/"/g, "'");
291
- return `(Boolean) js.ExecuteScript("return (${scriptString})"${generateScriptArguments(script)})`;
292
- }
293
-
294
- function emitControlFlowDo() {
295
- return Promise.resolve({
296
- commands: [{
297
- level: 0,
298
- statement: 'do {'
299
- }],
300
- endingLevelAdjustment: 1
301
- });
302
- }
303
-
304
- function emitControlFlowElse() {
305
- return Promise.resolve({
306
- commands: [{
307
- level: 0,
308
- statement: '} else {'
309
- }],
310
- startingLevelAdjustment: -1,
311
- endingLevelAdjustment: +1
312
- });
313
- }
314
-
315
- function emitControlFlowElseIf(script) {
316
- return Promise.resolve({
317
- commands: [{
318
- level: 0,
319
- statement: `} else if (${generateExpressionScript(script)}) {`
320
- }],
321
- startingLevelAdjustment: -1,
322
- endingLevelAdjustment: +1
323
- });
324
- }
325
-
326
- function emitControlFlowEnd() {
327
- return Promise.resolve({
328
- commands: [{
329
- level: 0,
330
- statement: `}`
331
- }],
332
- startingLevelAdjustment: -1
333
- });
334
- }
335
-
336
- function emitControlFlowIf(script) {
337
- return Promise.resolve({
338
- commands: [{
339
- level: 0,
340
- statement: `if (${generateExpressionScript(script)}) {`
341
- }],
342
- endingLevelAdjustment: 1
343
- });
344
- }
345
-
346
- function emitControlFlowForEach(collectionVarName, iteratorVarName) {
347
- return Promise.resolve({
348
- commands: [{
349
- level: 0,
350
- statement: `var ${collectionVarName}Enum = ((IReadOnlyCollection<object>)vars["${collectionVarName}"]).ToList().GetEnumerator();`
351
- }, {
352
- level: 0,
353
- statement: `while (${collectionVarName}Enum.MoveNext())`
354
- }, {
355
- level: 0,
356
- statement: `{`
357
- }, {
358
- level: 1,
359
- statement: `vars["${iteratorVarName}"] = ${collectionVarName}Enum.Current;`
360
- }]
361
- });
362
- }
363
-
364
- function emitControlFlowRepeatIf(script) {
365
- return Promise.resolve({
366
- commands: [{
367
- level: 0,
368
- statement: `} while (${generateExpressionScript(script)});`
369
- }],
370
- startingLevelAdjustment: -1
371
- });
372
- }
373
-
374
- function emitControlFlowTimes(target) {
375
- const commands = [{
376
- level: 0,
377
- statement: `var times = ${target};`
378
- }, {
379
- level: 0,
380
- statement: 'for(int i = 0; i < times; i++) {'
381
- }];
382
- return Promise.resolve({
383
- commands,
384
- endingLevelAdjustment: 1
385
- });
386
- }
387
-
388
- function emitControlFlowWhile(script) {
389
- return Promise.resolve({
390
- commands: [{
391
- level: 0,
392
- statement: `while (${generateExpressionScript(script)}) {`
393
- }],
394
- endingLevelAdjustment: 1
395
- });
396
- }
397
-
398
- async function emitDoubleClick(target) {
399
- const commands = [{
400
- level: 0,
401
- statement: '{'
402
- }, {
403
- level: 1,
404
- statement: `var element = driver.FindElement(${await _location.default.emit(target)});`
405
- }, {
406
- level: 1,
407
- statement: 'Actions builder = new Actions(driver);'
408
- }, {
409
- level: 1,
410
- statement: 'builder.DoubleClick(element).Perform();'
411
- }, {
412
- level: 0,
413
- statement: '}'
414
- }];
415
- return Promise.resolve({
416
- commands
417
- });
418
- }
419
-
420
- async function emitDragAndDrop(dragged, dropped) {
421
- const commands = [{
422
- level: 0,
423
- statement: '{'
424
- }, {
425
- level: 1,
426
- statement: `var dragged = driver.FindElement(${await _location.default.emit(dragged)});`
427
- }, {
428
- level: 1,
429
- statement: `var dropped = driver.FindElement(${await _location.default.emit(dropped)});`
430
- }, {
431
- level: 1,
432
- statement: 'Actions builder = new Actions(driver);'
433
- }, {
434
- level: 1,
435
- statement: 'builder.DragAndDrop(dragged, dropped).Perform();'
436
- }, {
437
- level: 0,
438
- statement: '}'
439
- }];
440
- return Promise.resolve({
441
- commands
442
- });
443
- }
444
-
445
- async function emitEcho(message) {
446
- const _message = message.startsWith('vars[') ? message : `"${message}"`;
447
-
448
- return Promise.resolve(`Console.WriteLine(${_message});`);
449
- }
450
-
451
- async function emitEditContent(locator, content) {
452
- const commands = [{
453
- level: 0,
454
- statement: '{'
455
- }, {
456
- level: 1,
457
- statement: `var element = driver.FindElement(${await _location.default.emit(locator)});`
458
- }, {
459
- level: 1,
460
- statement: `js.ExecuteScript("if(arguments[0].contentEditable === 'true') {arguments[0].innerText = '${content}'}", element);`
461
- }, {
462
- level: 0,
463
- statement: '}'
464
- }];
465
- return Promise.resolve({
466
- commands
467
- });
468
- }
469
-
470
- async function emitExecuteScript(script, varName) {
471
- const result = `js.ExecuteScript("${script.script}"${generateScriptArguments(script)})`;
472
- return Promise.resolve(variableSetter(varName, result));
473
- }
474
-
475
- async function emitExecuteAsyncScript(script, varName) {
476
- const result = `js.executeAsyncScript("var callback = arguments[arguments.length - 1];${script.script}.then(callback).catch(callback);${generateScriptArguments(script)}")`;
477
- return Promise.resolve(variableSetter(varName, result));
478
- }
479
-
480
- function generateScriptArguments(script) {
481
- return `${script.argv.length ? ', ' : ''}${script.argv.map(varName => `vars["${varName}"]`).join(',')}`;
482
- }
483
-
484
- async function emitMouseDown(locator) {
485
- const commands = [{
486
- level: 0,
487
- statement: '{'
488
- }, {
489
- level: 1,
490
- statement: `var element = driver.FindElement(${await _location.default.emit(locator)});`
491
- }, {
492
- level: 1,
493
- statement: 'Actions builder = new Actions(driver);'
494
- }, {
495
- level: 1,
496
- statement: 'builder.MoveToElement(element).ClickAndHold().Perform();'
497
- }, {
498
- level: 0,
499
- statement: '}'
500
- }];
501
- return Promise.resolve({
502
- commands
503
- });
504
- }
505
-
506
- async function emitMouseMove(locator) {
507
- const commands = [{
508
- level: 0,
509
- statement: '{'
510
- }, {
511
- level: 1,
512
- statement: `var element = driver.FindElement(${await _location.default.emit(locator)});`
513
- }, {
514
- level: 1,
515
- statement: 'Actions builder = new Actions(driver);'
516
- }, {
517
- level: 1,
518
- statement: 'builder.MoveToElement(element).Perform();'
519
- }, {
520
- level: 0,
521
- statement: '}'
522
- }];
523
- return Promise.resolve({
524
- commands
525
- });
526
- }
527
-
528
- async function emitMouseOut() {
529
- const commands = [{
530
- level: 0,
531
- statement: '{'
532
- }, {
533
- level: 1,
534
- statement: `var element = driver.FindElement(By.tagName("body"));`
535
- }, {
536
- level: 1,
537
- statement: 'Actions builder = new Actions(driver);'
538
- }, {
539
- level: 1,
540
- statement: 'builder.MoveToElement(element, 0, 0).Perform();'
541
- }, {
542
- level: 0,
543
- statement: '}'
544
- }];
545
- return Promise.resolve({
546
- commands
547
- });
548
- }
549
-
550
- async function emitMouseUp(locator) {
551
- const commands = [{
552
- level: 0,
553
- statement: '{'
554
- }, {
555
- level: 1,
556
- statement: `var element = driver.FindElement(${await _location.default.emit(locator)});`
557
- }, {
558
- level: 1,
559
- statement: 'Actions builder = new Actions(driver);'
560
- }, {
561
- level: 1,
562
- statement: 'builder.MoveToElement(element).Release().Perform();'
563
- }, {
564
- level: 0,
565
- statement: '}'
566
- }];
567
- return Promise.resolve({
568
- commands
569
- });
570
- }
571
-
572
- function emitOpen(target) {
573
- const url = /^(file|http|https):\/\//.test(target) ? `"${target}"` : `"${global.baseUrl}${target}"`;
574
- return Promise.resolve(`driver.Navigate().GoToUrl(${url});`);
575
- }
576
-
577
- async function emitPause(time) {
578
- const commands = [{
579
- level: 0,
580
- statement: 'try {'
581
- }, {
582
- level: 1,
583
- statement: `Thread.Sleep(${time});`
584
- }, {
585
- level: 0,
586
- statement: '} catch (Exception e) {'
587
- }, {
588
- level: 1,
589
- statement: 'Console.WriteLine("{0} Exception caught.", e);'
590
- }, {
591
- level: 0,
592
- statement: '}'
593
- }];
594
- return Promise.resolve({
595
- commands
596
- });
597
- }
598
-
599
- async function emitRun(testName) {
600
- return Promise.resolve(`${_sideUtils.codeExport.parsers.sanitizeName(testName)}();`);
601
- }
602
-
603
- async function emitRunScript(script) {
604
- return Promise.resolve(`js.ExecuteScript("${script.script}${generateScriptArguments(script)}");`);
605
- }
606
-
607
- async function emitSetWindowSize(size) {
608
- const [width, height] = size.split('x');
609
- return Promise.resolve(`driver.Manage().Window.Size = new System.Drawing.Size(${width}, ${height});`);
610
- }
611
-
612
- async function emitSelect(selectElement, option) {
613
- const commands = [{
614
- level: 0,
615
- statement: '{'
616
- }, {
617
- level: 1,
618
- statement: `var dropdown = driver.FindElement(${await _location.default.emit(selectElement)});`
619
- }, {
620
- level: 1,
621
- statement: `dropdown.FindElement(${await _selection.default.emit(option)}).Click();`
622
- }, {
623
- level: 0,
624
- statement: '}'
625
- }];
626
- return Promise.resolve({
627
- commands
628
- });
629
- }
630
-
631
- async function emitSelectFrame(frameLocation) {
632
- if (frameLocation === 'relative=top' || frameLocation === 'relative=parent') {
633
- return Promise.resolve('driver.SwitchTo().DefaultContent();');
634
- } else if (/^index=/.test(frameLocation)) {
635
- return Promise.resolve(`driver.SwitchTo().Frame(${Math.floor(frameLocation.split('index=')[1])});`);
636
- } else {
637
- return Promise.resolve({
638
- commands: [{
639
- level: 0,
640
- statement: '{'
641
- }, {
642
- level: 1,
643
- statement: `var element = driver.FindElement(${await _location.default.emit(frameLocation)});`
644
- }, {
645
- level: 1,
646
- statement: 'driver.SwitchTo().Frame(element);'
647
- }, {
648
- level: 0,
649
- statement: '}'
650
- }]
651
- });
652
- }
653
- }
654
-
655
- async function emitSelectWindow(windowLocation) {
656
- if (/^handle=/.test(windowLocation)) {
657
- return Promise.resolve(`driver.SwitchTo().Window(${windowLocation.split('handle=')[1]});`);
658
- } else if (/^name=/.test(windowLocation)) {
659
- return Promise.resolve(`driver.SwitchTo().Window("${windowLocation.split('name=')[1]}");`);
660
- } else if (/^win_ser_/.test(windowLocation)) {
661
- if (windowLocation === 'win_ser_local') {
662
- return Promise.resolve({
663
- commands: [{
664
- level: 0,
665
- statement: '{'
666
- }, {
667
- level: 1,
668
- statement: 'ArrayList<string> handles = new ArrayList<string>(driver.WindowHandles());'
669
- }, {
670
- level: 1,
671
- statement: 'driver.SwitchTo().Window(handles[0]);'
672
- }, {
673
- level: 0,
674
- statement: '}'
675
- }]
676
- });
677
- } else {
678
- const index = parseInt(windowLocation.substr('win_ser_'.length));
679
- return Promise.resolve({
680
- commands: [{
681
- level: 0,
682
- statement: '{'
683
- }, {
684
- level: 1,
685
- statement: 'ArrayList<string> handles = new ArrayList<string>(driver.WindowHandles);'
686
- }, {
687
- level: 1,
688
- statement: `driver.SwitchTo().Window(handles[${index}]);`
689
- }, {
690
- level: 0,
691
- statement: '}'
692
- }]
693
- });
694
- }
695
- } else {
696
- return Promise.reject(new Error('Can only emit `select window` using handles'));
697
- }
698
- }
699
-
700
- function generateSendKeysInput(value) {
701
- if (typeof value === 'object') {
702
- return value.map(s => {
703
- if (s.startsWith('vars[')) {
704
- return s;
705
- } else if (s.startsWith('Key[')) {
706
- const key = s.match(/\['(.*)'\]/)[1];
707
- return `Keys.${_sideUtils.codeExport.parsers.capitalize(key.toLowerCase())}`;
708
- } else {
709
- return `"${s}"`;
710
- }
711
- }).join(' + ');
712
- } else {
713
- if (value.startsWith('vars[')) {
714
- return value;
715
- } else {
716
- return `"${value}"`;
717
- }
718
- }
719
- }
720
-
721
- async function emitSendKeys(target, value) {
722
- return Promise.resolve(`driver.FindElement(${await _location.default.emit(target)}).SendKeys(${generateSendKeysInput(value)});`);
723
- }
724
-
725
- function emitSetSpeed() {
726
- return Promise.resolve(`Console.WriteLine("\`set speed\` is a no-op in code export, use \`pause\` instead");`);
727
- }
728
-
729
- async function emitStore(value, varName) {
730
- return Promise.resolve(variableSetter(varName, `"${value}"`));
731
- }
732
-
733
- async function emitStoreAttribute(locator, varName) {
734
- const attributePos = locator.lastIndexOf('@');
735
- const elementLocator = locator.slice(0, attributePos);
736
- const attributeName = locator.slice(attributePos + 1);
737
- const commands = [{
738
- level: 0,
739
- statement: '{'
740
- }, {
741
- level: 1,
742
- statement: `var element = driver.FindElement(${await _location.default.emit(elementLocator)});`
743
- }, {
744
- level: 1,
745
- statement: `string attribute = element.GetAttribute("${attributeName}");`
746
- }, {
747
- level: 1,
748
- statement: `${variableSetter(varName, 'attribute')}`
749
- }, {
750
- level: 0,
751
- statement: '}'
752
- }];
753
- return Promise.resolve({
754
- commands
755
- });
756
- }
757
-
758
- async function emitStoreJson(_json, _varName) {
759
- return Promise.resolve('throw new System.Exception("The `storeJson` command is not yet implemented for this language.");');
760
- }
761
-
762
- async function emitStoreText(locator, varName) {
763
- const result = `driver.FindElement(${await _location.default.emit(locator)}).Text`;
764
- return Promise.resolve(variableSetter(varName, result));
765
- }
766
-
767
- async function emitStoreTitle(_, varName) {
768
- return Promise.resolve(variableSetter(varName, 'driver.Title'));
769
- }
770
-
771
- async function emitStoreValue(locator, varName) {
772
- const result = `driver.FindElement(${await _location.default.emit(locator)}).GetAttribute("value")`;
773
- return Promise.resolve(variableSetter(varName, result));
774
- }
775
-
776
- async function emitStoreWindowHandle(varName) {
777
- return Promise.resolve(variableSetter(varName, 'driver.CurrentWindowHandle'));
778
- }
779
-
780
- async function emitStoreXpathCount(locator, varName) {
781
- const result = `driver.FindElements(${await _location.default.emit(locator)}).Count`;
782
- return Promise.resolve(variableSetter(varName, result));
783
- }
784
-
785
- async function emitSubmit(_locator) {
786
- return Promise.resolve(`throw new System.Exception("\`submit\` is not a supported command in Selenium WebDriver. Please re-record the step in the IDE.");`);
787
- }
788
-
789
- async function emitType(target, value) {
790
- return Promise.resolve(`driver.FindElement(${await _location.default.emit(target)}).SendKeys(${generateSendKeysInput(value)});`);
791
- }
792
-
793
- async function emitUncheck(locator) {
794
- const commands = [{
795
- level: 0,
796
- statement: '{'
797
- }, {
798
- level: 1,
799
- statement: `var element = driver.FindElement(${await _location.default.emit(locator)});`
800
- }, {
801
- level: 1,
802
- statement: 'if (element.Selected) {'
803
- }, {
804
- level: 2,
805
- statement: 'element.Click();'
806
- }, {
807
- level: 1,
808
- statement: '}'
809
- }, {
810
- level: 0,
811
- statement: '}'
812
- }];
813
- return Promise.resolve({
814
- commands
815
- });
816
- }
817
-
818
- async function emitVerifyChecked(locator) {
819
- return Promise.resolve(`Assert.True(driver.FindElement(${await _location.default.emit(locator)}).Selected);`);
820
- }
821
-
822
- async function emitVerifyEditable(locator) {
823
- const commands = [{
824
- level: 0,
825
- statement: '{'
826
- }, {
827
- level: 1,
828
- statement: `var element = driver.FindElement(${await _location.default.emit(locator)});`
829
- }, {
830
- level: 1,
831
- statement: 'Boolean isEditable = element.Enabled && element.GetAttribute("readonly") == null;'
832
- }, {
833
- level: 1,
834
- statement: 'Assert.True(isEditable);'
835
- }, {
836
- level: 0,
837
- statement: '}'
838
- }];
839
- return Promise.resolve({
840
- commands
841
- });
842
- }
843
-
844
- async function emitVerifyElementPresent(locator) {
845
- const commands = [{
846
- level: 0,
847
- statement: `var elements = driver.FindElements(${await _location.default.emit(locator)});`
848
- }, {
849
- level: 0,
850
- statement: 'Assert.True(elements.Count > 0);'
851
- }];
852
- return Promise.resolve({
853
- commands
854
- });
855
- }
856
-
857
- async function emitVerifyElementNotPresent(locator) {
858
- const commands = [{
859
- level: 0,
860
- statement: '{'
861
- }, {
862
- level: 1,
863
- statement: `var elements = driver.FindElements(${await _location.default.emit(locator)});`
864
- }, {
865
- level: 1,
866
- statement: 'Assert.True(elements.Count == 0);'
867
- }, {
868
- level: 0,
869
- statement: '}'
870
- }];
871
- return Promise.resolve({
872
- commands
873
- });
874
- }
875
-
876
- async function emitVerifyNotChecked(locator) {
877
- return Promise.resolve(`Assert.False(driver.FindElement(${await _location.default.emit(locator)}).Selected);`);
878
- }
879
-
880
- async function emitVerifyNotEditable(locator) {
881
- const commands = [{
882
- level: 0,
883
- statement: '{'
884
- }, {
885
- level: 1,
886
- statement: `var element = driver.FindElement(${await _location.default.emit(locator)});`
887
- }, {
888
- level: 1,
889
- statement: 'Boolean isEditable = element.Enabled && element.GetAttribute("readonly") == null;'
890
- }, {
891
- level: 1,
892
- statement: 'Assert.False(isEditable);'
893
- }, {
894
- level: 0,
895
- statement: '}'
896
- }];
897
- return Promise.resolve({
898
- commands
899
- });
900
- }
901
-
902
- async function emitVerifyNotSelectedValue(locator, expectedValue) {
903
- const commands = [{
904
- level: 0,
905
- statement: '{'
906
- }, {
907
- level: 1,
908
- statement: `string value = driver.FindElement(${await _location.default.emit(locator)}).GetAttribute("value");`
909
- }, {
910
- level: 1,
911
- statement: `Assert.That(value, Is.Not.EqualTo("${_sideUtils.codeExport.emit.text(expectedValue)}"));`
912
- }, {
913
- level: 0,
914
- statement: '}'
915
- }];
916
- return Promise.resolve({
917
- commands
918
- });
919
- }
920
-
921
- async function emitVerifyNotText(locator, text) {
922
- const result = `driver.FindElement(${await _location.default.emit(locator)}).Text`;
923
- return Promise.resolve(`Assert.That(${result}, Is.Not.EqualTo("${_sideUtils.codeExport.emit.text(text)}"));`);
924
- }
925
-
926
- async function emitVerifySelectedLabel(locator, labelValue) {
927
- const commands = [{
928
- level: 0,
929
- statement: '{'
930
- }, {
931
- level: 1,
932
- statement: `var element = driver.FindElement(${await _location.default.emit(locator)});`
933
- }, {
934
- level: 1,
935
- statement: 'string value = element.GetAttribute("value");'
936
- }, {
937
- level: 1,
938
- statement: `string locator = string.Format("option[@value='%s']", value);`
939
- }, {
940
- level: 1,
941
- statement: 'string selectedText = element.FindElement(By.XPath(locator)).Text;'
942
- }, {
943
- level: 1,
944
- statement: `Assert.That(selectedText, Is.EqualTo("${labelValue}"));`
945
- }, {
946
- level: 0,
947
- statement: '}'
948
- }];
949
- return Promise.resolve({
950
- commands
951
- });
952
- }
953
-
954
- async function emitVerifySelectedValue(locator, value) {
955
- return emitVerifyValue(locator, value);
956
- }
957
-
958
- async function emitVerifyText(locator, text) {
959
- return Promise.resolve(`Assert.That(driver.FindElement(${await _location.default.emit(locator)}).Text, Is.EqualTo("${_sideUtils.codeExport.emit.text(text)}"));`);
960
- }
961
-
962
- async function emitVerifyValue(locator, value) {
963
- const commands = [{
964
- level: 0,
965
- statement: '{'
966
- }, {
967
- level: 1,
968
- statement: `string value = driver.FindElement(${await _location.default.emit(locator)}).GetAttribute("value");`
969
- }, {
970
- level: 1,
971
- statement: `Assert.That(value, Is.EqualTo("${value}"));`
972
- }, {
973
- level: 0,
974
- statement: '}'
975
- }];
976
- return Promise.resolve({
977
- commands
978
- });
979
- }
980
-
981
- async function emitVerifyTitle(title) {
982
- return Promise.resolve(`Assert.That(driver.Title, Is.EqualTo("${title}"));`);
983
- }
984
-
985
- async function emitWaitForElementEditable(locator, timeout) {
986
- const commands = [{
987
- level: 0,
988
- statement: '{'
989
- }, {
990
- level: 1,
991
- statement: `WebDriverWait wait = new WebDriverWait(driver, System.TimeSpan.FromSeconds(${Math.floor(timeout / 1000)}));`
992
- }, {
993
- level: 1,
994
- statement: `wait.Until(driver => driver.FindElement(${await _location.default.emit(locator)}).Enabled);`
995
- }, {
996
- level: 0,
997
- statement: '}'
998
- }];
999
- return Promise.resolve({
1000
- commands
1001
- });
1002
- }
1003
-
1004
- async function emitWaitForText(locator, text) {
1005
- const timeout = 30000;
1006
- const commands = [{
1007
- level: 0,
1008
- statement: '{'
1009
- }, {
1010
- level: 1,
1011
- statement: `WebDriverWait wait = new WebDriverWait(driver, System.TimeSpan.FromSeconds(${Math.floor(timeout / 1000)}));`
1012
- }, {
1013
- level: 1,
1014
- statement: `wait.Until(driver => driver.FindElement(${await _location.default.emit(locator)}).Text == "${text}");`
1015
- }, {
1016
- level: 0,
1017
- statement: '}'
1018
- }];
1019
- return Promise.resolve({
1020
- commands
1021
- });
1022
- }
1023
-
1024
- function skip() {
1025
- return Promise.resolve('');
1026
- }
1027
-
1028
- async function emitWaitForElementPresent(locator, timeout) {
1029
- const commands = [{
1030
- level: 0,
1031
- statement: '{'
1032
- }, {
1033
- level: 1,
1034
- statement: `WebDriverWait wait = new WebDriverWait(driver, System.TimeSpan.FromSeconds(${Math.floor(timeout / 1000)}));`
1035
- }, {
1036
- level: 1,
1037
- statement: `wait.Until(driver => driver.FindElements(${await _location.default.emit(locator)}).Count > 0);`
1038
- }, {
1039
- level: 0,
1040
- statement: '}'
1041
- }];
1042
- return Promise.resolve({
1043
- commands
1044
- });
1045
- }
1046
-
1047
- async function emitWaitForElementVisible(locator, timeout) {
1048
- const commands = [{
1049
- level: 0,
1050
- statement: '{'
1051
- }, {
1052
- level: 1,
1053
- statement: `WebDriverWait wait = new WebDriverWait(driver, System.TimeSpan.FromSeconds(${Math.floor(timeout / 1000)}));`
1054
- }, {
1055
- level: 1,
1056
- statement: `wait.Until(driver => driver.FindElement(${await _location.default.emit(locator)}).Displayed);`
1057
- }, {
1058
- level: 0,
1059
- statement: '}'
1060
- }];
1061
- return Promise.resolve({
1062
- commands
1063
- });
1064
- }
1065
-
1066
- async function emitWaitForElementNotEditable(locator, timeout) {
1067
- const commands = [{
1068
- level: 0,
1069
- statement: '{'
1070
- }, {
1071
- level: 1,
1072
- statement: `WebDriverWait wait = new WebDriverWait(driver, System.TimeSpan.FromSeconds(${Math.floor(timeout / 1000)}));`
1073
- }, {
1074
- level: 1,
1075
- statement: `wait.Until(driver => !driver.FindElement(${await _location.default.emit(locator)}).Enabled);`
1076
- }, {
1077
- level: 0,
1078
- statement: '}'
1079
- }];
1080
- return Promise.resolve({
1081
- commands
1082
- });
1083
- }
1084
-
1085
- async function emitWaitForElementNotPresent(locator, timeout) {
1086
- const commands = [{
1087
- level: 0,
1088
- statement: '{'
1089
- }, {
1090
- level: 1,
1091
- statement: `WebDriverWait wait = new WebDriverWait(driver, System.TimeSpan.FromSeconds(${Math.floor(timeout / 1000)}));`
1092
- }, {
1093
- level: 1,
1094
- statement: `wait.Until(driver => driver.FindElements(${await _location.default.emit(locator)}).Count == 0);`
1095
- }, {
1096
- level: 0,
1097
- statement: '}'
1098
- }];
1099
- return Promise.resolve({
1100
- commands
1101
- });
1102
- }
1103
-
1104
- async function emitWaitForElementNotVisible(locator, timeout) {
1105
- const commands = [{
1106
- level: 0,
1107
- statement: '{'
1108
- }, {
1109
- level: 1,
1110
- statement: `WebDriverWait wait = new WebDriverWait(driver, System.TimeSpan.FromSeconds(${Math.floor(timeout / 1000)}));`
1111
- }, {
1112
- level: 1,
1113
- statement: `wait.Until(driver => !driver.FindElement(${await _location.default.emit(locator)}).Displayed);`
1114
- }, {
1115
- level: 0,
1116
- statement: '}'
1117
- }];
1118
- return Promise.resolve({
1119
- commands
1120
- });
1121
- }
1122
-
1123
- var _default = {
1124
- emitters,
1125
- variableLookup,
1126
- variableSetter,
1127
- canEmit,
1128
- emit,
1129
- register,
1130
- extras: {
1131
- emitWaitForWindow,
1132
- emitNewWindowHandling
1133
- }
1134
- };
1135
- exports.default = _default;