@seleniumhq/code-export-python-pytest 3.17.4 → 4.0.0-alpha.2
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.d.ts +25 -0
- package/dist/command.d.ts.map +1 -0
- package/dist/command.js +795 -0
- package/dist/command.js.map +1 -0
- package/dist/hook.d.ts +68 -0
- package/dist/hook.d.ts.map +1 -0
- package/dist/hook.js +132 -0
- package/dist/hook.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +53 -0
- package/dist/index.js.map +1 -0
- package/dist/location.d.ts +6 -0
- package/dist/location.d.ts.map +1 -0
- package/dist/location.js +55 -0
- package/dist/location.js.map +1 -0
- package/dist/selection.d.ts +6 -0
- package/dist/selection.d.ts.map +1 -0
- package/dist/selection.js +49 -0
- package/dist/selection.js.map +1 -0
- package/package.json +13 -14
- package/src/{command.js → command.ts} +99 -85
- package/src/{hook.js → hook.ts} +3 -13
- package/src/index.ts +63 -0
- package/src/{location.js → location.ts} +8 -8
- package/src/{selection.js → selection.ts} +6 -6
- package/tsconfig.json +18 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/.babelrc +0 -13
- package/src/index.js +0 -140
package/dist/command.js
ADDED
|
@@ -0,0 +1,795 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Licensed to the Software Freedom Conservancy (SFC) under one
|
|
3
|
+
// or more contributor license agreements. See the NOTICE file
|
|
4
|
+
// distributed with this work for additional information
|
|
5
|
+
// regarding copyright ownership. The SFC licenses this file
|
|
6
|
+
// to you under the Apache License, Version 2.0 (the
|
|
7
|
+
// "License"); you may not use this file except in compliance
|
|
8
|
+
// with the License. You may obtain a copy of the License at
|
|
9
|
+
//
|
|
10
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
//
|
|
12
|
+
// Unless required by applicable law or agreed to in writing,
|
|
13
|
+
// software distributed under the License is distributed on an
|
|
14
|
+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
+
// KIND, either express or implied. See the License for the
|
|
16
|
+
// specific language governing permissions and limitations
|
|
17
|
+
// under the License.
|
|
18
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
19
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.emitters = void 0;
|
|
23
|
+
const side_code_export_1 = require("side-code-export");
|
|
24
|
+
const location_1 = __importDefault(require("./location"));
|
|
25
|
+
const selection_1 = __importDefault(require("./selection"));
|
|
26
|
+
exports.emitters = {
|
|
27
|
+
addSelection: emitSelect,
|
|
28
|
+
answerOnNextPrompt: skip,
|
|
29
|
+
assert: emitAssert,
|
|
30
|
+
assertAlert: emitAssertAlert,
|
|
31
|
+
assertChecked: emitVerifyChecked,
|
|
32
|
+
assertConfirmation: emitAssertAlert,
|
|
33
|
+
assertEditable: emitVerifyEditable,
|
|
34
|
+
assertElementPresent: emitVerifyElementPresent,
|
|
35
|
+
assertElementNotPresent: emitVerifyElementNotPresent,
|
|
36
|
+
assertNotChecked: emitVerifyNotChecked,
|
|
37
|
+
assertNotEditable: emitVerifyNotEditable,
|
|
38
|
+
assertNotSelectedValue: emitVerifyNotSelectedValue,
|
|
39
|
+
assertNotText: emitVerifyNotText,
|
|
40
|
+
assertPrompt: emitAssertAlert,
|
|
41
|
+
assertSelectedLabel: emitVerifySelectedLabel,
|
|
42
|
+
assertSelectedValue: emitVerifyValue,
|
|
43
|
+
assertValue: emitVerifyValue,
|
|
44
|
+
assertText: emitVerifyText,
|
|
45
|
+
assertTitle: emitVerifyTitle,
|
|
46
|
+
check: emitCheck,
|
|
47
|
+
chooseCancelOnNextConfirmation: skip,
|
|
48
|
+
chooseCancelOnNextPrompt: skip,
|
|
49
|
+
chooseOkOnNextConfirmation: skip,
|
|
50
|
+
click: emitClick,
|
|
51
|
+
clickAt: emitClick,
|
|
52
|
+
close: emitClose,
|
|
53
|
+
debugger: skip,
|
|
54
|
+
do: emitControlFlowDo,
|
|
55
|
+
doubleClick: emitDoubleClick,
|
|
56
|
+
doubleClickAt: emitDoubleClick,
|
|
57
|
+
dragAndDropToObject: emitDragAndDrop,
|
|
58
|
+
echo: emitEcho,
|
|
59
|
+
editContent: emitEditContent,
|
|
60
|
+
else: emitControlFlowElse,
|
|
61
|
+
elseIf: emitControlFlowElseIf,
|
|
62
|
+
end: emitControlFlowEnd,
|
|
63
|
+
executeScript: emitExecuteScript,
|
|
64
|
+
executeAsyncScript: emitExecuteAsyncScript,
|
|
65
|
+
forEach: emitControlFlowForEach,
|
|
66
|
+
if: emitControlFlowIf,
|
|
67
|
+
mouseDown: emitMouseDown,
|
|
68
|
+
mouseDownAt: emitMouseDown,
|
|
69
|
+
mouseMove: emitMouseMove,
|
|
70
|
+
mouseMoveAt: emitMouseMove,
|
|
71
|
+
mouseOver: emitMouseMove,
|
|
72
|
+
mouseOut: emitMouseOut,
|
|
73
|
+
mouseUp: emitMouseUp,
|
|
74
|
+
mouseUpAt: emitMouseUp,
|
|
75
|
+
open: emitOpen,
|
|
76
|
+
pause: emitPause,
|
|
77
|
+
removeSelection: emitSelect,
|
|
78
|
+
repeatIf: emitControlFlowRepeatIf,
|
|
79
|
+
run: emitRun,
|
|
80
|
+
runScript: emitRunScript,
|
|
81
|
+
select: emitSelect,
|
|
82
|
+
selectFrame: emitSelectFrame,
|
|
83
|
+
selectWindow: emitSelectWindow,
|
|
84
|
+
sendKeys: emitSendKeys,
|
|
85
|
+
setSpeed: emitSetSpeed,
|
|
86
|
+
setWindowSize: emitSetWindowSize,
|
|
87
|
+
store: emitStore,
|
|
88
|
+
storeAttribute: emitStoreAttribute,
|
|
89
|
+
storeJson: emitStoreJson,
|
|
90
|
+
storeText: emitStoreText,
|
|
91
|
+
storeTitle: emitStoreTitle,
|
|
92
|
+
storeValue: emitStoreValue,
|
|
93
|
+
storeWindowHandle: emitStoreWindowHandle,
|
|
94
|
+
storeXpathCount: emitStoreXpathCount,
|
|
95
|
+
submit: emitSubmit,
|
|
96
|
+
times: emitControlFlowTimes,
|
|
97
|
+
type: emitType,
|
|
98
|
+
uncheck: emitUncheck,
|
|
99
|
+
verify: emitAssert,
|
|
100
|
+
verifyChecked: emitVerifyChecked,
|
|
101
|
+
verifyEditable: emitVerifyEditable,
|
|
102
|
+
verifyElementPresent: emitVerifyElementPresent,
|
|
103
|
+
verifyElementNotPresent: emitVerifyElementNotPresent,
|
|
104
|
+
verifyNotChecked: emitVerifyNotChecked,
|
|
105
|
+
verifyNotEditable: emitVerifyNotEditable,
|
|
106
|
+
verifyNotSelectedValue: emitVerifyNotSelectedValue,
|
|
107
|
+
verifyNotText: emitVerifyNotText,
|
|
108
|
+
verifySelectedLabel: emitVerifySelectedLabel,
|
|
109
|
+
verifySelectedValue: emitVerifyValue,
|
|
110
|
+
verifyText: emitVerifyText,
|
|
111
|
+
verifyTitle: emitVerifyTitle,
|
|
112
|
+
verifyValue: emitVerifyValue,
|
|
113
|
+
waitForElementEditable: emitWaitForElementEditable,
|
|
114
|
+
waitForElementPresent: emitWaitForElementPresent,
|
|
115
|
+
waitForElementVisible: emitWaitForElementVisible,
|
|
116
|
+
waitForElementNotEditable: emitWaitForElementNotEditable,
|
|
117
|
+
waitForElementNotPresent: emitWaitForElementNotPresent,
|
|
118
|
+
waitForElementNotVisible: emitWaitForElementNotVisible,
|
|
119
|
+
webdriverAnswerOnVisiblePrompt: emitAnswerOnNextPrompt,
|
|
120
|
+
waitForText: emitWaitForText,
|
|
121
|
+
webdriverChooseCancelOnVisibleConfirmation: emitChooseCancelOnNextConfirmation,
|
|
122
|
+
webdriverChooseCancelOnVisiblePrompt: emitChooseCancelOnNextConfirmation,
|
|
123
|
+
webdriverChooseOkOnVisibleConfirmation: emitChooseOkOnNextConfirmation,
|
|
124
|
+
while: emitControlFlowWhile,
|
|
125
|
+
};
|
|
126
|
+
side_code_export_1.codeExport.register.preprocessors(exports.emitters);
|
|
127
|
+
function register(command, emitter) {
|
|
128
|
+
side_code_export_1.codeExport.register.emitter({ command, emitter, emitters: exports.emitters });
|
|
129
|
+
}
|
|
130
|
+
function emit(command) {
|
|
131
|
+
return side_code_export_1.codeExport.emit.command(command, exports.emitters[command.command], {
|
|
132
|
+
variableLookup,
|
|
133
|
+
emitNewWindowHandling,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
function variableLookup(varName) {
|
|
137
|
+
return `self.vars["${varName}"]`;
|
|
138
|
+
}
|
|
139
|
+
function variableSetter(varName, value) {
|
|
140
|
+
return varName ? `self.vars["${varName}"] = ${value}` : '';
|
|
141
|
+
}
|
|
142
|
+
function emitWaitForWindow() {
|
|
143
|
+
const generateMethodDeclaration = (name) => {
|
|
144
|
+
return `def ${name}(self, timeout = 2):`;
|
|
145
|
+
};
|
|
146
|
+
const commands = [
|
|
147
|
+
{ level: 0, statement: 'time.sleep(round(timeout / 1000))' },
|
|
148
|
+
{ level: 0, statement: 'wh_now = self.driver.window_handles' },
|
|
149
|
+
{
|
|
150
|
+
level: 0,
|
|
151
|
+
statement: 'wh_then = self.vars["window_handles"]',
|
|
152
|
+
},
|
|
153
|
+
{ level: 0, statement: 'if len(wh_now) > len(wh_then):' },
|
|
154
|
+
{
|
|
155
|
+
level: 1,
|
|
156
|
+
statement: 'return set(wh_now).difference(set(wh_then)).pop()',
|
|
157
|
+
},
|
|
158
|
+
];
|
|
159
|
+
return Promise.resolve({
|
|
160
|
+
name: 'wait_for_window',
|
|
161
|
+
commands,
|
|
162
|
+
generateMethodDeclaration,
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
async function emitNewWindowHandling(command, emittedCommand) {
|
|
166
|
+
return Promise.resolve(`self.vars["window_handles"] = self.driver.window_handles\n${await emittedCommand}\nself.vars["${command.windowHandleName}"] = self.wait_for_window(${command.windowTimeout})`);
|
|
167
|
+
}
|
|
168
|
+
function emitAssert(varName, value) {
|
|
169
|
+
let _value;
|
|
170
|
+
if (value === 'true' || value === 'false') {
|
|
171
|
+
_value = side_code_export_1.codeExport.parsers.capitalize(value);
|
|
172
|
+
}
|
|
173
|
+
else if (value === '0' || !!Number(value)) {
|
|
174
|
+
_value = value;
|
|
175
|
+
}
|
|
176
|
+
const result = _value
|
|
177
|
+
? `assert(self.vars["${varName}"] == ${_value})`
|
|
178
|
+
: `assert(self.vars["${varName}"] == "${value}")`;
|
|
179
|
+
return Promise.resolve(result);
|
|
180
|
+
}
|
|
181
|
+
function emitAssertAlert(alertText) {
|
|
182
|
+
return Promise.resolve(`assert self.driver.switch_to.alert.text == "${alertText}"`);
|
|
183
|
+
}
|
|
184
|
+
function emitAnswerOnNextPrompt(textToSend) {
|
|
185
|
+
const commands = [
|
|
186
|
+
{ level: 0, statement: 'alert = self.driver.switch_to.alert' },
|
|
187
|
+
{ level: 0, statement: `alert.send_keys("${textToSend}")` },
|
|
188
|
+
{ level: 0, statement: 'alert.accept()' },
|
|
189
|
+
];
|
|
190
|
+
return Promise.resolve({ commands });
|
|
191
|
+
}
|
|
192
|
+
async function emitCheck(locator) {
|
|
193
|
+
const commands = [
|
|
194
|
+
{
|
|
195
|
+
level: 0,
|
|
196
|
+
statement: `element = self.driver.find_element(${await location_1.default.emit(locator)})`,
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
level: 0,
|
|
200
|
+
statement: 'if element.is_selected() != True: element.click()',
|
|
201
|
+
},
|
|
202
|
+
];
|
|
203
|
+
return Promise.resolve({ commands });
|
|
204
|
+
}
|
|
205
|
+
function emitChooseCancelOnNextConfirmation() {
|
|
206
|
+
return Promise.resolve(`self.driver.switch_to.alert.dismiss()`);
|
|
207
|
+
}
|
|
208
|
+
function emitChooseOkOnNextConfirmation() {
|
|
209
|
+
return Promise.resolve(`self.driver.switch_to.alert.accept()`);
|
|
210
|
+
}
|
|
211
|
+
async function emitClick(target) {
|
|
212
|
+
return Promise.resolve(`self.driver.find_element(${await location_1.default.emit(target)}).click()`);
|
|
213
|
+
}
|
|
214
|
+
async function emitClose() {
|
|
215
|
+
return Promise.resolve(`self.driver.close()`);
|
|
216
|
+
}
|
|
217
|
+
function generateExpressionScript(script) {
|
|
218
|
+
return `self.driver.execute_script("return (${script.script})"${generateScriptArguments(script)})`;
|
|
219
|
+
}
|
|
220
|
+
function generateScriptArguments(script) {
|
|
221
|
+
return `${script.argv.length ? ', ' : ''}${script.argv
|
|
222
|
+
.map((varName) => `self.vars["${varName}"]`)
|
|
223
|
+
.join(',')}`;
|
|
224
|
+
}
|
|
225
|
+
function emitControlFlowDo() {
|
|
226
|
+
return Promise.resolve({
|
|
227
|
+
commands: [
|
|
228
|
+
{ level: 0, statement: 'condition = True' },
|
|
229
|
+
{ level: 0, statement: 'while condition:' },
|
|
230
|
+
],
|
|
231
|
+
endingLevelAdjustment: 1,
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
function emitControlFlowElse() {
|
|
235
|
+
return Promise.resolve({
|
|
236
|
+
commands: [{ level: 0, statement: 'else:' }],
|
|
237
|
+
startingLevelAdjustment: -1,
|
|
238
|
+
endingLevelAdjustment: +1,
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
function emitControlFlowElseIf(script) {
|
|
242
|
+
return Promise.resolve({
|
|
243
|
+
commands: [
|
|
244
|
+
{
|
|
245
|
+
level: 0,
|
|
246
|
+
statement: `elif ${generateExpressionScript(script)}:`,
|
|
247
|
+
},
|
|
248
|
+
],
|
|
249
|
+
startingLevelAdjustment: -1,
|
|
250
|
+
endingLevelAdjustment: +1,
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
function emitControlFlowEnd() {
|
|
254
|
+
return Promise.resolve({
|
|
255
|
+
commands: [{ level: 0, statement: `` }],
|
|
256
|
+
startingLevelAdjustment: -1,
|
|
257
|
+
skipEmitting: true,
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
function emitControlFlowIf(script) {
|
|
261
|
+
return Promise.resolve({
|
|
262
|
+
commands: [
|
|
263
|
+
{ level: 0, statement: `if ${generateExpressionScript(script)}:` },
|
|
264
|
+
],
|
|
265
|
+
endingLevelAdjustment: 1,
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
function emitControlFlowForEach(collectionVarName, iteratorVarName) {
|
|
269
|
+
return Promise.resolve({
|
|
270
|
+
commands: [
|
|
271
|
+
{
|
|
272
|
+
level: 0,
|
|
273
|
+
statement: `collection = self.vars["${collectionVarName}"]`,
|
|
274
|
+
},
|
|
275
|
+
{
|
|
276
|
+
level: 0,
|
|
277
|
+
statement: `for entry in collection:`,
|
|
278
|
+
},
|
|
279
|
+
{
|
|
280
|
+
level: 1,
|
|
281
|
+
statement: `self.vars["${iteratorVarName}"] = entry`,
|
|
282
|
+
},
|
|
283
|
+
],
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
function emitControlFlowRepeatIf(script) {
|
|
287
|
+
return Promise.resolve({
|
|
288
|
+
commands: [
|
|
289
|
+
{
|
|
290
|
+
level: 0,
|
|
291
|
+
statement: `condition = ${generateExpressionScript(script)}`,
|
|
292
|
+
},
|
|
293
|
+
],
|
|
294
|
+
endingLevelAdjustment: -1,
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
function emitControlFlowTimes(target) {
|
|
298
|
+
const commands = [{ level: 0, statement: `for i in range(0, ${target}):` }];
|
|
299
|
+
return Promise.resolve({ commands, endingLevelAdjustment: 1 });
|
|
300
|
+
}
|
|
301
|
+
function emitControlFlowWhile(script) {
|
|
302
|
+
return Promise.resolve({
|
|
303
|
+
commands: [
|
|
304
|
+
{ level: 0, statement: `while ${generateExpressionScript(script)}:` },
|
|
305
|
+
],
|
|
306
|
+
endingLevelAdjustment: 1,
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
async function emitDoubleClick(target) {
|
|
310
|
+
const commands = [
|
|
311
|
+
{
|
|
312
|
+
level: 0,
|
|
313
|
+
statement: `element = self.driver.find_element(${await location_1.default.emit(target)})`,
|
|
314
|
+
},
|
|
315
|
+
{ level: 0, statement: 'actions = ActionChains(self.driver)' },
|
|
316
|
+
{ level: 0, statement: 'actions.double_click(element).perform()' },
|
|
317
|
+
];
|
|
318
|
+
return Promise.resolve({ commands });
|
|
319
|
+
}
|
|
320
|
+
async function emitDragAndDrop(dragged, dropped) {
|
|
321
|
+
const commands = [
|
|
322
|
+
{
|
|
323
|
+
level: 0,
|
|
324
|
+
statement: `dragged = self.driver.find_element(${await location_1.default.emit(dragged)})`,
|
|
325
|
+
},
|
|
326
|
+
{
|
|
327
|
+
level: 0,
|
|
328
|
+
statement: `dropped = self.driver.find_element(${await location_1.default.emit(dropped)})`,
|
|
329
|
+
},
|
|
330
|
+
{ level: 0, statement: 'actions = ActionChains(self.driver)' },
|
|
331
|
+
{
|
|
332
|
+
level: 0,
|
|
333
|
+
statement: 'actions.drag_and_drop(dragged, dropped).perform()',
|
|
334
|
+
},
|
|
335
|
+
];
|
|
336
|
+
return Promise.resolve({ commands });
|
|
337
|
+
}
|
|
338
|
+
function translateToPythonString(str) {
|
|
339
|
+
const regExp = /self.vars\["\w+"]/;
|
|
340
|
+
const vars = str.match(regExp);
|
|
341
|
+
if (vars && vars.length > 0) {
|
|
342
|
+
const fmtStr = str.replace(regExp, '{}');
|
|
343
|
+
return `"${fmtStr}".format(${vars.join(', ')})`;
|
|
344
|
+
}
|
|
345
|
+
return `"${str}"`;
|
|
346
|
+
}
|
|
347
|
+
async function emitEcho(message) {
|
|
348
|
+
const _message = translateToPythonString(message);
|
|
349
|
+
return Promise.resolve(`print(${_message})`);
|
|
350
|
+
}
|
|
351
|
+
async function emitEditContent(locator, content) {
|
|
352
|
+
const commands = [
|
|
353
|
+
{
|
|
354
|
+
level: 0,
|
|
355
|
+
statement: `element = self.driver.find_element(${await location_1.default.emit(locator)})`,
|
|
356
|
+
},
|
|
357
|
+
{
|
|
358
|
+
level: 0,
|
|
359
|
+
statement: `self.driver.execute_script("if(arguments[0].contentEditable === 'true') {arguments[0].innerText = '${content}'}", element)`,
|
|
360
|
+
},
|
|
361
|
+
];
|
|
362
|
+
return Promise.resolve({ commands });
|
|
363
|
+
}
|
|
364
|
+
async function emitExecuteScript(script, varName) {
|
|
365
|
+
const scriptString = script.script.replace(/"/g, "'");
|
|
366
|
+
const result = `self.driver.execute_script("${scriptString}"${generateScriptArguments(script)})`;
|
|
367
|
+
return Promise.resolve(variableSetter(varName, result));
|
|
368
|
+
}
|
|
369
|
+
async function emitExecuteAsyncScript(script, varName) {
|
|
370
|
+
const result = `self.driver.execute_async_script("var callback = arguments[arguments.length - 1];${script.script}.then(callback).catch(callback);${generateScriptArguments(script)}")`;
|
|
371
|
+
return Promise.resolve(variableSetter(varName, result));
|
|
372
|
+
}
|
|
373
|
+
async function emitMouseDown(locator) {
|
|
374
|
+
const commands = [
|
|
375
|
+
{
|
|
376
|
+
level: 0,
|
|
377
|
+
statement: `element = self.driver.find_element(${await location_1.default.emit(locator)})`,
|
|
378
|
+
},
|
|
379
|
+
{ level: 0, statement: 'actions = ActionChains(self.driver)' },
|
|
380
|
+
{
|
|
381
|
+
level: 0,
|
|
382
|
+
statement: 'actions.move_to_element(element).click_and_hold().perform()',
|
|
383
|
+
},
|
|
384
|
+
];
|
|
385
|
+
return Promise.resolve({ commands });
|
|
386
|
+
}
|
|
387
|
+
async function emitMouseMove(locator) {
|
|
388
|
+
const commands = [
|
|
389
|
+
{
|
|
390
|
+
level: 0,
|
|
391
|
+
statement: `element = self.driver.find_element(${await location_1.default.emit(locator)})`,
|
|
392
|
+
},
|
|
393
|
+
{ level: 0, statement: 'actions = ActionChains(self.driver)' },
|
|
394
|
+
{ level: 0, statement: 'actions.move_to_element(element).perform()' },
|
|
395
|
+
];
|
|
396
|
+
return Promise.resolve({ commands });
|
|
397
|
+
}
|
|
398
|
+
async function emitMouseOut() {
|
|
399
|
+
const commands = [
|
|
400
|
+
{
|
|
401
|
+
level: 0,
|
|
402
|
+
statement: `element = self.driver.find_element(By.CSS_SELECTOR, "body")`,
|
|
403
|
+
},
|
|
404
|
+
{ level: 0, statement: 'actions = ActionChains(self.driver)' },
|
|
405
|
+
{ level: 0, statement: 'actions.move_to_element(element).perform()' },
|
|
406
|
+
];
|
|
407
|
+
return Promise.resolve({ commands });
|
|
408
|
+
}
|
|
409
|
+
async function emitMouseUp(locator) {
|
|
410
|
+
const commands = [
|
|
411
|
+
{
|
|
412
|
+
level: 0,
|
|
413
|
+
statement: `element = self.driver.find_element(${await location_1.default.emit(locator)})`,
|
|
414
|
+
},
|
|
415
|
+
{ level: 0, statement: 'actions = ActionChains(self.driver)' },
|
|
416
|
+
{
|
|
417
|
+
level: 0,
|
|
418
|
+
statement: 'actions.move_to_element(element).release().perform()',
|
|
419
|
+
},
|
|
420
|
+
];
|
|
421
|
+
return Promise.resolve({ commands });
|
|
422
|
+
}
|
|
423
|
+
function emitOpen(target) {
|
|
424
|
+
const url = /^(file|http|https):\/\//.test(target)
|
|
425
|
+
? `"${target}"`
|
|
426
|
+
: // @ts-expect-error globals yuck
|
|
427
|
+
`"${global.baseUrl}${target}"`;
|
|
428
|
+
return Promise.resolve(`self.driver.get(${url})`);
|
|
429
|
+
}
|
|
430
|
+
async function emitPause(time) {
|
|
431
|
+
const sec = time / 1000;
|
|
432
|
+
const commands = [{ level: 0, statement: `time.sleep(${sec})` }];
|
|
433
|
+
return Promise.resolve({ commands });
|
|
434
|
+
}
|
|
435
|
+
async function emitRun(testName) {
|
|
436
|
+
return Promise.resolve(`self.${side_code_export_1.codeExport.parsers.sanitizeName(testName)}()`);
|
|
437
|
+
}
|
|
438
|
+
async function emitRunScript(script) {
|
|
439
|
+
return Promise.resolve(`self.driver.execute_script("${script.script}${generateScriptArguments(script)}")`);
|
|
440
|
+
}
|
|
441
|
+
async function emitSetWindowSize(size) {
|
|
442
|
+
const [width, height] = size.split('x');
|
|
443
|
+
return Promise.resolve(`self.driver.set_window_size(${width}, ${height})`);
|
|
444
|
+
}
|
|
445
|
+
async function emitSelect(selectElement, option) {
|
|
446
|
+
const commands = [
|
|
447
|
+
{
|
|
448
|
+
level: 0,
|
|
449
|
+
statement: `dropdown = self.driver.find_element(${await location_1.default.emit(selectElement)})`,
|
|
450
|
+
},
|
|
451
|
+
{
|
|
452
|
+
level: 0,
|
|
453
|
+
statement: `dropdown.find_element(${await selection_1.default.emit(option)}).click()`,
|
|
454
|
+
},
|
|
455
|
+
];
|
|
456
|
+
return Promise.resolve({ commands });
|
|
457
|
+
}
|
|
458
|
+
async function emitSelectFrame(frameLocation) {
|
|
459
|
+
if (frameLocation === 'relative=top' || frameLocation === 'relative=parent') {
|
|
460
|
+
return Promise.resolve('self.driver.switch_to.default_content()');
|
|
461
|
+
}
|
|
462
|
+
else if (/^index=/.test(frameLocation)) {
|
|
463
|
+
return Promise.resolve(`self.driver.switch_to.frame(${Math.floor(Number(frameLocation.split('index=')?.[1]))})`);
|
|
464
|
+
}
|
|
465
|
+
else {
|
|
466
|
+
return Promise.resolve({
|
|
467
|
+
commands: [
|
|
468
|
+
{
|
|
469
|
+
level: 0,
|
|
470
|
+
statement: `element = self.driver.find_element(${await location_1.default.emit(frameLocation)})`,
|
|
471
|
+
},
|
|
472
|
+
{ level: 0, statement: 'self.driver.switch_to.frame(element)' },
|
|
473
|
+
],
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
async function emitSelectWindow(windowLocation) {
|
|
478
|
+
if (/^handle=/.test(windowLocation)) {
|
|
479
|
+
return Promise.resolve(`self.driver.switch_to.window(${windowLocation.split('handle=')[1]})`);
|
|
480
|
+
}
|
|
481
|
+
else if (/^name=/.test(windowLocation)) {
|
|
482
|
+
return Promise.resolve(`self.driver.switch_to.window("${windowLocation.split('name=')[1]}")`);
|
|
483
|
+
}
|
|
484
|
+
else if (/^win_ser_/.test(windowLocation)) {
|
|
485
|
+
if (windowLocation === 'win_ser_local') {
|
|
486
|
+
return Promise.resolve({
|
|
487
|
+
commands: [
|
|
488
|
+
{
|
|
489
|
+
level: 0,
|
|
490
|
+
statement: 'self.driver.switch_to.window(self.driver.window_handles[0])',
|
|
491
|
+
},
|
|
492
|
+
],
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
else {
|
|
496
|
+
const index = parseInt(windowLocation.substr('win_ser_'.length));
|
|
497
|
+
return Promise.resolve({
|
|
498
|
+
commands: [
|
|
499
|
+
{
|
|
500
|
+
level: 0,
|
|
501
|
+
statement: `self.driver.switch_to.window(self.driver.window_handles[${index}])`,
|
|
502
|
+
},
|
|
503
|
+
],
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
else {
|
|
508
|
+
return Promise.reject(new Error('Can only emit `select window` using handles'));
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
function generateSendKeysInput(value) {
|
|
512
|
+
if (typeof value === 'object') {
|
|
513
|
+
return value
|
|
514
|
+
.map((s) => {
|
|
515
|
+
if (s.startsWith('self.vars[')) {
|
|
516
|
+
return s;
|
|
517
|
+
}
|
|
518
|
+
else if (s.startsWith('Key[')) {
|
|
519
|
+
const key = s.match(/\['(.*)'\]/)?.[1];
|
|
520
|
+
return `Keys.${key}`;
|
|
521
|
+
}
|
|
522
|
+
else {
|
|
523
|
+
return `"${s}"`;
|
|
524
|
+
}
|
|
525
|
+
})
|
|
526
|
+
.join(', ');
|
|
527
|
+
}
|
|
528
|
+
else {
|
|
529
|
+
if (value.startsWith('self.vars[')) {
|
|
530
|
+
return value;
|
|
531
|
+
}
|
|
532
|
+
else {
|
|
533
|
+
return `"${value}"`;
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
async function emitSendKeys(target, value) {
|
|
538
|
+
return Promise.resolve(`self.driver.find_element(${await location_1.default.emit(target)}).send_keys(${generateSendKeysInput(value)})`);
|
|
539
|
+
}
|
|
540
|
+
function emitSetSpeed() {
|
|
541
|
+
return Promise.resolve('print("`set speed` is a no-op in code export, use `pause` instead")');
|
|
542
|
+
}
|
|
543
|
+
async function emitStore(value, varName) {
|
|
544
|
+
return Promise.resolve(variableSetter(varName, `"${value}"`));
|
|
545
|
+
}
|
|
546
|
+
async function emitStoreAttribute(locator, varName) {
|
|
547
|
+
const attributePos = locator.lastIndexOf('@');
|
|
548
|
+
const elementLocator = locator.slice(0, attributePos);
|
|
549
|
+
const attributeName = locator.slice(attributePos + 1);
|
|
550
|
+
const commands = [
|
|
551
|
+
{
|
|
552
|
+
level: 0,
|
|
553
|
+
statement: `attribute = self.driver.find_element(${await location_1.default.emit(elementLocator)}).get_attribute("${attributeName}")`,
|
|
554
|
+
},
|
|
555
|
+
{ level: 0, statement: `${variableSetter(varName, 'attribute')}` },
|
|
556
|
+
];
|
|
557
|
+
return Promise.resolve({ commands });
|
|
558
|
+
}
|
|
559
|
+
async function emitStoreJson(json, varName) {
|
|
560
|
+
return Promise.resolve(variableSetter(varName, `json.loads('${json}')`));
|
|
561
|
+
}
|
|
562
|
+
async function emitStoreText(locator, varName) {
|
|
563
|
+
const result = `self.driver.find_element(${await location_1.default.emit(locator)}).text`;
|
|
564
|
+
return Promise.resolve(variableSetter(varName, result));
|
|
565
|
+
}
|
|
566
|
+
async function emitStoreTitle(_, varName) {
|
|
567
|
+
return Promise.resolve(variableSetter(varName, 'self.driver.title'));
|
|
568
|
+
}
|
|
569
|
+
async function emitStoreValue(locator, varName) {
|
|
570
|
+
const result = `self.driver.find_element(${await location_1.default.emit(locator)}).get_attribute("value")`;
|
|
571
|
+
return Promise.resolve(variableSetter(varName, result));
|
|
572
|
+
}
|
|
573
|
+
async function emitStoreWindowHandle(varName) {
|
|
574
|
+
return Promise.resolve(variableSetter(varName, 'self.driver.current_window_handle'));
|
|
575
|
+
}
|
|
576
|
+
async function emitStoreXpathCount(locator, varName) {
|
|
577
|
+
const result = `len(self.driver.find_elements(${await location_1.default.emit(locator)}))`;
|
|
578
|
+
return Promise.resolve(variableSetter(varName, result));
|
|
579
|
+
}
|
|
580
|
+
async function emitSubmit(_locator) {
|
|
581
|
+
return Promise.resolve(`raise Exception("'submit' is not a supported command in Selenium WebDriver. Please re-record the step in the IDE.")`);
|
|
582
|
+
}
|
|
583
|
+
async function emitType(target, value) {
|
|
584
|
+
return Promise.resolve(`self.driver.find_element(${await location_1.default.emit(target)}).send_keys(${generateSendKeysInput(value)})`);
|
|
585
|
+
}
|
|
586
|
+
async function emitUncheck(locator) {
|
|
587
|
+
const commands = [
|
|
588
|
+
{
|
|
589
|
+
level: 0,
|
|
590
|
+
statement: `element = self.driver.find_element(${await location_1.default.emit(locator)})`,
|
|
591
|
+
},
|
|
592
|
+
{ level: 0, statement: 'if element.is_selected: element.click()' },
|
|
593
|
+
];
|
|
594
|
+
return Promise.resolve({ commands });
|
|
595
|
+
}
|
|
596
|
+
async function emitVerifyChecked(locator) {
|
|
597
|
+
return Promise.resolve(`assert self.driver.find_element(${await location_1.default.emit(locator)}).is_selected() is True`);
|
|
598
|
+
}
|
|
599
|
+
async function emitVerifyEditable(locator) {
|
|
600
|
+
const commands = [
|
|
601
|
+
{
|
|
602
|
+
level: 0,
|
|
603
|
+
statement: `element = self.driver.find_element(${await location_1.default.emit(locator)})`,
|
|
604
|
+
},
|
|
605
|
+
{ level: 0, statement: 'assert element.is_enabled() is True' },
|
|
606
|
+
];
|
|
607
|
+
return Promise.resolve({ commands });
|
|
608
|
+
}
|
|
609
|
+
async function emitVerifyElementPresent(locator) {
|
|
610
|
+
const commands = [
|
|
611
|
+
{
|
|
612
|
+
level: 0,
|
|
613
|
+
statement: `elements = self.driver.find_elements(${await location_1.default.emit(locator)})`,
|
|
614
|
+
},
|
|
615
|
+
{ level: 0, statement: 'assert len(elements) > 0' },
|
|
616
|
+
];
|
|
617
|
+
return Promise.resolve({ commands });
|
|
618
|
+
}
|
|
619
|
+
async function emitVerifyElementNotPresent(locator) {
|
|
620
|
+
const commands = [
|
|
621
|
+
{
|
|
622
|
+
level: 0,
|
|
623
|
+
statement: `elements = self.driver.find_elements(${await location_1.default.emit(locator)})`,
|
|
624
|
+
},
|
|
625
|
+
{ level: 0, statement: 'assert len(elements) == 0' },
|
|
626
|
+
];
|
|
627
|
+
return Promise.resolve({ commands });
|
|
628
|
+
}
|
|
629
|
+
async function emitVerifyNotChecked(locator) {
|
|
630
|
+
return Promise.resolve(`assert self.driver.find_element(${await location_1.default.emit(locator)}).is_selected() is False`);
|
|
631
|
+
}
|
|
632
|
+
async function emitVerifyNotEditable(locator) {
|
|
633
|
+
const commands = [
|
|
634
|
+
{
|
|
635
|
+
level: 0,
|
|
636
|
+
statement: `element = self.driver.find_element(${await location_1.default.emit(locator)})`,
|
|
637
|
+
},
|
|
638
|
+
{ level: 0, statement: 'assert element.is_enabled() is False' },
|
|
639
|
+
];
|
|
640
|
+
return Promise.resolve({ commands });
|
|
641
|
+
}
|
|
642
|
+
async function emitVerifyNotSelectedValue(locator, expectedValue) {
|
|
643
|
+
const commands = [
|
|
644
|
+
{
|
|
645
|
+
level: 0,
|
|
646
|
+
statement: `value = self.driver.find_element(${await location_1.default.emit(locator)}).get_attribute("value")`,
|
|
647
|
+
},
|
|
648
|
+
{
|
|
649
|
+
level: 0,
|
|
650
|
+
statement: `assert value != "${side_code_export_1.codeExport.emit.text(expectedValue)}"`,
|
|
651
|
+
},
|
|
652
|
+
];
|
|
653
|
+
return Promise.resolve({ commands });
|
|
654
|
+
}
|
|
655
|
+
async function emitVerifyNotText(locator, text) {
|
|
656
|
+
const commands = [
|
|
657
|
+
{
|
|
658
|
+
level: 0,
|
|
659
|
+
statement: `text = self.driver.find_element(${await location_1.default.emit(locator)}).text`,
|
|
660
|
+
},
|
|
661
|
+
{ level: 0, statement: `assert text != "${side_code_export_1.codeExport.emit.text(text)}"` },
|
|
662
|
+
];
|
|
663
|
+
return Promise.resolve({ commands });
|
|
664
|
+
}
|
|
665
|
+
async function emitVerifySelectedLabel(locator, labelValue) {
|
|
666
|
+
const commands = [
|
|
667
|
+
{
|
|
668
|
+
level: 0,
|
|
669
|
+
statement: `element = self.driver.find_element(${await location_1.default.emit(locator)})`,
|
|
670
|
+
},
|
|
671
|
+
{
|
|
672
|
+
level: 0,
|
|
673
|
+
statement: `locator = "option[@value='{}']".format(element.get_attribute("value"))`,
|
|
674
|
+
},
|
|
675
|
+
{
|
|
676
|
+
level: 0,
|
|
677
|
+
statement: 'selected_text = element.find_element(By.XPATH, locator).text',
|
|
678
|
+
},
|
|
679
|
+
{ level: 0, statement: `assert selected_text == "${labelValue}"` },
|
|
680
|
+
];
|
|
681
|
+
return Promise.resolve({
|
|
682
|
+
commands,
|
|
683
|
+
});
|
|
684
|
+
}
|
|
685
|
+
async function emitVerifyText(locator, text) {
|
|
686
|
+
const commands = [
|
|
687
|
+
{
|
|
688
|
+
level: 0,
|
|
689
|
+
statement: `assert self.driver.find_element(${await location_1.default.emit(locator)}).text == "${side_code_export_1.codeExport.emit.text(text)}"`,
|
|
690
|
+
},
|
|
691
|
+
];
|
|
692
|
+
return Promise.resolve({ commands });
|
|
693
|
+
}
|
|
694
|
+
async function emitVerifyValue(locator, value) {
|
|
695
|
+
const commands = [
|
|
696
|
+
{
|
|
697
|
+
level: 0,
|
|
698
|
+
statement: `value = self.driver.find_element(${await location_1.default.emit(locator)}).get_attribute("value")`,
|
|
699
|
+
},
|
|
700
|
+
{ level: 0, statement: `assert value == "${value}"` },
|
|
701
|
+
];
|
|
702
|
+
return Promise.resolve({ commands });
|
|
703
|
+
}
|
|
704
|
+
async function emitVerifyTitle(title) {
|
|
705
|
+
return Promise.resolve(`assert self.driver.title == "${title}"`);
|
|
706
|
+
}
|
|
707
|
+
async function emitWaitForElementEditable(locator, timeout) {
|
|
708
|
+
const sec = timeout / 1000;
|
|
709
|
+
const commands = [
|
|
710
|
+
{
|
|
711
|
+
level: 0,
|
|
712
|
+
statement: `WebDriverWait(self.driver, ${sec}).until(expected_conditions.element_to_be_clickable((${await location_1.default.emit(locator)})))`,
|
|
713
|
+
},
|
|
714
|
+
];
|
|
715
|
+
return Promise.resolve({ commands });
|
|
716
|
+
}
|
|
717
|
+
async function emitWaitForText(locator, text) {
|
|
718
|
+
const timeout = 30000;
|
|
719
|
+
const sec = timeout / 1000;
|
|
720
|
+
const commands = [
|
|
721
|
+
{
|
|
722
|
+
level: 0,
|
|
723
|
+
statement: `WebDriverWait(self.driver, ${sec}).until(expected_conditions.text_to_be_present_in_element((${await location_1.default.emit(locator)}), "${text}"))`,
|
|
724
|
+
},
|
|
725
|
+
];
|
|
726
|
+
return Promise.resolve({ commands });
|
|
727
|
+
}
|
|
728
|
+
function skip() {
|
|
729
|
+
return Promise.resolve('');
|
|
730
|
+
}
|
|
731
|
+
async function emitWaitForElementPresent(locator, timeout) {
|
|
732
|
+
const sec = timeout / 1000;
|
|
733
|
+
const commands = [
|
|
734
|
+
{
|
|
735
|
+
level: 0,
|
|
736
|
+
statement: `WebDriverWait(self.driver, ${sec}).until(expected_conditions.presence_of_element_located((${await location_1.default.emit(locator)})))`,
|
|
737
|
+
},
|
|
738
|
+
];
|
|
739
|
+
return Promise.resolve({ commands });
|
|
740
|
+
}
|
|
741
|
+
async function emitWaitForElementVisible(locator, timeout) {
|
|
742
|
+
const sec = timeout / 1000;
|
|
743
|
+
const commands = [
|
|
744
|
+
{
|
|
745
|
+
level: 0,
|
|
746
|
+
statement: `WebDriverWait(self.driver, ${sec}).until(expected_conditions.visibility_of_element_located((${await location_1.default.emit(locator)})))`,
|
|
747
|
+
},
|
|
748
|
+
];
|
|
749
|
+
return Promise.resolve({
|
|
750
|
+
commands,
|
|
751
|
+
});
|
|
752
|
+
}
|
|
753
|
+
async function emitWaitForElementNotEditable(locator, timeout) {
|
|
754
|
+
const sec = timeout / 1000;
|
|
755
|
+
const commands = [
|
|
756
|
+
{
|
|
757
|
+
level: 0,
|
|
758
|
+
statement: `WebDriverWait(self.driver, ${sec}).until_not(expected_conditions.element_to_be_clickable((${await location_1.default.emit(locator)})))`,
|
|
759
|
+
},
|
|
760
|
+
];
|
|
761
|
+
return Promise.resolve({
|
|
762
|
+
commands,
|
|
763
|
+
});
|
|
764
|
+
}
|
|
765
|
+
async function emitWaitForElementNotPresent(locator, timeout) {
|
|
766
|
+
const sec = timeout / 1000;
|
|
767
|
+
const commands = [
|
|
768
|
+
{
|
|
769
|
+
level: 0,
|
|
770
|
+
statement: `WebDriverWait(self.driver, ${sec}).until(expected_conditions.invisibility_of_element_located((${await location_1.default.emit(locator)})))`,
|
|
771
|
+
},
|
|
772
|
+
];
|
|
773
|
+
return Promise.resolve({
|
|
774
|
+
commands,
|
|
775
|
+
});
|
|
776
|
+
}
|
|
777
|
+
async function emitWaitForElementNotVisible(locator, timeout) {
|
|
778
|
+
const sec = timeout / 1000;
|
|
779
|
+
const commands = [
|
|
780
|
+
{
|
|
781
|
+
level: 0,
|
|
782
|
+
statement: `WebDriverWait(self.driver, ${sec}).until(expected_conditions.invisibility_of_element_located((${await location_1.default.emit(locator)})))`,
|
|
783
|
+
},
|
|
784
|
+
];
|
|
785
|
+
return Promise.resolve({
|
|
786
|
+
commands,
|
|
787
|
+
});
|
|
788
|
+
}
|
|
789
|
+
exports.default = {
|
|
790
|
+
emit,
|
|
791
|
+
emitters: exports.emitters,
|
|
792
|
+
register,
|
|
793
|
+
extras: { emitNewWindowHandling, emitWaitForWindow },
|
|
794
|
+
};
|
|
795
|
+
//# sourceMappingURL=command.js.map
|