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