@testim/testim-cli 3.289.0 → 3.290.0-beta
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/cli.js +22390 -122
- package/cli.js.map +1 -0
- package/npm-shrinkwrap.json +8 -29129
- package/package.json +16 -10
- package/OverrideTestDataBuilder.js +0 -117
- package/agent/routers/cliJsCode/index.js +0 -13
- package/agent/routers/cliJsCode/router.js +0 -63
- package/agent/routers/cliJsCode/service.js +0 -705
- package/agent/routers/codim/router.js +0 -69
- package/agent/routers/codim/router.test.js +0 -60
- package/agent/routers/codim/service.js +0 -193
- package/agent/routers/general/index.js +0 -36
- package/agent/routers/hybrid/registerRoutes.js +0 -81
- package/agent/routers/index.js +0 -56
- package/agent/routers/playground/router.js +0 -77
- package/agent/routers/playground/service.js +0 -96
- package/agent/routers/standalone-browser/registerRoutes.js +0 -47
- package/agent/server.js +0 -150
- package/cdpTestRunner.js +0 -86
- package/chromiumInstaller.js +0 -91
- package/cli/isCiRun.js +0 -10
- package/cli/onExit.js +0 -65
- package/cli/writeStackTrace.js +0 -27
- package/cliAgentMode.js +0 -384
- package/codim/codim-cli.js +0 -91
- package/codim/codim-npm-package/index.ts +0 -427
- package/codim/codim-npm-package/package-lock.json +0 -14
- package/codim/codim-npm-package/package.json +0 -14
- package/codim/hybrid-utils.js +0 -28
- package/codim/measure-perf.js +0 -41
- package/codim/template.js/.idea/workspace.xml +0 -57
- package/codim/template.js/.vscode/launch.json +0 -53
- package/codim/template.ts/.idea/workspace.xml +0 -57
- package/codim/template.ts/.vscode/launch.json +0 -55
- package/commons/AbortError.js +0 -12
- package/commons/SeleniumPerfStats.js +0 -58
- package/commons/chrome-launcher.js +0 -15
- package/commons/chromedriverWrapper.js +0 -70
- package/commons/config.js +0 -39
- package/commons/constants.js +0 -67
- package/commons/detectDebugger.js +0 -19
- package/commons/featureAvailabilityService.js +0 -26
- package/commons/featureFlags.js +0 -132
- package/commons/getSessionPlayerRequire.js +0 -28
- package/commons/httpRequest.js +0 -261
- package/commons/httpRequestCounters.js +0 -98
- package/commons/httpRequestCounters.test.js +0 -38
- package/commons/initializeUserWithAuth.js +0 -55
- package/commons/lazyRequire.js +0 -105
- package/commons/logUtils.js +0 -15
- package/commons/logUtils.test.js +0 -21
- package/commons/logger.js +0 -178
- package/commons/mockNetworkRuleFileSchema.json +0 -140
- package/commons/npmWrapper.js +0 -174
- package/commons/npmWrapper.test.js +0 -374
- package/commons/performance-logger.js +0 -71
- package/commons/preloadTests.js +0 -29
- package/commons/prepareRunner.js +0 -85
- package/commons/prepareRunner.test.js +0 -144
- package/commons/prepareRunnerAndTestimStartUtils.js +0 -198
- package/commons/prepareRunnerAndTestimStartUtils.test.js +0 -73
- package/commons/requireWithFallback.js +0 -25
- package/commons/runnerFileCache.js +0 -204
- package/commons/socket/baseSocketServiceSocketIO.js +0 -197
- package/commons/socket/realDataService.js +0 -59
- package/commons/socket/realDataServiceSocketIO.js +0 -33
- package/commons/socket/remoteStepService.js +0 -55
- package/commons/socket/remoteStepServiceSocketIO.js +0 -61
- package/commons/socket/socketService.js +0 -175
- package/commons/socket/testResultService.js +0 -62
- package/commons/socket/testResultServiceSocketIO.js +0 -64
- package/commons/testimAnalytics.js +0 -40
- package/commons/testimCloudflare.js +0 -83
- package/commons/testimCloudflare.test.js +0 -185
- package/commons/testimCustomToken.js +0 -124
- package/commons/testimDesiredCapabilitiesBuilder.js +0 -647
- package/commons/testimNgrok.js +0 -90
- package/commons/testimNgrok.test.js +0 -140
- package/commons/testimServicesApi.js +0 -631
- package/commons/testimTunnel.js +0 -73
- package/commons/testimTunnel.test.js +0 -172
- package/commons/xhr2.js +0 -897
- package/coverage/SummaryToObjectReport.js +0 -19
- package/coverage/jsCoverage.js +0 -252
- package/credentialsManager.js +0 -142
- package/errors.js +0 -161
- package/executionQueue.js +0 -37
- package/fixLocalBuild.js +0 -24
- package/inputFileUtils.js +0 -103
- package/lib/coralogix-winston.transport.js +0 -99
- package/player/SeleniumProtocolError.js +0 -100
- package/player/WebDriverHttpRequest.js +0 -177
- package/player/WebdriverioWebDriverApi.js +0 -671
- package/player/appiumTestPlayer.js +0 -90
- package/player/chromeLauncherTestPlayer.js +0 -67
- package/player/constants.js +0 -332
- package/player/extensionTestPlayer.js +0 -32
- package/player/findElementStrategy.js +0 -154
- package/player/scripts/isElementDisplayed.js +0 -252
- package/player/seleniumTestPlayer.js +0 -140
- package/player/services/frameLocator.js +0 -170
- package/player/services/mobileFrameLocatorMock.js +0 -32
- package/player/services/playbackTimeoutCalculator.js +0 -175
- package/player/services/portSelector.js +0 -19
- package/player/services/tabService.js +0 -551
- package/player/services/tabServiceMock.js +0 -167
- package/player/services/windowCreationListener.js +0 -8
- package/player/stepActions/RefreshStepAction.js +0 -16
- package/player/stepActions/apiStepAction.js +0 -89
- package/player/stepActions/baseCliJsStepAction.js +0 -51
- package/player/stepActions/baseJsStepAction.js +0 -277
- package/player/stepActions/cliConditionStepAction.js +0 -11
- package/player/stepActions/cliJsStepAction.js +0 -11
- package/player/stepActions/dropFileStepAction.js +0 -34
- package/player/stepActions/evaluateExpressionStepAction.js +0 -52
- package/player/stepActions/extensionOnlyStepAction.js +0 -12
- package/player/stepActions/extractTextStepAction.js +0 -19
- package/player/stepActions/hoverStepAction.js +0 -55
- package/player/stepActions/inputFileStepAction.js +0 -199
- package/player/stepActions/jsCodeStepAction.js +0 -11
- package/player/stepActions/jsConditionStepAction.js +0 -11
- package/player/stepActions/locateStepAction.js +0 -159
- package/player/stepActions/mouseStepAction.js +0 -370
- package/player/stepActions/navigationStepAction.js +0 -29
- package/player/stepActions/nodePackageStepAction.js +0 -47
- package/player/stepActions/pixelValidationStepAction.js +0 -39
- package/player/stepActions/scripts/dispatchEvents.js +0 -282
- package/player/stepActions/scripts/doClick.js +0 -221
- package/player/stepActions/scripts/doDragPath.js +0 -225
- package/player/stepActions/scripts/doubleClick.js +0 -119
- package/player/stepActions/scripts/dropEvent.js +0 -63
- package/player/stepActions/scripts/focusElement.js +0 -46
- package/player/stepActions/scripts/html5dragAction.js +0 -56
- package/player/stepActions/scripts/html5dragActionV2.js +0 -312
- package/player/stepActions/scripts/runCode.js +0 -147
- package/player/stepActions/scripts/scroll.js +0 -90
- package/player/stepActions/scripts/selectOption.js +0 -51
- package/player/stepActions/scripts/setText.js +0 -415
- package/player/stepActions/scripts/wheel.js +0 -61
- package/player/stepActions/scrollStepAction.js +0 -96
- package/player/stepActions/selectOptionStepAction.js +0 -49
- package/player/stepActions/sfdcRecordedStepAction.js +0 -24
- package/player/stepActions/sfdcStepAction.js +0 -28
- package/player/stepActions/sleepStepAction.js +0 -12
- package/player/stepActions/specialKeyStepAction.js +0 -52
- package/player/stepActions/stepAction.js +0 -73
- package/player/stepActions/stepActionRegistrar.js +0 -111
- package/player/stepActions/submitStepAction.js +0 -12
- package/player/stepActions/tdkHybridStepAction.js +0 -18
- package/player/stepActions/textStepAction.js +0 -110
- package/player/stepActions/textValidationStepAction.js +0 -64
- package/player/stepActions/wheelStepAction.js +0 -41
- package/player/utils/cookieUtils.js +0 -39
- package/player/utils/eyeSdkService.js +0 -250
- package/player/utils/imageCaptureUtils.js +0 -267
- package/player/utils/screenshotUtils.js +0 -68
- package/player/utils/stepActionUtils.js +0 -90
- package/player/utils/windowUtils.js +0 -195
- package/player/webDriverUtils.js +0 -40
- package/player/webDriverUtils.test.js +0 -116
- package/player/webdriver.js +0 -976
- package/polyfills/Array.prototype.at.js +0 -13
- package/polyfills/index.js +0 -13
- package/processHandler.js +0 -79
- package/processHandler.test.js +0 -55
- package/reports/chromeReporter.js +0 -17
- package/reports/consoleReporter.js +0 -190
- package/reports/debugReporter.js +0 -82
- package/reports/jsonReporter.js +0 -55
- package/reports/junitReporter.js +0 -183
- package/reports/reporter.js +0 -166
- package/reports/reporterUtils.js +0 -54
- package/reports/teamCityReporter.js +0 -73
- package/runOptions.d.ts +0 -305
- package/runOptions.js +0 -1288
- package/runOptionsAgentFlow.js +0 -87
- package/runOptionsUtils.js +0 -60
- package/runner.js +0 -355
- package/runners/ParallelWorkerManager.js +0 -284
- package/runners/TestPlanRunner.js +0 -419
- package/runners/buildCodeTests.js +0 -159
- package/runners/runnerUtils.js +0 -81
- package/services/analyticsService.js +0 -96
- package/services/branchService.js +0 -29
- package/services/gridService.js +0 -357
- package/services/gridService.test.js +0 -357
- package/services/labFeaturesService.js +0 -64
- package/services/lambdatestService.js +0 -227
- package/services/lambdatestService.test.js +0 -353
- package/services/localRCASaver.js +0 -124
- package/stepPlayers/cliJsStepPlayback.js +0 -40
- package/stepPlayers/hybridStepPlayback.js +0 -140
- package/stepPlayers/nodePackageStepPlayback.js +0 -28
- package/stepPlayers/playwrightHybridStepPlayback.js +0 -61
- package/stepPlayers/puppeteerHybridStepPlayback.js +0 -76
- package/stepPlayers/remoteStepPlayback.js +0 -80
- package/stepPlayers/seleniumHybridStepPlayback.js +0 -84
- package/stepPlayers/tdkHybridStepPlayback.js +0 -112
- package/testRunHandler.js +0 -603
- package/testRunStatus.js +0 -567
- package/testimNpmDriver.js +0 -52
- package/utils/argsUtils.js +0 -91
- package/utils/argsUtils.test.js +0 -32
- package/utils/fsUtils.js +0 -174
- package/utils/index.js +0 -197
- package/utils/promiseUtils.js +0 -85
- package/utils/stringUtils.js +0 -98
- package/utils/stringUtils.test.js +0 -22
- package/utils/timeUtils.js +0 -25
- package/utils/utils.test.js +0 -27
- package/workers/BaseWorker.js +0 -498
- package/workers/BaseWorker.test.js +0 -186
- package/workers/WorkerAppium.js +0 -180
- package/workers/WorkerExtension.js +0 -192
- package/workers/WorkerExtensionSingleBrowser.js +0 -77
- package/workers/WorkerSelenium.js +0 -253
- package/workers/workerUtils.js +0 -20
|
@@ -1,671 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const webdriverio = require('@testim/webdriverio');
|
|
4
|
-
const Queue = require('promise-queue');
|
|
5
|
-
const config = require('../commons/config');
|
|
6
|
-
const { UNICODE_CHARACTERS, W3C_ELEMENT_ID } = require('./constants');
|
|
7
|
-
const isElementDisplayed = require('./scripts/isElementDisplayed');
|
|
8
|
-
const logger = require('../commons/logger').getLogger('WebDriverApi');
|
|
9
|
-
const { isOldProtocol, encodeForSafari } = require('./webDriverUtils');
|
|
10
|
-
const { extractElementId } = require('../utils');
|
|
11
|
-
const { SELENIUM_PERF_MARKS } = require('../commons/SeleniumPerfStats');
|
|
12
|
-
|
|
13
|
-
Queue.configure(Promise);
|
|
14
|
-
const perf = require('../commons/performance-logger');
|
|
15
|
-
|
|
16
|
-
const getViewportSizeHelper = function () {
|
|
17
|
-
return {
|
|
18
|
-
screenWidth: Math.floor(window.innerWidth || 0),
|
|
19
|
-
screenHeight: Math.floor(window.innerHeight || 0),
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
class WebdriverioWebDriverApi {
|
|
24
|
-
constructor() {
|
|
25
|
-
this.w3cRequests = {};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
windowHandleMaximize() {
|
|
29
|
-
return this.addToQueue(() => this.client.windowHandleMaximize().then(result => ({
|
|
30
|
-
height: result.value.height,
|
|
31
|
-
width: result.value.width,
|
|
32
|
-
})));
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
rejectWithLog(err, func) {
|
|
36
|
-
const { testName, testResultId } = this;
|
|
37
|
-
const crashingFunc = func ? func.toString().substr(0, 2000) : '';
|
|
38
|
-
logger.warn('error from selenium', {
|
|
39
|
-
err, testResultId, testName, crashingFunc,
|
|
40
|
-
});
|
|
41
|
-
return Promise.reject(err);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
initQueueRequests() {
|
|
45
|
-
let maxConcurrent = Infinity;
|
|
46
|
-
if (this.isAndroid()) {
|
|
47
|
-
maxConcurrent = 1;
|
|
48
|
-
}
|
|
49
|
-
if (typeof config.REQUESTS_QUEUE_SIZE !== 'undefined') {
|
|
50
|
-
maxConcurrent = config.REQUESTS_QUEUE_SIZE;
|
|
51
|
-
}
|
|
52
|
-
const maxQueue = Infinity;
|
|
53
|
-
this.queue = new Queue(maxConcurrent, maxQueue);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/** @returns {Promise<any>} */
|
|
57
|
-
addToQueue(func) {
|
|
58
|
-
const perfId = this.seleniumPerfStats.markStart();
|
|
59
|
-
return this.queue.add(func)
|
|
60
|
-
.catch(err => this.rejectWithLog(err, func))
|
|
61
|
-
.finally(() => this.seleniumPerfStats.markEnd(perfId));
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
async initClient(capabilities, testName, testResultId) {
|
|
65
|
-
this.testName = testName;
|
|
66
|
-
this.testResultId = testResultId;
|
|
67
|
-
// silence warning regarding `buttonPress` being deprecated
|
|
68
|
-
capabilities.deprecationWarnings = false;
|
|
69
|
-
this.client = webdriverio.remote(capabilities);
|
|
70
|
-
this.initQueueRequests();
|
|
71
|
-
perf.log('right before addToQueue');
|
|
72
|
-
const perfId = this.seleniumPerfStats.markStart(SELENIUM_PERF_MARKS.GET_BROWSER);
|
|
73
|
-
try {
|
|
74
|
-
await this.addToQueue(() => {
|
|
75
|
-
logger.info('requesting browser', { testResultId, testName });
|
|
76
|
-
perf.log('before this.client.init');
|
|
77
|
-
return this.client.init();
|
|
78
|
-
});
|
|
79
|
-
perf.log('after client init');
|
|
80
|
-
} finally {
|
|
81
|
-
await this.seleniumPerfStats.markEnd(perfId, SELENIUM_PERF_MARKS.GET_BROWSER);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
get isMobile() {
|
|
86
|
-
return this.client.isMobile;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
getSessionId() {
|
|
90
|
-
return this.client?.requestHandler?.sessionID;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
isChrome() {
|
|
94
|
-
return this.client.desiredCapabilities.browserName === 'chrome';
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
isChromium() {
|
|
98
|
-
return this.isChrome() || this.isEdgeChromium();
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
isFirefox() {
|
|
102
|
-
return this.client.desiredCapabilities.browserName === 'firefox';
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
isSafari() {
|
|
106
|
-
return this.client.desiredCapabilities.browserName === 'safari' || this.client.desiredCapabilities.browserName === 'safari technology preview';
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
isAndroid() {
|
|
110
|
-
return this.client.desiredCapabilities.platformName === 'Android';
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
isEdgeChromium() {
|
|
114
|
-
return this.client.desiredCapabilities.browserName === 'MicrosoftEdge' && !this.client.desiredCapabilities._isOldEdge;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
execute(...args) {
|
|
118
|
-
return this.addToQueue(() => {
|
|
119
|
-
let script = args.shift();
|
|
120
|
-
|
|
121
|
-
/*!
|
|
122
|
-
* parameter check
|
|
123
|
-
*/
|
|
124
|
-
if ((typeof script !== 'string' && typeof script !== 'function')) {
|
|
125
|
-
return Promise.reject(new Error('number or type of arguments don\'t agree with execute protocol command'));
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/*!
|
|
129
|
-
* instances started as multibrowserinstance can't getting called with
|
|
130
|
-
* a function parameter, therefor we need to check if it starts with "function () {"
|
|
131
|
-
*/
|
|
132
|
-
if (typeof script === 'function') {
|
|
133
|
-
script = `return (${script}).apply(null, arguments)`;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const decorateErrorWithExecutedScript = (err => {
|
|
137
|
-
err.executedScript = script;
|
|
138
|
-
throw err;
|
|
139
|
-
});
|
|
140
|
-
const newEndpoint = () => this.client.requestHandler.create('/session/:sessionId/execute/sync', {
|
|
141
|
-
script,
|
|
142
|
-
args,
|
|
143
|
-
}).catch(decorateErrorWithExecutedScript);
|
|
144
|
-
const oldEndpoint = () => this.client.requestHandler.create('/session/:sessionId/execute', { script, args })
|
|
145
|
-
.catch(decorateErrorWithExecutedScript);
|
|
146
|
-
|
|
147
|
-
if (this.w3cRequests.execute) {
|
|
148
|
-
return newEndpoint();
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
return oldEndpoint()
|
|
152
|
-
.catch(err => {
|
|
153
|
-
/**
|
|
154
|
-
* jsonwire command not supported try webdriver endpoint
|
|
155
|
-
*/
|
|
156
|
-
if (isOldProtocol(err)) {
|
|
157
|
-
this.w3cRequests.execute = true;
|
|
158
|
-
return newEndpoint();
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
throw err;
|
|
162
|
-
});
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* note that script received here must accept a callback, and call it when they finish running!
|
|
168
|
-
* @param {...any} args - the first argument is a script, the others are the script arguments.
|
|
169
|
-
*/
|
|
170
|
-
executeAsync(...args) {
|
|
171
|
-
return this.addToQueue(() => {
|
|
172
|
-
let script = args.shift();
|
|
173
|
-
|
|
174
|
-
/*!
|
|
175
|
-
* parameter check
|
|
176
|
-
*/
|
|
177
|
-
if ((typeof script !== 'string' && typeof script !== 'function')) {
|
|
178
|
-
return Promise.reject(new Error('number or type of arguments don\'t agree with execute protocol command'));
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/*!
|
|
182
|
-
* instances started as multibrowserinstance can't getting called with
|
|
183
|
-
* a function parameter, therefor we need to check if it starts with "function () {"
|
|
184
|
-
*/
|
|
185
|
-
if (typeof script === 'function') {
|
|
186
|
-
script = `return (${script}).apply(null, arguments)`;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
const newEndpoint = () => this.client.requestHandler.create('/session/:sessionId/execute/async', {
|
|
190
|
-
script,
|
|
191
|
-
args,
|
|
192
|
-
});
|
|
193
|
-
const oldEndpoint = () => this.client.requestHandler.create('/session/:sessionId/execute_async', {
|
|
194
|
-
script,
|
|
195
|
-
args,
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
if (this.w3cRequests.executeAsync) {
|
|
199
|
-
return newEndpoint();
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
return oldEndpoint()
|
|
203
|
-
.catch(err => {
|
|
204
|
-
/**
|
|
205
|
-
* jsonwire command not supported try webdriver endpoint
|
|
206
|
-
*/
|
|
207
|
-
if (isOldProtocol(err)) {
|
|
208
|
-
this.w3cRequests.executeAsync = true;
|
|
209
|
-
return newEndpoint();
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
throw err;
|
|
213
|
-
});
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
async executeCDP(command, parameters = {}) {
|
|
218
|
-
if (!this.isChromium()) {
|
|
219
|
-
return undefined;
|
|
220
|
-
}
|
|
221
|
-
const result = await this.client.requestHandler.create({
|
|
222
|
-
path: '/session/:sessionId/chromium/send_command_and_get_result',
|
|
223
|
-
method: 'POST',
|
|
224
|
-
}, {
|
|
225
|
-
cmd: command,
|
|
226
|
-
params: parameters,
|
|
227
|
-
});
|
|
228
|
-
if (!result || !result.value || !result.value.targetInfos) {
|
|
229
|
-
return [];
|
|
230
|
-
}
|
|
231
|
-
return result.value.targetInfos;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
takeScreenshot() {
|
|
235
|
-
const perfId = this.seleniumPerfStats.markStart(SELENIUM_PERF_MARKS.GET_SCREENSHOT);
|
|
236
|
-
return this.addToQueue(() => this.client.screenshot())
|
|
237
|
-
.finally(() => this.seleniumPerfStats.markEnd(perfId, SELENIUM_PERF_MARKS.GET_SCREENSHOT));
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
/**
|
|
241
|
-
* @param {string} selector
|
|
242
|
-
* @returns {Promise<{ value: HTMLElement }>}
|
|
243
|
-
*/
|
|
244
|
-
getElementBySelector(selector) {
|
|
245
|
-
return this.addToQueue(() => this.client.element(selector));
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
elementIdDisplayed(elementId) {
|
|
249
|
-
return this.addToQueue(() => {
|
|
250
|
-
const oldEndpoint = () => this.client.elementIdDisplayed(elementId);
|
|
251
|
-
const newEndpoint = () => this.execute(isElementDisplayed, { ELEMENT: elementId, [W3C_ELEMENT_ID]: elementId });
|
|
252
|
-
|
|
253
|
-
if (this.w3cRequests.elementIdDisplayed) {
|
|
254
|
-
return newEndpoint();
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
return oldEndpoint()
|
|
258
|
-
.catch(err => {
|
|
259
|
-
/**
|
|
260
|
-
* jsonwire command not supported try webdriver endpoint
|
|
261
|
-
*/
|
|
262
|
-
if (isOldProtocol(err)) {
|
|
263
|
-
this.w3cRequests.elementIdDisplayed = true;
|
|
264
|
-
return newEndpoint();
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
throw err;
|
|
268
|
-
});
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
windowHandles() {
|
|
273
|
-
return this.addToQueue(() => {
|
|
274
|
-
const oldEndpoint = () => this.client.requestHandler.create('/session/:sessionId/window_handles');
|
|
275
|
-
const newEndpoint = () => this.client.requestHandler.create('/session/:sessionId/window/handles');
|
|
276
|
-
|
|
277
|
-
if (this.w3cRequests.windowHandles) {
|
|
278
|
-
return newEndpoint();
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
return oldEndpoint()
|
|
282
|
-
.catch(err => {
|
|
283
|
-
/**
|
|
284
|
-
* jsonwire command not supported try webdriver endpoint
|
|
285
|
-
*/
|
|
286
|
-
if (isOldProtocol(err)) {
|
|
287
|
-
this.w3cRequests.windowHandles = true;
|
|
288
|
-
return newEndpoint();
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
throw err;
|
|
292
|
-
});
|
|
293
|
-
});
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
url(url) {
|
|
297
|
-
return this.addToQueue(() => this.client.url(encodeForSafari(url, this.isSafari(), logger)));
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
reloadTab() {
|
|
301
|
-
return this.addToQueue(() => this.client.refresh());
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
source() {
|
|
305
|
-
return this.addToQueue(() => this.client.source());
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
timeouts(type, ms) {
|
|
309
|
-
return this.addToQueue(() => {
|
|
310
|
-
const oldEndpoint = () => this.client.requestHandler.create('/session/:sessionId/timeouts', {
|
|
311
|
-
type,
|
|
312
|
-
ms,
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
const newEndpoint = () => this.client.requestHandler.create('/session/:sessionId/timeouts', {
|
|
316
|
-
[type]: ms,
|
|
317
|
-
});
|
|
318
|
-
|
|
319
|
-
if (this.w3cRequests.timeouts) {
|
|
320
|
-
return newEndpoint();
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
return oldEndpoint()
|
|
324
|
-
.catch(err => {
|
|
325
|
-
if (isOldProtocol(err)) {
|
|
326
|
-
this.w3cRequests.timeouts = true;
|
|
327
|
-
return newEndpoint();
|
|
328
|
-
}
|
|
329
|
-
throw err;
|
|
330
|
-
});
|
|
331
|
-
});
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
scroll(xoffset, yoffset) {
|
|
335
|
-
xoffset = typeof xoffset === 'number' ? xoffset : 0;
|
|
336
|
-
yoffset = typeof yoffset === 'number' ? yoffset : 0;
|
|
337
|
-
|
|
338
|
-
const scroll = function (x, y) {
|
|
339
|
-
window.scrollTo(x, y);
|
|
340
|
-
};
|
|
341
|
-
|
|
342
|
-
return this.execute(scroll, xoffset, yoffset);
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
setValue(element, value) {
|
|
346
|
-
return this.elementIdClear(extractElementId(element))
|
|
347
|
-
.then(() => this.elementIdValue(extractElementId(element), value));
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
getViewportSize(prop) {
|
|
351
|
-
return this.execute(getViewportSizeHelper).then((res) => {
|
|
352
|
-
if (typeof prop === 'string' && prop.match(/(width|height)/)) {
|
|
353
|
-
prop = `screen${prop.slice(0, 1).toUpperCase()}${prop.slice(1)}`;
|
|
354
|
-
return res.value[prop];
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
return {
|
|
358
|
-
width: res.value.screenWidth || 0,
|
|
359
|
-
height: res.value.screenHeight || 0,
|
|
360
|
-
};
|
|
361
|
-
});
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
keys(value) {
|
|
365
|
-
const checkUnicode = _value => (UNICODE_CHARACTERS.hasOwnProperty(_value) ? [UNICODE_CHARACTERS[_value]] : _value.split(''));
|
|
366
|
-
|
|
367
|
-
let key = [];
|
|
368
|
-
|
|
369
|
-
/**
|
|
370
|
-
* replace key with corresponding unicode character
|
|
371
|
-
*/
|
|
372
|
-
if (typeof value === 'string') {
|
|
373
|
-
key = checkUnicode(value);
|
|
374
|
-
} else if (value instanceof Array) {
|
|
375
|
-
for (const charSet of value) {
|
|
376
|
-
key = key.concat(checkUnicode(charSet));
|
|
377
|
-
}
|
|
378
|
-
} else {
|
|
379
|
-
return Promise.reject(new Error('number or type of arguments don\'t agree with keys protocol command'));
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
const oldEndpoint = () => this.client.requestHandler.create('/session/:sessionId/keys', { value: key });
|
|
383
|
-
const newEndpoint = () => {
|
|
384
|
-
const keyDownActions = key.map((_value) => ({ type: 'keyDown', value: _value }));
|
|
385
|
-
const keyUpActions = key.map((_value) => ({ type: 'keyUp', value: _value }));
|
|
386
|
-
|
|
387
|
-
return this.actions([{
|
|
388
|
-
type: 'key',
|
|
389
|
-
id: 'keys',
|
|
390
|
-
actions: [...keyDownActions, ...keyUpActions],
|
|
391
|
-
}]);
|
|
392
|
-
};
|
|
393
|
-
|
|
394
|
-
if (this.w3cRequests.keys) {
|
|
395
|
-
return newEndpoint();
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
return this.addToQueue(() => oldEndpoint().catch(err => {
|
|
399
|
-
/**
|
|
400
|
-
* use W3C path if old path failed
|
|
401
|
-
*/
|
|
402
|
-
if (isOldProtocol(err)) {
|
|
403
|
-
this.w3cRequests.keys = true;
|
|
404
|
-
return newEndpoint();
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
throw err;
|
|
408
|
-
}));
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
elementIdValue(elementId, value) {
|
|
412
|
-
return this.addToQueue(() => this.client.elementIdValue(elementId, value));
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
elementIdClear(elementId) {
|
|
416
|
-
return this.addToQueue(() => this.client.elementIdClear(elementId));
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
submitForm(element) {
|
|
420
|
-
return this.addToQueue(() => this.client.submit(extractElementId(element)));
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
buttonPress(button) {
|
|
424
|
-
return this.addToQueue(() => this.client.buttonPress(button));
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
findElementAndPress(element, xOffset, yOffset, button) {
|
|
428
|
-
return this.moveTo(extractElementId(element), xOffset, yOffset)
|
|
429
|
-
.then(() => this.buttonPress(button));
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
rightClick(element, xOffset, yOffset) {
|
|
433
|
-
return this.findElementAndPress(element, xOffset, yOffset, 'right');
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
leftClick(element, xOffset, yOffset) {
|
|
437
|
-
return this.findElementAndPress(element, xOffset, yOffset, 'left');
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
elementIdClick(elementId) {
|
|
441
|
-
return this.addToQueue(() => this.client.elementIdClick(elementId));
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
actions(actions) {
|
|
445
|
-
return this.addToQueue(() => this.client.actions(actions));
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
doDoubleClick() {
|
|
449
|
-
return this.addToQueue(() => this.client.doDoubleClick());
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
dragAndDrop(sourceSelector, destinationSelector) {
|
|
453
|
-
return this.addToQueue(() => this.client.dragAndDrop(sourceSelector, destinationSelector));
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
buttonDown() {
|
|
457
|
-
return this.addToQueue(() => this.client.buttonDown());
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
buttonUp() {
|
|
461
|
-
return this.addToQueue(() => this.client.buttonUp());
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
moveTo(element, xoffset, yoffset) {
|
|
465
|
-
const data = {};
|
|
466
|
-
|
|
467
|
-
if (typeof xoffset === 'number') {
|
|
468
|
-
data.xoffset = xoffset;
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
if (typeof yoffset === 'number') {
|
|
472
|
-
data.yoffset = yoffset;
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
// wordaround change offset to x=1 y=1 on Safari
|
|
476
|
-
if (this.isSafari() && !data.hasOwnProperty('yoffset')) {
|
|
477
|
-
data.yoffset = 1;
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
if (this.isSafari() && !data.hasOwnProperty('xoffset')) {
|
|
481
|
-
data.xoffset = 1;
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
if (typeof element === 'string') {
|
|
485
|
-
data.element = element;
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
return this.addToQueue(() => this.client.requestHandler.create('/session/:sessionId/moveto', data));
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
uploadFile(localFileLocation) {
|
|
492
|
-
return this.addToQueue(() => this.client.uploadFile(localFileLocation));
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
getUrl() {
|
|
496
|
-
return this.addToQueue(() => this.client.getUrl());
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
getTitle() {
|
|
500
|
-
return this.addToQueue(() => this.client.getTitle());
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
// eslint-disable-next-line default-param-last
|
|
504
|
-
windowHandleSize(windowHandle = 'current', size) {
|
|
505
|
-
return this.addToQueue(() => {
|
|
506
|
-
let data = {};
|
|
507
|
-
|
|
508
|
-
if (typeof windowHandle === 'object') {
|
|
509
|
-
[windowHandle, size] = ['current', windowHandle];
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
/*!
|
|
513
|
-
* protocol options
|
|
514
|
-
*/
|
|
515
|
-
const requestOptions = {
|
|
516
|
-
path: `/session/:sessionId/window/${windowHandle}/size`,
|
|
517
|
-
method: 'GET',
|
|
518
|
-
};
|
|
519
|
-
|
|
520
|
-
/*!
|
|
521
|
-
* change window size if the new size is given
|
|
522
|
-
*/
|
|
523
|
-
if (typeof size === 'object' && size.width && size.height) {
|
|
524
|
-
requestOptions.method = 'POST';
|
|
525
|
-
// The width and height value might return as a negative value, so
|
|
526
|
-
// we make sure to use its absolute value.
|
|
527
|
-
data = {
|
|
528
|
-
width: Math.abs(size.width),
|
|
529
|
-
height: Math.abs(size.height),
|
|
530
|
-
};
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
/*!
|
|
534
|
-
* type check
|
|
535
|
-
*/
|
|
536
|
-
if (requestOptions.method === 'POST' && typeof data.width !== 'number' && typeof data.height !== 'number') {
|
|
537
|
-
return Promise.reject(new Error('number or type of arguments don\'t agree with windowHandleSize protocol command'));
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
const oldEndpoint = () => this.client.requestHandler.create(requestOptions, data);
|
|
541
|
-
const newEndpoint = () => {
|
|
542
|
-
requestOptions.path = '/session/:sessionId/window/rect';
|
|
543
|
-
return this.client.requestHandler.create(requestOptions, data);
|
|
544
|
-
};
|
|
545
|
-
|
|
546
|
-
if (this.w3cRequests.windowHandleSize) {
|
|
547
|
-
return newEndpoint();
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
return oldEndpoint()
|
|
551
|
-
.catch(err => {
|
|
552
|
-
/**
|
|
553
|
-
* use W3C path if old path failed
|
|
554
|
-
*/
|
|
555
|
-
if (isOldProtocol(err)) {
|
|
556
|
-
this.w3cRequests.windowHandleSize = true;
|
|
557
|
-
return newEndpoint();
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
throw err;
|
|
561
|
-
});
|
|
562
|
-
});
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
setCookie(name, value, domain, httpOnly, secure, path, expiry) {
|
|
566
|
-
return this.addToQueue(() => this.client.setCookie({
|
|
567
|
-
name,
|
|
568
|
-
value,
|
|
569
|
-
domain,
|
|
570
|
-
httpOnly,
|
|
571
|
-
secure,
|
|
572
|
-
path,
|
|
573
|
-
expiry: expiry ? Math.floor(expiry) : expiry,
|
|
574
|
-
}));
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
getCookie(name) {
|
|
578
|
-
return this.addToQueue(() => this.client.requestHandler.create('/session/:sessionId/cookie')
|
|
579
|
-
.then(res => {
|
|
580
|
-
res.value = res.value || [];
|
|
581
|
-
|
|
582
|
-
if (typeof name === 'string') {
|
|
583
|
-
return res.value.find((cookie) => cookie.name === name || cookie.name === encodeURIComponent(encodeURIComponent(name))) || null;
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
return res.value || (typeof name === 'string' ? null : []);
|
|
587
|
-
}));
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
deleteCookie(name) {
|
|
591
|
-
return this.addToQueue(() => this.client.deleteCookie(name));
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
isVisibleWithinViewport(selector) {
|
|
595
|
-
return this.addToQueue(() => this.client.isVisibleWithinViewport(selector));
|
|
596
|
-
}
|
|
597
|
-
|
|
598
|
-
getCurrentTabId() {
|
|
599
|
-
return this.addToQueue(() => this.client.getCurrentTabId());
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
frame(id) {
|
|
603
|
-
return this.addToQueue(() => this.client.frame(id));
|
|
604
|
-
}
|
|
605
|
-
|
|
606
|
-
switchTab(tabId) {
|
|
607
|
-
return this.addToQueue(() => this.client.switchTab(tabId));
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
alertAccept() {
|
|
611
|
-
return this.addToQueue(() => this.client.alertAccept());
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
log(type = 'browser') {
|
|
615
|
-
return this.addToQueue(() => this.client.log(type));
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
end() {
|
|
619
|
-
this.w3cRequests = {};
|
|
620
|
-
return this.queue ? this.addToQueue(() => this.client.end()) : Promise.resolve();
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
forceEnd() {
|
|
624
|
-
this.w3cRequests = {};
|
|
625
|
-
return this.client ? this.client.end() : Promise.resolve();
|
|
626
|
-
}
|
|
627
|
-
|
|
628
|
-
touchPerform(actions) {
|
|
629
|
-
return this.addToQueue(() => this.client.touchPerform(actions));
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
touchAction(attr) {
|
|
633
|
-
return this.addToQueue(() => this.client.touchAction(attr));
|
|
634
|
-
}
|
|
635
|
-
|
|
636
|
-
pressKeycode(keyCode) {
|
|
637
|
-
return this.addToQueue(() => this.client.pressKeycode(keyCode));
|
|
638
|
-
}
|
|
639
|
-
|
|
640
|
-
setImmediateValue(elementId, text) {
|
|
641
|
-
return this.addToQueue(() => this.client.setImmediateValue(elementId, text));
|
|
642
|
-
}
|
|
643
|
-
|
|
644
|
-
elementIdText(elementId) {
|
|
645
|
-
return this.addToQueue(() => this.client.elementIdText(elementId))
|
|
646
|
-
.then(res => res.value);
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
isAppInstalled(packageName) {
|
|
650
|
-
return this.addToQueue(() => this.client.isAppInstalled(packageName))
|
|
651
|
-
.then(isInstalled => {
|
|
652
|
-
const ret = !!isInstalled.value;
|
|
653
|
-
logger.info(`is app (${packageName}) installed? ${ret}`, isInstalled);
|
|
654
|
-
return ret;
|
|
655
|
-
});
|
|
656
|
-
}
|
|
657
|
-
|
|
658
|
-
launch() {
|
|
659
|
-
return this.addToQueue(() => this.client.launch());
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
context(id) {
|
|
663
|
-
return this.addToQueue(() => this.client.context(id));
|
|
664
|
-
}
|
|
665
|
-
|
|
666
|
-
elementIdLocation(elementId) {
|
|
667
|
-
return this.addToQueue(() => this.client.elementIdLocation(elementId));
|
|
668
|
-
}
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
module.exports = WebdriverioWebDriverApi;
|