@seleniumhq/code-export-python-pytest 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/LICENSE +202 -0
- package/__test__/src/command.spec.js +1 -1
- package/__test__/src/index.spec.js +2 -2
- package/package.json +4 -3
- package/src/command.js +1 -1
- package/src/hook.js +1 -1
- package/src/index.js +1 -1
- package/src/location.js +1 -1
- package/src/selection.js +1 -1
- package/dist/command.js +0 -914
- package/dist/hook.js +0 -179
- package/dist/index.js +0 -138
- package/dist/location.js +0 -68
- package/dist/selection.js +0 -61
package/dist/command.js
DELETED
|
@@ -1,914 +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 `self.vars["${varName}"]`;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
function variableSetter(varName, value) {
|
|
160
|
-
return varName ? `self.vars["${varName}"] = ${value}` : '';
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
function emitWaitForWindow() {
|
|
164
|
-
const generateMethodDeclaration = name => {
|
|
165
|
-
return `def ${name}(self, timeout = 2):`;
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
const commands = [{
|
|
169
|
-
level: 0,
|
|
170
|
-
statement: 'time.sleep(round(timeout / 1000))'
|
|
171
|
-
}, {
|
|
172
|
-
level: 0,
|
|
173
|
-
statement: 'wh_now = self.driver.window_handles'
|
|
174
|
-
}, {
|
|
175
|
-
level: 0,
|
|
176
|
-
statement: 'wh_then = self.vars["window_handles"]'
|
|
177
|
-
}, {
|
|
178
|
-
level: 0,
|
|
179
|
-
statement: 'if len(wh_now) > len(wh_then):'
|
|
180
|
-
}, {
|
|
181
|
-
level: 1,
|
|
182
|
-
statement: 'return set(wh_now).difference(set(wh_then)).pop()'
|
|
183
|
-
}];
|
|
184
|
-
return Promise.resolve({
|
|
185
|
-
name: 'wait_for_window',
|
|
186
|
-
commands,
|
|
187
|
-
generateMethodDeclaration
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
async function emitNewWindowHandling(command, emittedCommand) {
|
|
192
|
-
return Promise.resolve(`self.vars["window_handles"] = self.driver.window_handles\n${await emittedCommand}\nself.vars["${command.windowHandleName}"] = self.wait_for_window(${command.windowTimeout})`);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
function emitAssert(varName, value) {
|
|
196
|
-
let _value;
|
|
197
|
-
|
|
198
|
-
if (value === 'true' || value === 'false') {
|
|
199
|
-
_value = _sideUtils.codeExport.parsers.capitalize(value);
|
|
200
|
-
} else if (value === '0' || !!Number(value)) {
|
|
201
|
-
_value = value;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
const result = _value ? `assert(self.vars["${varName}"] == ${_value})` : `assert(self.vars["${varName}"] == "${value}")`;
|
|
205
|
-
return Promise.resolve(result);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
function emitAssertAlert(alertText) {
|
|
209
|
-
return Promise.resolve(`assert self.driver.switch_to.alert.text == "${alertText}"`);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
function emitAnswerOnNextPrompt(textToSend) {
|
|
213
|
-
const commands = [{
|
|
214
|
-
level: 0,
|
|
215
|
-
statement: 'alert = self.driver.switch_to.alert'
|
|
216
|
-
}, {
|
|
217
|
-
level: 0,
|
|
218
|
-
statement: `alert.send_keys("${textToSend}")`
|
|
219
|
-
}, {
|
|
220
|
-
level: 0,
|
|
221
|
-
statement: 'alert.accept()'
|
|
222
|
-
}];
|
|
223
|
-
return Promise.resolve({
|
|
224
|
-
commands
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
async function emitCheck(locator) {
|
|
229
|
-
const commands = [{
|
|
230
|
-
level: 0,
|
|
231
|
-
statement: `element = self.driver.find_element(${await _location.default.emit(locator)})`
|
|
232
|
-
}, {
|
|
233
|
-
level: 0,
|
|
234
|
-
statement: 'if element.is_selected() != True: element.click()'
|
|
235
|
-
}];
|
|
236
|
-
return Promise.resolve({
|
|
237
|
-
commands
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
function emitChooseCancelOnNextConfirmation() {
|
|
242
|
-
return Promise.resolve(`self.driver.switch_to.alert.dismiss()`);
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
function emitChooseOkOnNextConfirmation() {
|
|
246
|
-
return Promise.resolve(`self.driver.switch_to.alert.accept()`);
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
async function emitClick(target) {
|
|
250
|
-
return Promise.resolve(`self.driver.find_element(${await _location.default.emit(target)}).click()`);
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
async function emitClose() {
|
|
254
|
-
return Promise.resolve(`self.driver.close()`);
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
function generateExpressionScript(script) {
|
|
258
|
-
return `self.driver.execute_script("return (${script.script})"${generateScriptArguments(script)})`;
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
function generateScriptArguments(script) {
|
|
262
|
-
return `${script.argv.length ? ', ' : ''}${script.argv.map(varName => `self.vars["${varName}"]`).join(',')}`;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
function emitControlFlowDo() {
|
|
266
|
-
return Promise.resolve({
|
|
267
|
-
commands: [{
|
|
268
|
-
level: 0,
|
|
269
|
-
statement: 'condition = True'
|
|
270
|
-
}, {
|
|
271
|
-
level: 0,
|
|
272
|
-
statement: 'while condition:'
|
|
273
|
-
}],
|
|
274
|
-
endingLevelAdjustment: 1
|
|
275
|
-
});
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
function emitControlFlowElse() {
|
|
279
|
-
return Promise.resolve({
|
|
280
|
-
commands: [{
|
|
281
|
-
level: 0,
|
|
282
|
-
statement: 'else:'
|
|
283
|
-
}],
|
|
284
|
-
startingLevelAdjustment: -1,
|
|
285
|
-
endingLevelAdjustment: +1
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
function emitControlFlowElseIf(script) {
|
|
290
|
-
return Promise.resolve({
|
|
291
|
-
commands: [{
|
|
292
|
-
level: 0,
|
|
293
|
-
statement: `elif ${generateExpressionScript(script)}:`
|
|
294
|
-
}],
|
|
295
|
-
startingLevelAdjustment: -1,
|
|
296
|
-
endingLevelAdjustment: +1
|
|
297
|
-
});
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
function emitControlFlowEnd() {
|
|
301
|
-
return Promise.resolve({
|
|
302
|
-
commands: [{
|
|
303
|
-
level: 0,
|
|
304
|
-
statement: ``
|
|
305
|
-
}],
|
|
306
|
-
startingLevelAdjustment: -1,
|
|
307
|
-
skipEmitting: true
|
|
308
|
-
});
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
function emitControlFlowIf(script) {
|
|
312
|
-
return Promise.resolve({
|
|
313
|
-
commands: [{
|
|
314
|
-
level: 0,
|
|
315
|
-
statement: `if ${generateExpressionScript(script)}:`
|
|
316
|
-
}],
|
|
317
|
-
endingLevelAdjustment: 1
|
|
318
|
-
});
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
function emitControlFlowForEach(collectionVarName, iteratorVarName) {
|
|
322
|
-
return Promise.resolve({
|
|
323
|
-
commands: [{
|
|
324
|
-
level: 0,
|
|
325
|
-
statement: `collection = self.vars["${collectionVarName}"]`
|
|
326
|
-
}, {
|
|
327
|
-
level: 0,
|
|
328
|
-
statement: `for entry in collection:`
|
|
329
|
-
}, {
|
|
330
|
-
level: 1,
|
|
331
|
-
statement: `self.vars["${iteratorVarName}"] = entry`
|
|
332
|
-
}]
|
|
333
|
-
});
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
function emitControlFlowRepeatIf(script) {
|
|
337
|
-
return Promise.resolve({
|
|
338
|
-
commands: [{
|
|
339
|
-
level: 0,
|
|
340
|
-
statement: `condition = ${generateExpressionScript(script)}`
|
|
341
|
-
}],
|
|
342
|
-
endingLevelAdjustment: -1
|
|
343
|
-
});
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
function emitControlFlowTimes(target) {
|
|
347
|
-
const commands = [{
|
|
348
|
-
level: 0,
|
|
349
|
-
statement: `for i in range(0, ${target}):`
|
|
350
|
-
}];
|
|
351
|
-
return Promise.resolve({
|
|
352
|
-
commands,
|
|
353
|
-
endingLevelAdjustment: 1
|
|
354
|
-
});
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
function emitControlFlowWhile(script) {
|
|
358
|
-
return Promise.resolve({
|
|
359
|
-
commands: [{
|
|
360
|
-
level: 0,
|
|
361
|
-
statement: `while ${generateExpressionScript(script)}:`
|
|
362
|
-
}],
|
|
363
|
-
endingLevelAdjustment: 1
|
|
364
|
-
});
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
async function emitDoubleClick(target) {
|
|
368
|
-
const commands = [{
|
|
369
|
-
level: 0,
|
|
370
|
-
statement: `element = self.driver.find_element(${await _location.default.emit(target)})`
|
|
371
|
-
}, {
|
|
372
|
-
level: 0,
|
|
373
|
-
statement: 'actions = ActionChains(self.driver)'
|
|
374
|
-
}, {
|
|
375
|
-
level: 0,
|
|
376
|
-
statement: 'actions.double_click(element).perform()'
|
|
377
|
-
}];
|
|
378
|
-
return Promise.resolve({
|
|
379
|
-
commands
|
|
380
|
-
});
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
async function emitDragAndDrop(dragged, dropped) {
|
|
384
|
-
const commands = [{
|
|
385
|
-
level: 0,
|
|
386
|
-
statement: `dragged = self.driver.find_element(${await _location.default.emit(dragged)})`
|
|
387
|
-
}, {
|
|
388
|
-
level: 0,
|
|
389
|
-
statement: `dropped = self.driver.find_element(${await _location.default.emit(dropped)})`
|
|
390
|
-
}, {
|
|
391
|
-
level: 0,
|
|
392
|
-
statement: 'actions = ActionChains(self.driver)'
|
|
393
|
-
}, {
|
|
394
|
-
level: 0,
|
|
395
|
-
statement: 'actions.drag_and_drop(dragged, dropped).perform()'
|
|
396
|
-
}];
|
|
397
|
-
return Promise.resolve({
|
|
398
|
-
commands
|
|
399
|
-
});
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
function translateToPythonString(str) {
|
|
403
|
-
const regExp = /self.vars\["\w+"]/;
|
|
404
|
-
const vars = str.match(regExp);
|
|
405
|
-
|
|
406
|
-
if (vars && vars.length > 0) {
|
|
407
|
-
const fmtStr = str.replace(regExp, '{}');
|
|
408
|
-
return `"${fmtStr}".format(${vars.join(', ')})`;
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
return `"${str}"`;
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
async function emitEcho(message) {
|
|
415
|
-
const _message = translateToPythonString(message);
|
|
416
|
-
|
|
417
|
-
return Promise.resolve(`print(${_message})`);
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
async function emitEditContent(locator, content) {
|
|
421
|
-
const commands = [{
|
|
422
|
-
level: 0,
|
|
423
|
-
statement: `element = self.driver.find_element(${await _location.default.emit(locator)})`
|
|
424
|
-
}, {
|
|
425
|
-
level: 0,
|
|
426
|
-
statement: `self.driver.execute_script("if(arguments[0].contentEditable === 'true') {arguments[0].innerText = '${content}'}", element)`
|
|
427
|
-
}];
|
|
428
|
-
return Promise.resolve({
|
|
429
|
-
commands
|
|
430
|
-
});
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
async function emitExecuteScript(script, varName) {
|
|
434
|
-
const scriptString = script.script.replace(/"/g, "'");
|
|
435
|
-
const result = `self.driver.execute_script("${scriptString}"${generateScriptArguments(script)})`;
|
|
436
|
-
return Promise.resolve(variableSetter(varName, result));
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
async function emitExecuteAsyncScript(script, varName) {
|
|
440
|
-
const result = `self.driver.execute_async_script("var callback = arguments[arguments.length - 1];${script.script}.then(callback).catch(callback);${generateScriptArguments(script)}")`;
|
|
441
|
-
return Promise.resolve(variableSetter(varName, result));
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
async function emitMouseDown(locator) {
|
|
445
|
-
const commands = [{
|
|
446
|
-
level: 0,
|
|
447
|
-
statement: `element = self.driver.find_element(${await _location.default.emit(locator)})`
|
|
448
|
-
}, {
|
|
449
|
-
level: 0,
|
|
450
|
-
statement: 'actions = ActionChains(self.driver)'
|
|
451
|
-
}, {
|
|
452
|
-
level: 0,
|
|
453
|
-
statement: 'actions.move_to_element(element).click_and_hold().perform()'
|
|
454
|
-
}];
|
|
455
|
-
return Promise.resolve({
|
|
456
|
-
commands
|
|
457
|
-
});
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
async function emitMouseMove(locator) {
|
|
461
|
-
const commands = [{
|
|
462
|
-
level: 0,
|
|
463
|
-
statement: `element = self.driver.find_element(${await _location.default.emit(locator)})`
|
|
464
|
-
}, {
|
|
465
|
-
level: 0,
|
|
466
|
-
statement: 'actions = ActionChains(self.driver)'
|
|
467
|
-
}, {
|
|
468
|
-
level: 0,
|
|
469
|
-
statement: 'actions.move_to_element(element).perform()'
|
|
470
|
-
}];
|
|
471
|
-
return Promise.resolve({
|
|
472
|
-
commands
|
|
473
|
-
});
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
async function emitMouseOut() {
|
|
477
|
-
const commands = [{
|
|
478
|
-
level: 0,
|
|
479
|
-
statement: `element = self.driver.find_element(By.CSS_SELECTOR, "body")`
|
|
480
|
-
}, {
|
|
481
|
-
level: 0,
|
|
482
|
-
statement: 'actions = ActionChains(self.driver)'
|
|
483
|
-
}, {
|
|
484
|
-
level: 0,
|
|
485
|
-
statement: 'actions.move_to_element(element, 0, 0).perform()'
|
|
486
|
-
}];
|
|
487
|
-
return Promise.resolve({
|
|
488
|
-
commands
|
|
489
|
-
});
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
async function emitMouseUp(locator) {
|
|
493
|
-
const commands = [{
|
|
494
|
-
level: 0,
|
|
495
|
-
statement: `element = self.driver.find_element(${await _location.default.emit(locator)})`
|
|
496
|
-
}, {
|
|
497
|
-
level: 0,
|
|
498
|
-
statement: 'actions = ActionChains(self.driver)'
|
|
499
|
-
}, {
|
|
500
|
-
level: 0,
|
|
501
|
-
statement: 'actions.move_to_element(element).release().perform()'
|
|
502
|
-
}];
|
|
503
|
-
return Promise.resolve({
|
|
504
|
-
commands
|
|
505
|
-
});
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
function emitOpen(target) {
|
|
509
|
-
const url = /^(file|http|https):\/\//.test(target) ? `"${target}"` : `"${global.baseUrl}${target}"`;
|
|
510
|
-
return Promise.resolve(`self.driver.get(${url})`);
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
async function emitPause(time) {
|
|
514
|
-
const sec = time / 1000;
|
|
515
|
-
const commands = [{
|
|
516
|
-
level: 0,
|
|
517
|
-
statement: `time.sleep(${sec})`
|
|
518
|
-
}];
|
|
519
|
-
return Promise.resolve({
|
|
520
|
-
commands
|
|
521
|
-
});
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
async function emitRun(testName) {
|
|
525
|
-
return Promise.resolve(`self.${_sideUtils.codeExport.parsers.sanitizeName(testName)}()`);
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
async function emitRunScript(script) {
|
|
529
|
-
return Promise.resolve(`self.driver.execute_script("${script.script}${generateScriptArguments(script)}")`);
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
async function emitSetWindowSize(size) {
|
|
533
|
-
const [width, height] = size.split('x');
|
|
534
|
-
return Promise.resolve(`self.driver.set_window_size(${width}, ${height})`);
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
async function emitSelect(selectElement, option) {
|
|
538
|
-
const commands = [{
|
|
539
|
-
level: 0,
|
|
540
|
-
statement: `dropdown = self.driver.find_element(${await _location.default.emit(selectElement)})`
|
|
541
|
-
}, {
|
|
542
|
-
level: 0,
|
|
543
|
-
statement: `dropdown.find_element(${await _selection.default.emit(option)}).click()`
|
|
544
|
-
}];
|
|
545
|
-
return Promise.resolve({
|
|
546
|
-
commands
|
|
547
|
-
});
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
async function emitSelectFrame(frameLocation) {
|
|
551
|
-
if (frameLocation === 'relative=top' || frameLocation === 'relative=parent') {
|
|
552
|
-
return Promise.resolve('self.driver.switch_to.default_content()');
|
|
553
|
-
} else if (/^index=/.test(frameLocation)) {
|
|
554
|
-
return Promise.resolve(`self.driver.switch_to.frame(${Math.floor(frameLocation.split('index=')[1])})`);
|
|
555
|
-
} else {
|
|
556
|
-
return Promise.resolve({
|
|
557
|
-
commands: [{
|
|
558
|
-
level: 0,
|
|
559
|
-
statement: `element = self.driver.find_element(${await _location.default.emit(frameLocation)})`
|
|
560
|
-
}, {
|
|
561
|
-
level: 0,
|
|
562
|
-
statement: 'self.driver.switch_to.frame(element)'
|
|
563
|
-
}]
|
|
564
|
-
});
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
async function emitSelectWindow(windowLocation) {
|
|
569
|
-
if (/^handle=/.test(windowLocation)) {
|
|
570
|
-
return Promise.resolve(`self.driver.switch_to.window(${windowLocation.split('handle=')[1]})`);
|
|
571
|
-
} else if (/^name=/.test(windowLocation)) {
|
|
572
|
-
return Promise.resolve(`self.driver.switch_to.window("${windowLocation.split('name=')[1]}")`);
|
|
573
|
-
} else if (/^win_ser_/.test(windowLocation)) {
|
|
574
|
-
if (windowLocation === 'win_ser_local') {
|
|
575
|
-
return Promise.resolve({
|
|
576
|
-
commands: [{
|
|
577
|
-
level: 0,
|
|
578
|
-
statement: 'self.driver.switch_to.window(self.driver.window_handles[0])'
|
|
579
|
-
}]
|
|
580
|
-
});
|
|
581
|
-
} else {
|
|
582
|
-
const index = parseInt(windowLocation.substr('win_ser_'.length));
|
|
583
|
-
return Promise.resolve({
|
|
584
|
-
commands: [{
|
|
585
|
-
level: 0,
|
|
586
|
-
statement: `self.driver.switch_to.window(self.driver.window_handles[${index}])`
|
|
587
|
-
}]
|
|
588
|
-
});
|
|
589
|
-
}
|
|
590
|
-
} else {
|
|
591
|
-
return Promise.reject(new Error('Can only emit `select window` using handles'));
|
|
592
|
-
}
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
function generateSendKeysInput(value) {
|
|
596
|
-
if (typeof value === 'object') {
|
|
597
|
-
return value.map(s => {
|
|
598
|
-
if (s.startsWith('self.vars[')) {
|
|
599
|
-
return s;
|
|
600
|
-
} else if (s.startsWith('Key[')) {
|
|
601
|
-
const key = s.match(/\['(.*)'\]/)[1];
|
|
602
|
-
return `Keys.${key}`;
|
|
603
|
-
} else {
|
|
604
|
-
return `"${s}"`;
|
|
605
|
-
}
|
|
606
|
-
}).join(', ');
|
|
607
|
-
} else {
|
|
608
|
-
if (value.startsWith('self.vars[')) {
|
|
609
|
-
return value;
|
|
610
|
-
} else {
|
|
611
|
-
return `"${value}"`;
|
|
612
|
-
}
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
async function emitSendKeys(target, value) {
|
|
617
|
-
return Promise.resolve(`self.driver.find_element(${await _location.default.emit(target)}).send_keys(${generateSendKeysInput(value)})`);
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
function emitSetSpeed() {
|
|
621
|
-
return Promise.resolve('print("`set speed` is a no-op in code export, use `pause` instead")');
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
async function emitStore(value, varName) {
|
|
625
|
-
return Promise.resolve(variableSetter(varName, `"${value}"`));
|
|
626
|
-
}
|
|
627
|
-
|
|
628
|
-
async function emitStoreAttribute(locator, varName) {
|
|
629
|
-
const attributePos = locator.lastIndexOf('@');
|
|
630
|
-
const elementLocator = locator.slice(0, attributePos);
|
|
631
|
-
const attributeName = locator.slice(attributePos + 1);
|
|
632
|
-
const commands = [{
|
|
633
|
-
level: 0,
|
|
634
|
-
statement: `attribute = self.driver.find_element(${await _location.default.emit(elementLocator)}).get_attribute("${attributeName}")`
|
|
635
|
-
}, {
|
|
636
|
-
level: 0,
|
|
637
|
-
statement: `${variableSetter(varName, 'attribute')}`
|
|
638
|
-
}];
|
|
639
|
-
return Promise.resolve({
|
|
640
|
-
commands
|
|
641
|
-
});
|
|
642
|
-
}
|
|
643
|
-
|
|
644
|
-
async function emitStoreJson(json, varName) {
|
|
645
|
-
return Promise.resolve(variableSetter(varName, `json.loads('${json}')`));
|
|
646
|
-
}
|
|
647
|
-
|
|
648
|
-
async function emitStoreText(locator, varName) {
|
|
649
|
-
const result = `self.driver.find_element(${await _location.default.emit(locator)}).text`;
|
|
650
|
-
return Promise.resolve(variableSetter(varName, result));
|
|
651
|
-
}
|
|
652
|
-
|
|
653
|
-
async function emitStoreTitle(_, varName) {
|
|
654
|
-
return Promise.resolve(variableSetter(varName, 'self.driver.title'));
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
async function emitStoreValue(locator, varName) {
|
|
658
|
-
const result = `self.driver.find_element(${await _location.default.emit(locator)}).get_attribute("value")`;
|
|
659
|
-
return Promise.resolve(variableSetter(varName, result));
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
async function emitStoreWindowHandle(varName) {
|
|
663
|
-
return Promise.resolve(variableSetter(varName, 'self.driver.current_window_handle'));
|
|
664
|
-
}
|
|
665
|
-
|
|
666
|
-
async function emitStoreXpathCount(locator, varName) {
|
|
667
|
-
const result = `len(self.driver.find_elements(${await _location.default.emit(locator)}))`;
|
|
668
|
-
return Promise.resolve(variableSetter(varName, result));
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
async function emitSubmit(_locator) {
|
|
672
|
-
return Promise.resolve(`raise Exception("'submit' is not a supported command in Selenium WebDriver. Please re-record the step in the IDE.")`);
|
|
673
|
-
}
|
|
674
|
-
|
|
675
|
-
async function emitType(target, value) {
|
|
676
|
-
return Promise.resolve(`self.driver.find_element(${await _location.default.emit(target)}).send_keys(${generateSendKeysInput(value)})`);
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
async function emitUncheck(locator) {
|
|
680
|
-
const commands = [{
|
|
681
|
-
level: 0,
|
|
682
|
-
statement: `element = self.driver.find_element(${await _location.default.emit(locator)})`
|
|
683
|
-
}, {
|
|
684
|
-
level: 0,
|
|
685
|
-
statement: 'if element.is_selected: element.click()'
|
|
686
|
-
}];
|
|
687
|
-
return Promise.resolve({
|
|
688
|
-
commands
|
|
689
|
-
});
|
|
690
|
-
}
|
|
691
|
-
|
|
692
|
-
async function emitVerifyChecked(locator) {
|
|
693
|
-
return Promise.resolve(`assert self.driver.find_element(${await _location.default.emit(locator)}).is_selected() is True`);
|
|
694
|
-
}
|
|
695
|
-
|
|
696
|
-
async function emitVerifyEditable(locator) {
|
|
697
|
-
const commands = [{
|
|
698
|
-
level: 0,
|
|
699
|
-
statement: `element = self.driver.find_element(${await _location.default.emit(locator)})`
|
|
700
|
-
}, {
|
|
701
|
-
level: 0,
|
|
702
|
-
statement: 'assert element.is_enabled() is True'
|
|
703
|
-
}];
|
|
704
|
-
return Promise.resolve({
|
|
705
|
-
commands
|
|
706
|
-
});
|
|
707
|
-
}
|
|
708
|
-
|
|
709
|
-
async function emitVerifyElementPresent(locator) {
|
|
710
|
-
const commands = [{
|
|
711
|
-
level: 0,
|
|
712
|
-
statement: `elements = self.driver.find_elements(${await _location.default.emit(locator)})`
|
|
713
|
-
}, {
|
|
714
|
-
level: 0,
|
|
715
|
-
statement: 'assert len(elements) > 0'
|
|
716
|
-
}];
|
|
717
|
-
return Promise.resolve({
|
|
718
|
-
commands
|
|
719
|
-
});
|
|
720
|
-
}
|
|
721
|
-
|
|
722
|
-
async function emitVerifyElementNotPresent(locator) {
|
|
723
|
-
const commands = [{
|
|
724
|
-
level: 0,
|
|
725
|
-
statement: `elements = self.driver.find_elements(${await _location.default.emit(locator)})`
|
|
726
|
-
}, {
|
|
727
|
-
level: 0,
|
|
728
|
-
statement: 'assert len(elements) == 0'
|
|
729
|
-
}];
|
|
730
|
-
return Promise.resolve({
|
|
731
|
-
commands
|
|
732
|
-
});
|
|
733
|
-
}
|
|
734
|
-
|
|
735
|
-
async function emitVerifyNotChecked(locator) {
|
|
736
|
-
return Promise.resolve(`assert self.driver.find_element(${await _location.default.emit(locator)}).is_selected() is False`);
|
|
737
|
-
}
|
|
738
|
-
|
|
739
|
-
async function emitVerifyNotEditable(locator) {
|
|
740
|
-
const commands = [{
|
|
741
|
-
level: 0,
|
|
742
|
-
statement: `element = self.driver.find_element(${await _location.default.emit(locator)})`
|
|
743
|
-
}, {
|
|
744
|
-
level: 0,
|
|
745
|
-
statement: 'assert element.is_enabled() is False'
|
|
746
|
-
}];
|
|
747
|
-
return Promise.resolve({
|
|
748
|
-
commands
|
|
749
|
-
});
|
|
750
|
-
}
|
|
751
|
-
|
|
752
|
-
async function emitVerifyNotSelectedValue(locator, expectedValue) {
|
|
753
|
-
const commands = [{
|
|
754
|
-
level: 0,
|
|
755
|
-
statement: `value = self.driver.find_element(${await _location.default.emit(locator)}).get_attribute("value")`
|
|
756
|
-
}, {
|
|
757
|
-
level: 0,
|
|
758
|
-
statement: `assert value != "${_sideUtils.codeExport.emit.text(expectedValue)}"`
|
|
759
|
-
}];
|
|
760
|
-
return Promise.resolve({
|
|
761
|
-
commands
|
|
762
|
-
});
|
|
763
|
-
}
|
|
764
|
-
|
|
765
|
-
async function emitVerifyNotText(locator, text) {
|
|
766
|
-
const commands = [{
|
|
767
|
-
level: 0,
|
|
768
|
-
statement: `text = self.driver.find_element(${await _location.default.emit(locator)}).text`
|
|
769
|
-
}, {
|
|
770
|
-
level: 0,
|
|
771
|
-
statement: `assert text != "${_sideUtils.codeExport.emit.text(text)}"`
|
|
772
|
-
}];
|
|
773
|
-
return Promise.resolve({
|
|
774
|
-
commands
|
|
775
|
-
});
|
|
776
|
-
}
|
|
777
|
-
|
|
778
|
-
async function emitVerifySelectedLabel(locator, labelValue) {
|
|
779
|
-
const commands = [{
|
|
780
|
-
level: 0,
|
|
781
|
-
statement: `element = self.driver.find_element(${await _location.default.emit(locator)})`
|
|
782
|
-
}, {
|
|
783
|
-
level: 0,
|
|
784
|
-
statement: `locator = "option[@value='{}']".format(element.get_attribute("value"))`
|
|
785
|
-
}, {
|
|
786
|
-
level: 0,
|
|
787
|
-
statement: 'selected_text = element.find_element(By.XPATH, locator).text'
|
|
788
|
-
}, {
|
|
789
|
-
level: 0,
|
|
790
|
-
statement: `assert selected_text == "${labelValue}"`
|
|
791
|
-
}];
|
|
792
|
-
return Promise.resolve({
|
|
793
|
-
commands
|
|
794
|
-
});
|
|
795
|
-
}
|
|
796
|
-
|
|
797
|
-
async function emitVerifyText(locator, text) {
|
|
798
|
-
const commands = [{
|
|
799
|
-
level: 0,
|
|
800
|
-
statement: `assert self.driver.find_element(${await _location.default.emit(locator)}).text == "${_sideUtils.codeExport.emit.text(text)}"`
|
|
801
|
-
}];
|
|
802
|
-
return Promise.resolve({
|
|
803
|
-
commands
|
|
804
|
-
});
|
|
805
|
-
}
|
|
806
|
-
|
|
807
|
-
async function emitVerifyValue(locator, value) {
|
|
808
|
-
const commands = [{
|
|
809
|
-
level: 0,
|
|
810
|
-
statement: `value = self.driver.find_element(${await _location.default.emit(locator)}).get_attribute("value")`
|
|
811
|
-
}, {
|
|
812
|
-
level: 0,
|
|
813
|
-
statement: `assert value == "${value}"`
|
|
814
|
-
}];
|
|
815
|
-
return Promise.resolve({
|
|
816
|
-
commands
|
|
817
|
-
});
|
|
818
|
-
}
|
|
819
|
-
|
|
820
|
-
async function emitVerifyTitle(title) {
|
|
821
|
-
return Promise.resolve(`assert self.driver.title == "${title}"`);
|
|
822
|
-
}
|
|
823
|
-
|
|
824
|
-
async function emitWaitForElementEditable(locator, timeout) {
|
|
825
|
-
const sec = timeout / 1000;
|
|
826
|
-
const commands = [{
|
|
827
|
-
level: 0,
|
|
828
|
-
statement: `WebDriverWait(self.driver, ${sec}).until(expected_conditions.element_to_be_clickable((${await _location.default.emit(locator)})))`
|
|
829
|
-
}];
|
|
830
|
-
return Promise.resolve({
|
|
831
|
-
commands
|
|
832
|
-
});
|
|
833
|
-
}
|
|
834
|
-
|
|
835
|
-
async function emitWaitForText(locator, text) {
|
|
836
|
-
const timeout = 30000;
|
|
837
|
-
const sec = timeout / 1000;
|
|
838
|
-
const commands = [{
|
|
839
|
-
level: 0,
|
|
840
|
-
statement: `WebDriverWait(self.driver, ${sec}).until(expected_conditions.text_to_be_present_in_element((${await _location.default.emit(locator)}), "${text}"))`
|
|
841
|
-
}];
|
|
842
|
-
return Promise.resolve({
|
|
843
|
-
commands
|
|
844
|
-
});
|
|
845
|
-
}
|
|
846
|
-
|
|
847
|
-
function skip() {
|
|
848
|
-
return Promise.resolve(undefined);
|
|
849
|
-
}
|
|
850
|
-
|
|
851
|
-
async function emitWaitForElementPresent(locator, timeout) {
|
|
852
|
-
const sec = timeout / 1000;
|
|
853
|
-
const commands = [{
|
|
854
|
-
level: 0,
|
|
855
|
-
statement: `WebDriverWait(self.driver, ${sec}).until(expected_conditions.presence_of_element_located((${await _location.default.emit(locator)})))`
|
|
856
|
-
}];
|
|
857
|
-
return Promise.resolve({
|
|
858
|
-
commands
|
|
859
|
-
});
|
|
860
|
-
}
|
|
861
|
-
|
|
862
|
-
async function emitWaitForElementVisible(locator, timeout) {
|
|
863
|
-
const sec = timeout / 1000;
|
|
864
|
-
const commands = [{
|
|
865
|
-
level: 0,
|
|
866
|
-
statement: `WebDriverWait(self.driver, ${sec}).until(expected_conditions.visibility_of_element_located((${await _location.default.emit(locator)})))`
|
|
867
|
-
}];
|
|
868
|
-
return Promise.resolve({
|
|
869
|
-
commands
|
|
870
|
-
});
|
|
871
|
-
}
|
|
872
|
-
|
|
873
|
-
async function emitWaitForElementNotEditable(locator, timeout) {
|
|
874
|
-
const sec = timeout / 1000;
|
|
875
|
-
const commands = [{
|
|
876
|
-
level: 0,
|
|
877
|
-
statement: `WebDriverWait(self.driver, ${sec}).until_not(expected_conditions.element_to_be_clickable((${await _location.default.emit(locator)})))`
|
|
878
|
-
}];
|
|
879
|
-
return Promise.resolve({
|
|
880
|
-
commands
|
|
881
|
-
});
|
|
882
|
-
}
|
|
883
|
-
|
|
884
|
-
async function emitWaitForElementNotPresent(locator, timeout) {
|
|
885
|
-
const sec = timeout / 1000;
|
|
886
|
-
const commands = [{
|
|
887
|
-
level: 0,
|
|
888
|
-
statement: `WebDriverWait(self.driver, ${sec}).until(expected_conditions.invisibility_of_element_located((${await _location.default.emit(locator)})))`
|
|
889
|
-
}];
|
|
890
|
-
return Promise.resolve({
|
|
891
|
-
commands
|
|
892
|
-
});
|
|
893
|
-
}
|
|
894
|
-
|
|
895
|
-
async function emitWaitForElementNotVisible(locator, timeout) {
|
|
896
|
-
const sec = timeout / 1000;
|
|
897
|
-
const commands = [{
|
|
898
|
-
level: 0,
|
|
899
|
-
statement: `WebDriverWait(self.driver, ${sec}).until(expected_conditions.invisibility_of_element_located((${await _location.default.emit(locator)})))`
|
|
900
|
-
}];
|
|
901
|
-
return Promise.resolve({
|
|
902
|
-
commands
|
|
903
|
-
});
|
|
904
|
-
}
|
|
905
|
-
|
|
906
|
-
var _default = {
|
|
907
|
-
canEmit,
|
|
908
|
-
emit,
|
|
909
|
-
register,
|
|
910
|
-
extras: {
|
|
911
|
-
emitWaitForWindow
|
|
912
|
-
}
|
|
913
|
-
};
|
|
914
|
-
exports.default = _default;
|