webdriverio 7.20.7 → 7.20.8-alpha.504
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/build/cjs/index.d.ts +3 -0
- package/build/cjs/index.d.ts.map +1 -0
- package/build/cjs/index.js +13 -0
- package/build/cjs/package.json +3 -0
- package/build/commands/browser/$$.d.ts +10 -1
- package/build/commands/browser/$$.d.ts.map +1 -1
- package/build/commands/browser/$$.js +16 -9
- package/build/commands/browser/$.js +8 -11
- package/build/commands/browser/action.d.ts +132 -0
- package/build/commands/browser/action.d.ts.map +1 -0
- package/build/commands/browser/action.js +13 -0
- package/build/commands/browser/actions.d.ts +29 -0
- package/build/commands/browser/actions.d.ts.map +1 -0
- package/build/commands/browser/actions.js +30 -0
- package/build/commands/browser/addCommand.d.ts +1 -1
- package/build/commands/browser/addCommand.js +1 -1
- package/build/commands/browser/call.d.ts +7 -5
- package/build/commands/browser/call.d.ts.map +1 -1
- package/build/commands/browser/call.js +8 -9
- package/build/commands/browser/custom$$.js +7 -10
- package/build/commands/browser/custom$.d.ts +1 -1
- package/build/commands/browser/custom$.js +6 -9
- package/build/commands/browser/debug.js +8 -14
- package/build/commands/browser/deleteCookies.d.ts +3 -3
- package/build/commands/browser/deleteCookies.js +4 -7
- package/build/commands/browser/execute.d.ts +2 -2
- package/build/commands/browser/execute.js +5 -8
- package/build/commands/browser/executeAsync.js +3 -6
- package/build/commands/browser/getCookies.d.ts +2 -2
- package/build/commands/browser/getCookies.js +3 -6
- package/build/commands/browser/getPuppeteer.d.ts +1 -1
- package/build/commands/browser/getPuppeteer.d.ts.map +1 -1
- package/build/commands/browser/getPuppeteer.js +14 -21
- package/build/commands/browser/getWindowSize.js +3 -6
- package/build/commands/browser/keys.d.ts +20 -10
- package/build/commands/browser/keys.d.ts.map +1 -1
- package/build/commands/browser/keys.js +29 -24
- package/build/commands/browser/mock.d.ts +5 -4
- package/build/commands/browser/mock.d.ts.map +1 -1
- package/build/commands/browser/mock.js +16 -22
- package/build/commands/browser/mockClearAll.js +5 -11
- package/build/commands/browser/mockRestoreAll.js +5 -11
- package/build/commands/browser/newWindow.js +5 -11
- package/build/commands/browser/pause.js +1 -4
- package/build/commands/browser/react$$.d.ts.map +1 -1
- package/build/commands/browser/react$$.js +16 -17
- package/build/commands/browser/react$.d.ts.map +1 -1
- package/build/commands/browser/react$.js +13 -14
- package/build/commands/browser/reloadSession.js +5 -12
- package/build/commands/browser/savePDF.d.ts +14 -14
- package/build/commands/browser/savePDF.js +21 -27
- package/build/commands/browser/saveRecordingScreen.js +6 -12
- package/build/commands/browser/saveScreenshot.js +6 -12
- package/build/commands/browser/scroll.d.ts +25 -0
- package/build/commands/browser/scroll.d.ts.map +1 -0
- package/build/commands/browser/scroll.js +41 -0
- package/build/commands/browser/setCookies.d.ts +1 -1
- package/build/commands/browser/setCookies.d.ts.map +1 -1
- package/build/commands/browser/setCookies.js +5 -7
- package/build/commands/browser/setTimeout.js +1 -4
- package/build/commands/browser/setWindowSize.js +3 -6
- package/build/commands/browser/switchWindow.js +1 -4
- package/build/commands/browser/throttle.js +3 -6
- package/build/commands/browser/touchAction.d.ts +1 -1
- package/build/commands/browser/touchAction.d.ts.map +1 -1
- package/build/commands/browser/touchAction.js +3 -6
- package/build/commands/browser/uploadFile.d.ts +1 -1
- package/build/commands/browser/uploadFile.d.ts.map +1 -1
- package/build/commands/browser/uploadFile.js +10 -15
- package/build/commands/browser/url.js +3 -6
- package/build/commands/browser/waitUntil.d.ts +1 -2
- package/build/commands/browser/waitUntil.d.ts.map +1 -1
- package/build/commands/browser/waitUntil.js +4 -11
- package/build/commands/browser.d.ts +37 -69
- package/build/commands/browser.d.ts.map +1 -1
- package/build/commands/browser.js +37 -44
- package/build/commands/constant.d.ts +1 -1
- package/build/commands/constant.d.ts.map +1 -1
- package/build/commands/constant.js +6 -12
- package/build/commands/element/$$.d.ts +1 -1
- package/build/commands/element/$$.d.ts.map +1 -1
- package/build/commands/element/$$.js +2 -7
- package/build/commands/element/$.d.ts +1 -1
- package/build/commands/element/$.d.ts.map +1 -1
- package/build/commands/element/$.js +2 -7
- package/build/commands/element/addValue.d.ts +10 -14
- package/build/commands/element/addValue.d.ts.map +1 -1
- package/build/commands/element/addValue.js +23 -27
- package/build/commands/element/clearValue.d.ts +1 -1
- package/build/commands/element/clearValue.js +2 -5
- package/build/commands/element/click.d.ts +1 -1
- package/build/commands/element/click.d.ts.map +1 -1
- package/build/commands/element/click.js +19 -34
- package/build/commands/element/custom$$.js +9 -11
- package/build/commands/element/custom$.js +8 -10
- package/build/commands/element/doubleClick.d.ts.map +1 -1
- package/build/commands/element/doubleClick.js +11 -17
- package/build/commands/element/dragAndDrop.d.ts.map +1 -1
- package/build/commands/element/dragAndDrop.js +13 -19
- package/build/commands/element/getAttribute.js +1 -4
- package/build/commands/element/getCSSProperty.d.ts +1 -1
- package/build/commands/element/getCSSProperty.d.ts.map +1 -1
- package/build/commands/element/getCSSProperty.js +7 -13
- package/build/commands/element/getComputedLabel.js +1 -4
- package/build/commands/element/getComputedRole.js +1 -4
- package/build/commands/element/getHTML.js +7 -13
- package/build/commands/element/getLocation.js +3 -5
- package/build/commands/element/getProperty.d.ts +5 -5
- package/build/commands/element/getProperty.d.ts.map +1 -1
- package/build/commands/element/getProperty.js +5 -11
- package/build/commands/element/getSize.js +3 -5
- package/build/commands/element/getTagName.js +1 -4
- package/build/commands/element/getText.js +1 -4
- package/build/commands/element/getValue.js +1 -4
- package/build/commands/element/isClickable.d.ts.map +1 -1
- package/build/commands/element/isClickable.js +10 -13
- package/build/commands/element/isDisplayed.js +9 -16
- package/build/commands/element/isDisplayedInViewport.js +7 -13
- package/build/commands/element/isEnabled.js +1 -4
- package/build/commands/element/isEqual.d.ts.map +1 -1
- package/build/commands/element/isEqual.js +9 -9
- package/build/commands/element/isExisting.js +1 -4
- package/build/commands/element/isFocused.js +7 -13
- package/build/commands/element/isSelected.js +1 -4
- package/build/commands/element/moveTo.d.ts.map +1 -1
- package/build/commands/element/moveTo.js +8 -13
- package/build/commands/element/nextElement.js +2 -5
- package/build/commands/element/parentElement.js +2 -5
- package/build/commands/element/previousElement.js +2 -5
- package/build/commands/element/react$$.d.ts.map +1 -1
- package/build/commands/element/react$$.js +16 -16
- package/build/commands/element/react$.d.ts.map +1 -1
- package/build/commands/element/react$.js +15 -14
- package/build/commands/element/saveScreenshot.js +6 -12
- package/build/commands/element/scrollIntoView.d.ts +4 -2
- package/build/commands/element/scrollIntoView.d.ts.map +1 -1
- package/build/commands/element/scrollIntoView.js +33 -12
- package/build/commands/element/selectByAttribute.js +3 -6
- package/build/commands/element/selectByIndex.js +3 -6
- package/build/commands/element/selectByVisibleText.js +3 -6
- package/build/commands/element/setValue.d.ts +13 -14
- package/build/commands/element/setValue.d.ts.map +1 -1
- package/build/commands/element/setValue.js +14 -17
- package/build/commands/element/shadow$$.d.ts +1 -1
- package/build/commands/element/shadow$$.d.ts.map +1 -1
- package/build/commands/element/shadow$$.js +3 -6
- package/build/commands/element/shadow$.js +3 -6
- package/build/commands/element/touchAction.js +3 -6
- package/build/commands/element/waitForClickable.js +1 -4
- package/build/commands/element/waitForDisplayed.js +1 -4
- package/build/commands/element/waitForEnabled.js +1 -4
- package/build/commands/element/waitForExist.js +1 -4
- package/build/commands/element/waitUntil.d.ts +2 -3
- package/build/commands/element/waitUntil.d.ts.map +1 -1
- package/build/commands/element/waitUntil.js +3 -9
- package/build/commands/element.d.ts +49 -99
- package/build/commands/element.d.ts.map +1 -1
- package/build/commands/element.js +49 -63
- package/build/constants.d.ts +67 -0
- package/build/constants.d.ts.map +1 -1
- package/build/constants.js +105 -12
- package/build/index.d.ts +65 -6
- package/build/index.d.ts.map +1 -1
- package/build/index.js +48 -86
- package/build/middlewares.d.ts +1 -1
- package/build/middlewares.js +11 -19
- package/build/multiremote.js +18 -24
- package/build/protocol-stub.d.ts.map +1 -1
- package/build/protocol-stub.js +4 -6
- package/build/scripts/getHTML.js +1 -4
- package/build/scripts/getProperty.d.ts +5 -5
- package/build/scripts/getProperty.d.ts.map +1 -1
- package/build/scripts/getProperty.js +1 -4
- package/build/scripts/isElementClickable.js +1 -4
- package/build/scripts/isElementDisplayed.js +2 -5
- package/build/scripts/isElementInViewport.js +1 -4
- package/build/scripts/isFocused.js +1 -4
- package/build/scripts/newWindow.js +1 -4
- package/build/scripts/resq.js +3 -9
- package/build/scripts/shadowFnFactory.js +2 -6
- package/build/types.d.ts +5 -9
- package/build/types.d.ts.map +1 -1
- package/build/types.js +1 -2
- package/build/utils/SevereServiceError.js +1 -4
- package/build/utils/Timer.d.ts.map +1 -1
- package/build/utils/Timer.js +13 -29
- package/build/utils/actions/base.d.ts +32 -0
- package/build/utils/actions/base.d.ts.map +1 -0
- package/build/utils/actions/base.js +66 -0
- package/build/utils/actions/index.d.ts +6 -0
- package/build/utils/actions/index.d.ts.map +1 -0
- package/build/utils/actions/index.js +5 -0
- package/build/utils/actions/key.d.ts +15 -0
- package/build/utils/actions/key.d.ts.map +1 -0
- package/build/utils/actions/key.js +22 -0
- package/build/utils/actions/pointer.d.ts +62 -0
- package/build/utils/actions/pointer.d.ts.map +1 -0
- package/build/utils/actions/pointer.js +76 -0
- package/build/utils/actions/wheel.d.ts +36 -0
- package/build/utils/actions/wheel.d.ts.map +1 -0
- package/build/utils/actions/wheel.js +20 -0
- package/build/utils/detectBackend.d.ts +1 -1
- package/build/utils/detectBackend.d.ts.map +1 -1
- package/build/utils/detectBackend.js +3 -7
- package/build/utils/findStrategy.d.ts.map +1 -1
- package/build/utils/findStrategy.js +50 -19
- package/build/utils/getElementObject.d.ts +1 -1
- package/build/utils/getElementObject.d.ts.map +1 -1
- package/build/utils/getElementObject.js +51 -32
- package/build/utils/implicitWait.js +3 -9
- package/build/utils/index.d.ts +8 -7
- package/build/utils/index.d.ts.map +1 -1
- package/build/utils/index.js +125 -148
- package/build/utils/interception/devtools.d.ts +1 -1
- package/build/utils/interception/devtools.d.ts.map +1 -1
- package/build/utils/interception/devtools.js +17 -36
- package/build/utils/interception/index.d.ts +2 -2
- package/build/utils/interception/index.d.ts.map +1 -1
- package/build/utils/interception/index.js +10 -13
- package/build/utils/interception/types.d.ts +1 -1
- package/build/utils/interception/types.d.ts.map +1 -1
- package/build/utils/interception/types.js +1 -2
- package/build/utils/interception/webdriver.d.ts +1 -1
- package/build/utils/interception/webdriver.d.ts.map +1 -1
- package/build/utils/interception/webdriver.js +6 -11
- package/build/utils/refetchElement.js +3 -9
- package/package.json +27 -17
- package/async.d.ts +0 -24
- package/sync.d.ts +0 -24
package/build/utils/index.js
CHANGED
|
@@ -1,27 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
const constants_1 = require("../constants");
|
|
21
|
-
const findStrategy_1 = require("./findStrategy");
|
|
22
|
-
const browserCommands = require('../commands/browser').default;
|
|
23
|
-
const elementCommands = require('../commands/element').default;
|
|
24
|
-
const log = (0, logger_1.default)('webdriverio');
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import http from 'node:http';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { URL } from 'node:url';
|
|
5
|
+
import cssValue from 'css-value';
|
|
6
|
+
import rgb2hex from 'rgb2hex';
|
|
7
|
+
import GraphemeSplitter from 'grapheme-splitter';
|
|
8
|
+
import logger from '@wdio/logger';
|
|
9
|
+
import isObject from 'lodash.isobject';
|
|
10
|
+
import isPlainObject from 'lodash.isplainobject';
|
|
11
|
+
// @ts-expect-error
|
|
12
|
+
import { locatorStrategy } from 'query-selector-shadow-dom/plugins/webdriverio/index.js';
|
|
13
|
+
import { SUPPORTED_BROWSER } from 'devtools';
|
|
14
|
+
import { UNICODE_CHARACTERS } from '@wdio/utils';
|
|
15
|
+
import * as browserCommands from '../commands/browser.js';
|
|
16
|
+
import * as elementCommands from '../commands/element.js';
|
|
17
|
+
import { ELEMENT_KEY, DRIVER_DEFAULT_ENDPOINT, DEEP_SELECTOR, Key } from '../constants.js';
|
|
18
|
+
import { findStrategy } from './findStrategy.js';
|
|
19
|
+
const log = logger('webdriverio');
|
|
25
20
|
const INVALID_SELECTOR_ERROR = 'selector needs to be typeof `string` or `function`';
|
|
26
21
|
const scopes = {
|
|
27
22
|
browser: browserCommands,
|
|
@@ -35,16 +30,12 @@ const applyScopePrototype = (prototype, scope) => {
|
|
|
35
30
|
/**
|
|
36
31
|
* enhances objects with element commands
|
|
37
32
|
*/
|
|
38
|
-
const getPrototype = (scope) => {
|
|
33
|
+
export const getPrototype = (scope) => {
|
|
39
34
|
const prototype = {
|
|
40
35
|
/**
|
|
41
36
|
* used to store the puppeteer instance in the browser scope
|
|
42
37
|
*/
|
|
43
|
-
puppeteer: { value: null, writable: true }
|
|
44
|
-
/**
|
|
45
|
-
* for handling sync execution in @wdio/sync
|
|
46
|
-
*/
|
|
47
|
-
_NOT_FIBER: { value: false, writable: true, configurable: true }
|
|
38
|
+
puppeteer: { value: null, writable: true }
|
|
48
39
|
};
|
|
49
40
|
/**
|
|
50
41
|
* register action commands
|
|
@@ -53,13 +44,12 @@ const getPrototype = (scope) => {
|
|
|
53
44
|
prototype.strategies = { value: new Map() };
|
|
54
45
|
return prototype;
|
|
55
46
|
};
|
|
56
|
-
exports.getPrototype = getPrototype;
|
|
57
47
|
/**
|
|
58
48
|
* get element id from WebDriver response
|
|
59
49
|
* @param {?Object|undefined} res body object from response or null
|
|
60
50
|
* @return {?string} element id or null if element couldn't be found
|
|
61
51
|
*/
|
|
62
|
-
const getElementFromResponse = (res) => {
|
|
52
|
+
export const getElementFromResponse = (res) => {
|
|
63
53
|
/**
|
|
64
54
|
* a function selector can return null
|
|
65
55
|
*/
|
|
@@ -75,52 +65,18 @@ const getElementFromResponse = (res) => {
|
|
|
75
65
|
/**
|
|
76
66
|
* W3C WebDriver response
|
|
77
67
|
*/
|
|
78
|
-
if (res[
|
|
79
|
-
return res[
|
|
68
|
+
if (res[ELEMENT_KEY]) {
|
|
69
|
+
return res[ELEMENT_KEY];
|
|
80
70
|
}
|
|
81
71
|
return null;
|
|
82
72
|
};
|
|
83
|
-
exports.getElementFromResponse = getElementFromResponse;
|
|
84
73
|
/**
|
|
85
74
|
* traverse up the scope chain until browser element was reached
|
|
86
75
|
*/
|
|
87
|
-
function getBrowserObject(elem) {
|
|
76
|
+
export function getBrowserObject(elem) {
|
|
88
77
|
const elemObject = elem;
|
|
89
78
|
return elemObject.parent ? getBrowserObject(elemObject.parent) : elem;
|
|
90
79
|
}
|
|
91
|
-
exports.getBrowserObject = getBrowserObject;
|
|
92
|
-
/**
|
|
93
|
-
* transform whatever value is into an array of char strings
|
|
94
|
-
*/
|
|
95
|
-
function transformToCharString(value, translateToUnicode = true) {
|
|
96
|
-
const ret = [];
|
|
97
|
-
if (!Array.isArray(value)) {
|
|
98
|
-
value = [value];
|
|
99
|
-
}
|
|
100
|
-
for (const val of value) {
|
|
101
|
-
if (typeof val === 'string') {
|
|
102
|
-
translateToUnicode
|
|
103
|
-
? ret.push(...checkUnicode(val))
|
|
104
|
-
: ret.push(...`${val}`.split(''));
|
|
105
|
-
}
|
|
106
|
-
else if (typeof val === 'number') {
|
|
107
|
-
const entry = `${val}`.split('');
|
|
108
|
-
ret.push(...entry);
|
|
109
|
-
}
|
|
110
|
-
else if (val && typeof val === 'object') {
|
|
111
|
-
try {
|
|
112
|
-
ret.push(...JSON.stringify(val).split(''));
|
|
113
|
-
}
|
|
114
|
-
catch (err) { /* ignore */ }
|
|
115
|
-
}
|
|
116
|
-
else if (typeof val === 'boolean') {
|
|
117
|
-
const entry = val ? 'true'.split('') : 'false'.split('');
|
|
118
|
-
ret.push(...entry);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
return ret;
|
|
122
|
-
}
|
|
123
|
-
exports.transformToCharString = transformToCharString;
|
|
124
80
|
function sanitizeCSS(value) {
|
|
125
81
|
/* istanbul ignore next */
|
|
126
82
|
if (!value) {
|
|
@@ -134,14 +90,13 @@ function sanitizeCSS(value) {
|
|
|
134
90
|
* @param {String} cssProperty name of css property to parse
|
|
135
91
|
* @return {Object} parsed css property
|
|
136
92
|
*/
|
|
137
|
-
function parseCSS(cssPropertyValue, cssProperty) {
|
|
138
|
-
var _a;
|
|
93
|
+
export function parseCSS(cssPropertyValue, cssProperty) {
|
|
139
94
|
const parsedValue = {
|
|
140
95
|
property: cssProperty,
|
|
141
96
|
value: cssPropertyValue.toLowerCase().trim(),
|
|
142
97
|
parsed: {}
|
|
143
98
|
};
|
|
144
|
-
if (
|
|
99
|
+
if (parsedValue.value?.indexOf('rgb') === 0) {
|
|
145
100
|
/**
|
|
146
101
|
* remove whitespaces in rgb values
|
|
147
102
|
*/
|
|
@@ -150,13 +105,13 @@ function parseCSS(cssPropertyValue, cssProperty) {
|
|
|
150
105
|
* parse color values
|
|
151
106
|
*/
|
|
152
107
|
let color = parsedValue.value;
|
|
153
|
-
parsedValue.parsed = (
|
|
108
|
+
parsedValue.parsed = rgb2hex(parsedValue.value);
|
|
154
109
|
parsedValue.parsed.type = 'color';
|
|
155
110
|
const colorType = /[rgba]+/g.exec(color) || [];
|
|
156
111
|
parsedValue.parsed[colorType[0]] = color;
|
|
157
112
|
}
|
|
158
113
|
else if (parsedValue.property === 'font-family') {
|
|
159
|
-
let font = (
|
|
114
|
+
let font = cssValue(cssPropertyValue);
|
|
160
115
|
let string = parsedValue.value;
|
|
161
116
|
let value = cssPropertyValue.split(/,/).map(sanitizeCSS);
|
|
162
117
|
parsedValue.value = sanitizeCSS(font[0].value || font[0].string);
|
|
@@ -167,7 +122,7 @@ function parseCSS(cssPropertyValue, cssProperty) {
|
|
|
167
122
|
* parse other css properties
|
|
168
123
|
*/
|
|
169
124
|
try {
|
|
170
|
-
const value = (
|
|
125
|
+
const value = cssValue(cssPropertyValue);
|
|
171
126
|
if (value.length === 1) {
|
|
172
127
|
parsedValue.parsed = value[0];
|
|
173
128
|
}
|
|
@@ -182,61 +137,76 @@ function parseCSS(cssPropertyValue, cssProperty) {
|
|
|
182
137
|
}
|
|
183
138
|
return parsedValue;
|
|
184
139
|
}
|
|
185
|
-
exports.parseCSS = parseCSS;
|
|
186
140
|
/**
|
|
187
141
|
* check for unicode character or split string into literals
|
|
188
142
|
* @param {String} value text
|
|
189
143
|
* @return {Array} set of characters or unicode symbols
|
|
190
144
|
*/
|
|
191
|
-
function checkUnicode(value, isDevTools = false) {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
145
|
+
export function checkUnicode(value, isDevTools = false, platformName) {
|
|
146
|
+
if (value === Key.Ctrl) {
|
|
147
|
+
return [platformName && platformName.match(/mac(\s)*os/i) ? Key.Command : Key.Control];
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* when sending emoji characters like 😄 or a value that is not a special character defined
|
|
151
|
+
* by the WebDriver protocol
|
|
152
|
+
*/
|
|
153
|
+
if (!Object.prototype.hasOwnProperty.call(UNICODE_CHARACTERS, value)) {
|
|
154
|
+
return new GraphemeSplitter().splitGraphemes(value);
|
|
155
|
+
}
|
|
156
|
+
if (isDevTools) {
|
|
157
|
+
return [value];
|
|
158
|
+
}
|
|
159
|
+
return [UNICODE_CHARACTERS[value]];
|
|
195
160
|
}
|
|
196
|
-
|
|
197
|
-
function fetchElementByJSFunction(selector, scope) {
|
|
161
|
+
function fetchElementByJSFunction(selector, scope, referenceId) {
|
|
198
162
|
if (!scope.elementId) {
|
|
199
|
-
return scope.execute(selector);
|
|
163
|
+
return scope.execute(selector, referenceId);
|
|
200
164
|
}
|
|
201
165
|
/**
|
|
202
166
|
* use a regular function because IE does not understand arrow functions
|
|
203
167
|
*/
|
|
204
|
-
const script = (function (elem) {
|
|
205
|
-
return selector.call(elem);
|
|
168
|
+
const script = (function (elem, id) {
|
|
169
|
+
return selector.call(elem, id);
|
|
206
170
|
}).toString().replace('selector', `(${selector.toString()})`);
|
|
207
|
-
return getBrowserObject(scope).execute(`return (${script}).apply(null, arguments)`, scope);
|
|
171
|
+
return getBrowserObject(scope).execute(`return (${script}).apply(null, arguments)`, scope, referenceId);
|
|
172
|
+
}
|
|
173
|
+
function isElement(o) {
|
|
174
|
+
return (typeof HTMLElement === 'object'
|
|
175
|
+
? o instanceof HTMLElement
|
|
176
|
+
: o && typeof o === 'object' && o !== null && o.nodeType === 1 && typeof o.nodeName === 'string');
|
|
208
177
|
}
|
|
209
178
|
/**
|
|
210
179
|
* logic to find an element
|
|
211
180
|
*/
|
|
212
|
-
async function findElement(selector) {
|
|
181
|
+
export async function findElement(selector) {
|
|
182
|
+
const browserObject = getBrowserObject(this);
|
|
213
183
|
/**
|
|
214
184
|
* check if shadow DOM integration is used
|
|
215
185
|
*/
|
|
216
|
-
if (!this.isDevTools && typeof selector === 'string' && selector.startsWith(
|
|
217
|
-
const notFoundError = new Error(`shadow selector "${selector.slice(
|
|
218
|
-
let elem = await
|
|
219
|
-
selector.slice(
|
|
186
|
+
if (!this.isDevTools && typeof selector === 'string' && selector.startsWith(DEEP_SELECTOR)) {
|
|
187
|
+
const notFoundError = new Error(`shadow selector "${selector.slice(DEEP_SELECTOR.length)}" did not return an HTMLElement`);
|
|
188
|
+
let elem = await browserObject.execute(locatorStrategy, ...[
|
|
189
|
+
selector.slice(DEEP_SELECTOR.length),
|
|
220
190
|
this.elementId ? this : undefined
|
|
221
191
|
].filter(Boolean));
|
|
222
192
|
elem = Array.isArray(elem) ? elem[0] : elem;
|
|
223
|
-
return
|
|
193
|
+
return getElementFromResponse(elem) ? elem : notFoundError;
|
|
224
194
|
}
|
|
225
195
|
/**
|
|
226
196
|
* fetch element using custom strategy function
|
|
227
197
|
*/
|
|
228
|
-
if ((
|
|
198
|
+
if (isPlainObject(selector) && typeof selector.strategy === 'function') {
|
|
229
199
|
const { strategy, strategyName, strategyArguments } = selector;
|
|
230
200
|
const notFoundError = new Error(`Custom Strategy "${strategyName}" did not return an HTMLElement`);
|
|
231
|
-
let elem = await
|
|
201
|
+
let elem = await browserObject.execute(strategy, ...strategyArguments);
|
|
232
202
|
elem = Array.isArray(elem) ? elem[0] : elem;
|
|
233
|
-
return
|
|
203
|
+
return getElementFromResponse(elem) ? elem : notFoundError;
|
|
234
204
|
}
|
|
235
205
|
/**
|
|
236
206
|
* fetch element using regular protocol command
|
|
237
207
|
*/
|
|
238
|
-
if (typeof selector === 'string' || (
|
|
239
|
-
const { using, value } =
|
|
208
|
+
if (typeof selector === 'string' || isPlainObject(selector)) {
|
|
209
|
+
const { using, value } = findStrategy(selector, this.isW3C, this.isMobile);
|
|
240
210
|
return this.elementId
|
|
241
211
|
// casting to any necessary given weak type support of protocol commands
|
|
242
212
|
? this.findElementFromElement(this.elementId, using, value)
|
|
@@ -249,40 +219,56 @@ async function findElement(selector) {
|
|
|
249
219
|
const notFoundError = new Error(`Function selector "${selector.toString()}" did not return an HTMLElement`);
|
|
250
220
|
let elem = await fetchElementByJSFunction(selector, this);
|
|
251
221
|
elem = Array.isArray(elem) ? elem[0] : elem;
|
|
252
|
-
return
|
|
222
|
+
return getElementFromResponse(elem) ? elem : notFoundError;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* handle DOM element transformation
|
|
226
|
+
* Note: this runs in the browser
|
|
227
|
+
*/
|
|
228
|
+
if (isElement(selector)) {
|
|
229
|
+
if (!window.__wdio_element) {
|
|
230
|
+
window.__wdio_element = {};
|
|
231
|
+
}
|
|
232
|
+
const notFoundError = new Error('DOM Node couldn\'t be found anymore');
|
|
233
|
+
const uid = Math.random().toString().slice(2);
|
|
234
|
+
window.__wdio_element[uid] = selector;
|
|
235
|
+
selector = ((id) => window.__wdio_element[id]);
|
|
236
|
+
let elem = await fetchElementByJSFunction(selector, this, uid);
|
|
237
|
+
elem = Array.isArray(elem) ? elem[0] : elem;
|
|
238
|
+
return getElementFromResponse(elem) ? elem : notFoundError;
|
|
253
239
|
}
|
|
254
240
|
throw new Error(INVALID_SELECTOR_ERROR);
|
|
255
241
|
}
|
|
256
|
-
exports.findElement = findElement;
|
|
257
242
|
/**
|
|
258
243
|
* logic to find a elements
|
|
259
244
|
*/
|
|
260
|
-
async function findElements(selector) {
|
|
245
|
+
export async function findElements(selector) {
|
|
246
|
+
const browserObject = getBrowserObject(this);
|
|
261
247
|
/**
|
|
262
248
|
* check if shadow DOM integration is used
|
|
263
249
|
*/
|
|
264
|
-
if (!this.isDevTools && typeof selector === 'string' && selector.startsWith(
|
|
265
|
-
const elems = await
|
|
266
|
-
selector.slice(
|
|
250
|
+
if (!this.isDevTools && typeof selector === 'string' && selector.startsWith(DEEP_SELECTOR)) {
|
|
251
|
+
const elems = await browserObject.execute(locatorStrategy, ...[
|
|
252
|
+
selector.slice(DEEP_SELECTOR.length),
|
|
267
253
|
this.elementId ? this : undefined
|
|
268
254
|
].filter(Boolean));
|
|
269
255
|
const elemArray = Array.isArray(elems) ? elems : [elems];
|
|
270
|
-
return elemArray.filter((elem) => elem &&
|
|
256
|
+
return elemArray.filter((elem) => elem && getElementFromResponse(elem));
|
|
271
257
|
}
|
|
272
258
|
/**
|
|
273
259
|
* fetch elements using custom strategy function
|
|
274
260
|
*/
|
|
275
|
-
if ((
|
|
261
|
+
if (isPlainObject(selector) && typeof selector.strategy === 'function') {
|
|
276
262
|
const { strategy, strategyArguments } = selector;
|
|
277
|
-
const elems = await
|
|
263
|
+
const elems = await browserObject.execute(strategy, ...strategyArguments);
|
|
278
264
|
const elemArray = Array.isArray(elems) ? elems : [elems];
|
|
279
|
-
return elemArray.filter((elem) => elem &&
|
|
265
|
+
return elemArray.filter((elem) => elem && getElementFromResponse(elem));
|
|
280
266
|
}
|
|
281
267
|
/**
|
|
282
268
|
* fetch element using regular protocol command
|
|
283
269
|
*/
|
|
284
|
-
if (typeof selector === 'string' || (
|
|
285
|
-
const { using, value } =
|
|
270
|
+
if (typeof selector === 'string' || isPlainObject(selector)) {
|
|
271
|
+
const { using, value } = findStrategy(selector, this.isW3C, this.isMobile);
|
|
286
272
|
return this.elementId
|
|
287
273
|
// casting to any necessary given weak type support of protocol commands
|
|
288
274
|
? this.findElementsFromElement(this.elementId, using, value)
|
|
@@ -294,23 +280,22 @@ async function findElements(selector) {
|
|
|
294
280
|
if (typeof selector === 'function') {
|
|
295
281
|
const elems = await fetchElementByJSFunction(selector, this);
|
|
296
282
|
const elemArray = Array.isArray(elems) ? elems : [elems];
|
|
297
|
-
return elemArray.filter((elem) => elem &&
|
|
283
|
+
return elemArray.filter((elem) => elem && getElementFromResponse(elem));
|
|
298
284
|
}
|
|
299
285
|
throw new Error(INVALID_SELECTOR_ERROR);
|
|
300
286
|
}
|
|
301
|
-
exports.findElements = findElements;
|
|
302
287
|
/**
|
|
303
288
|
* Strip element object and return w3c and jsonwp compatible keys
|
|
304
289
|
*/
|
|
305
|
-
function verifyArgsAndStripIfElement(args) {
|
|
290
|
+
export function verifyArgsAndStripIfElement(args) {
|
|
306
291
|
function verify(arg) {
|
|
307
|
-
if ((
|
|
292
|
+
if (isObject(arg) && arg.constructor.name === 'Element') {
|
|
308
293
|
const elem = arg;
|
|
309
294
|
if (!elem.elementId) {
|
|
310
295
|
throw new Error(`The element with selector "${elem.selector}" you are trying to pass into the execute method wasn't found`);
|
|
311
296
|
}
|
|
312
297
|
return {
|
|
313
|
-
[
|
|
298
|
+
[ELEMENT_KEY]: elem.elementId,
|
|
314
299
|
ELEMENT: elem.elementId
|
|
315
300
|
};
|
|
316
301
|
}
|
|
@@ -318,11 +303,10 @@ function verifyArgsAndStripIfElement(args) {
|
|
|
318
303
|
}
|
|
319
304
|
return !Array.isArray(args) ? verify(args) : args.map(verify);
|
|
320
305
|
}
|
|
321
|
-
exports.verifyArgsAndStripIfElement = verifyArgsAndStripIfElement;
|
|
322
306
|
/**
|
|
323
307
|
* getElementRect
|
|
324
308
|
*/
|
|
325
|
-
async function getElementRect(scope) {
|
|
309
|
+
export async function getElementRect(scope) {
|
|
326
310
|
const rect = await scope.getElementRect(scope.elementId);
|
|
327
311
|
let defaults = { x: 0, y: 0, width: 0, height: 0 };
|
|
328
312
|
/**
|
|
@@ -359,31 +343,28 @@ async function getElementRect(scope) {
|
|
|
359
343
|
}
|
|
360
344
|
return rect;
|
|
361
345
|
}
|
|
362
|
-
|
|
363
|
-
function getAbsoluteFilepath(filepath) {
|
|
346
|
+
export function getAbsoluteFilepath(filepath) {
|
|
364
347
|
return filepath.startsWith('/') || filepath.startsWith('\\') || filepath.match(/^[a-zA-Z]:\\/)
|
|
365
348
|
? filepath
|
|
366
|
-
:
|
|
349
|
+
: path.join(process.cwd(), filepath);
|
|
367
350
|
}
|
|
368
|
-
exports.getAbsoluteFilepath = getAbsoluteFilepath;
|
|
369
351
|
/**
|
|
370
352
|
* check if directory exists
|
|
371
353
|
*/
|
|
372
|
-
function assertDirectoryExists(filepath) {
|
|
373
|
-
if (!
|
|
374
|
-
throw new Error(`directory (${
|
|
354
|
+
export function assertDirectoryExists(filepath) {
|
|
355
|
+
if (!fs.existsSync(path.dirname(filepath))) {
|
|
356
|
+
throw new Error(`directory (${path.dirname(filepath)}) doesn't exist`);
|
|
375
357
|
}
|
|
376
358
|
}
|
|
377
|
-
exports.assertDirectoryExists = assertDirectoryExists;
|
|
378
359
|
/**
|
|
379
360
|
* check if urls are valid and fix them if necessary
|
|
380
361
|
* @param {string} url url to navigate to
|
|
381
362
|
* @param {Boolean} [retryCheck=false] true if an url was already check and still failed with fix applied
|
|
382
363
|
* @return {string} fixed url
|
|
383
364
|
*/
|
|
384
|
-
function validateUrl(url, origError) {
|
|
365
|
+
export function validateUrl(url, origError) {
|
|
385
366
|
try {
|
|
386
|
-
const urlObject = new
|
|
367
|
+
const urlObject = new URL(url);
|
|
387
368
|
return urlObject.href;
|
|
388
369
|
}
|
|
389
370
|
catch (err) {
|
|
@@ -396,19 +377,17 @@ function validateUrl(url, origError) {
|
|
|
396
377
|
return validateUrl(`http://${url}`, new Error(`Invalid URL: ${url}`));
|
|
397
378
|
}
|
|
398
379
|
}
|
|
399
|
-
exports.validateUrl = validateUrl;
|
|
400
380
|
/**
|
|
401
381
|
* get window's scrollX and scrollY
|
|
402
382
|
* @param {object} scope
|
|
403
383
|
*/
|
|
404
|
-
function getScrollPosition(scope) {
|
|
384
|
+
export function getScrollPosition(scope) {
|
|
405
385
|
return getBrowserObject(scope)
|
|
406
386
|
.execute(/* istanbul ignore next */ function () {
|
|
407
387
|
return { scrollX: this.pageXOffset, scrollY: this.pageYOffset };
|
|
408
388
|
});
|
|
409
389
|
}
|
|
410
|
-
|
|
411
|
-
async function hasElementId(element) {
|
|
390
|
+
export async function hasElementId(element) {
|
|
412
391
|
/*
|
|
413
392
|
* This is only necessary as isDisplayed is on the exclusion list for the middleware
|
|
414
393
|
*/
|
|
@@ -426,8 +405,7 @@ async function hasElementId(element) {
|
|
|
426
405
|
}
|
|
427
406
|
return true;
|
|
428
407
|
}
|
|
429
|
-
|
|
430
|
-
function addLocatorStrategyHandler(scope) {
|
|
408
|
+
export function addLocatorStrategyHandler(scope) {
|
|
431
409
|
return (name, func) => {
|
|
432
410
|
if (scope.strategies.get(name)) {
|
|
433
411
|
throw new Error(`Strategy ${name} already exists`);
|
|
@@ -435,7 +413,6 @@ function addLocatorStrategyHandler(scope) {
|
|
|
435
413
|
scope.strategies.set(name, func);
|
|
436
414
|
};
|
|
437
415
|
}
|
|
438
|
-
exports.addLocatorStrategyHandler = addLocatorStrategyHandler;
|
|
439
416
|
/**
|
|
440
417
|
* Enhance elements array with data required to refetch it
|
|
441
418
|
* @param {object[]} elements elements
|
|
@@ -445,22 +422,25 @@ exports.addLocatorStrategyHandler = addLocatorStrategyHandler;
|
|
|
445
422
|
* @param {Array} props additional properties required to fetch elements again
|
|
446
423
|
* @returns {object[]} elements
|
|
447
424
|
*/
|
|
448
|
-
const enhanceElementsArray = (elements, parent, selector, foundWith = '$$', props = []) => {
|
|
425
|
+
export const enhanceElementsArray = (elements, parent, selector, foundWith = '$$', props = []) => {
|
|
426
|
+
/**
|
|
427
|
+
* if we have an element collection, e.g. `const elems = $$([elemA, elemB])`
|
|
428
|
+
* we cna't assign a common selector to the element array
|
|
429
|
+
*/
|
|
430
|
+
if (!Array.isArray(selector)) {
|
|
431
|
+
elements.selector = selector;
|
|
432
|
+
}
|
|
449
433
|
elements.parent = parent;
|
|
450
|
-
elements.selector = selector;
|
|
451
434
|
elements.foundWith = foundWith;
|
|
452
435
|
elements.props = props;
|
|
453
436
|
return elements;
|
|
454
437
|
};
|
|
455
|
-
exports.enhanceElementsArray = enhanceElementsArray;
|
|
456
438
|
/**
|
|
457
439
|
* is protocol stub
|
|
458
440
|
* @param {string} automationProtocol
|
|
459
441
|
*/
|
|
460
|
-
const isStub = (automationProtocol) => automationProtocol === './protocol-stub';
|
|
461
|
-
|
|
462
|
-
const getAutomationProtocol = async (config) => {
|
|
463
|
-
var _a, _b;
|
|
442
|
+
export const isStub = (automationProtocol) => automationProtocol === './protocol-stub.js';
|
|
443
|
+
export const getAutomationProtocol = async (config) => {
|
|
464
444
|
/**
|
|
465
445
|
* if automation protocol is set by user prefer this
|
|
466
446
|
*/
|
|
@@ -476,10 +456,10 @@ const getAutomationProtocol = async (config) => {
|
|
|
476
456
|
/**
|
|
477
457
|
* only run DevTools protocol if capabilities match supported platforms
|
|
478
458
|
*/
|
|
479
|
-
const caps = (
|
|
459
|
+
const caps = (config.capabilities?.alwaysMatch ||
|
|
480
460
|
config.capabilities) || {};
|
|
481
461
|
const desiredCaps = caps;
|
|
482
|
-
if (!
|
|
462
|
+
if (!SUPPORTED_BROWSER.includes(caps.browserName?.toLowerCase())) {
|
|
483
463
|
return 'webdriver';
|
|
484
464
|
}
|
|
485
465
|
/**
|
|
@@ -500,7 +480,7 @@ const getAutomationProtocol = async (config) => {
|
|
|
500
480
|
* make a head request to check if a driver is available
|
|
501
481
|
*/
|
|
502
482
|
const resp = await new Promise((resolve) => {
|
|
503
|
-
const req =
|
|
483
|
+
const req = http.request(DRIVER_DEFAULT_ENDPOINT, resolve);
|
|
504
484
|
req.on('error', (error) => resolve({ error }));
|
|
505
485
|
req.end();
|
|
506
486
|
});
|
|
@@ -516,25 +496,23 @@ const getAutomationProtocol = async (config) => {
|
|
|
516
496
|
}
|
|
517
497
|
return 'devtools';
|
|
518
498
|
};
|
|
519
|
-
exports.getAutomationProtocol = getAutomationProtocol;
|
|
520
499
|
/**
|
|
521
500
|
* updateCapabilities allows modifying capabilities before session
|
|
522
501
|
* is started
|
|
523
502
|
*
|
|
524
503
|
* NOTE: this method is executed twice when running the WDIO testrunner
|
|
525
504
|
*/
|
|
526
|
-
const updateCapabilities =
|
|
505
|
+
export const updateCapabilities = (params, automationProtocol) => {
|
|
527
506
|
if (automationProtocol && !params.automationProtocol) {
|
|
528
507
|
params.automationProtocol = automationProtocol;
|
|
529
508
|
}
|
|
530
509
|
};
|
|
531
|
-
exports.updateCapabilities = updateCapabilities;
|
|
532
510
|
/**
|
|
533
511
|
* compare if an object (`base`) contains the same values as another object (`match`)
|
|
534
512
|
* @param {object} base object to compare to
|
|
535
513
|
* @param {object} match object that needs to match thebase
|
|
536
514
|
*/
|
|
537
|
-
const containsHeaderObject = (base, match) => {
|
|
515
|
+
export const containsHeaderObject = (base, match) => {
|
|
538
516
|
for (const [key, value] of Object.entries(match)) {
|
|
539
517
|
if (typeof base[key] === 'undefined' || base[key] !== value) {
|
|
540
518
|
return false;
|
|
@@ -542,4 +520,3 @@ const containsHeaderObject = (base, match) => {
|
|
|
542
520
|
}
|
|
543
521
|
return true;
|
|
544
522
|
};
|
|
545
|
-
exports.containsHeaderObject = containsHeaderObject;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type { CDPSession } from 'puppeteer-core/lib/cjs/puppeteer/common/Connection';
|
|
3
3
|
import type Protocol from 'devtools-protocol';
|
|
4
|
-
import Interception from '.';
|
|
4
|
+
import Interception from './index.js';
|
|
5
5
|
import type { Matches, MockOverwrite, MockResponseParams } from './types';
|
|
6
6
|
declare type ClientResponse = {
|
|
7
7
|
body: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devtools.d.ts","sourceRoot":"","sources":["../../../src/utils/interception/devtools.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"devtools.d.ts","sourceRoot":"","sources":["../../../src/utils/interception/devtools.ts"],"names":[],"mappings":";AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oDAAoD,CAAA;AACpF,OAAO,KAAK,QAAQ,MAAM,mBAAmB,CAAA;AAE7C,OAAO,YAAY,MAAM,YAAY,CAAA;AACrC,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAMzE,aAAK,cAAc,GAAG;IAClB,IAAI,EAAE,MAAM,CAAA;IACZ,aAAa,CAAC,EAAE,OAAO,CAAA;CAC1B,CAAA;AAED,UAAU,WAAW;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACjB;AAED,aAAK,KAAK,GAAG;IACT,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,OAAO,GAAG;QAAE,cAAc,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAA;IACtD,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,eAAe,EAAE,WAAW,EAAE,CAAA;CACjC,CAAA;AAID,MAAM,CAAC,OAAO,OAAO,oBAAqB,SAAQ,YAAY;IAC1D,MAAM,CAAC,yBAAyB,CAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,CAAC,IAAI,GAAG,cAAc,CAAC;IA+IjI;;OAEG;IACH,IAAI,KAAK,cAER;IAED;;OAEG;IACH,KAAK;IAIL;;;OAGG;IACH,OAAO;IAKP;;;;OAIG;IACH,OAAO,CAAE,SAAS,EAAE,aAAa,EAAE,MAAM,GAAE,kBAAuB;IAIlE;;;;OAIG;IACH,WAAW,CAAE,SAAS,EAAE,aAAa,EAAE,MAAM,GAAE,kBAAuB;IAItE;;;OAGG;IACH,KAAK,CAAE,WAAW,EAAE,QAAQ,CAAC,OAAO,CAAC,WAAW,EAAE,MAAM,GAAE,OAAc;IAOxE;;;OAGG;IACH,SAAS,CAAE,WAAW,EAAE,QAAQ,CAAC,OAAO,CAAC,WAAW;CAGvD"}
|