expect-webdriverio 3.4.0 → 3.5.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/lib/matchers/element/toBeClickable.js +3 -1
- package/lib/matchers/element/toBeDisabled.js +3 -1
- package/lib/matchers/element/toBeDisplayed.js +3 -1
- package/lib/matchers/element/toBeDisplayedInViewport.js +3 -1
- package/lib/matchers/element/toBeEnabled.js +3 -1
- package/lib/matchers/element/toBeExisting.js +3 -1
- package/lib/matchers/element/toBeFocused.js +3 -1
- package/lib/matchers/element/toBeSelected.js +3 -1
- package/lib/matchers/element/toHaveAttribute.js +6 -2
- package/lib/matchers/element/toHaveChildren.js +3 -1
- package/lib/matchers/element/toHaveElementClass.js +3 -1
- package/lib/matchers/element/toHaveElementProperty.js +3 -1
- package/lib/matchers/element/toHaveStyle.js +3 -1
- package/lib/matchers/element/toHaveText.js +3 -1
- package/lib/matchers/elements/toBeElementsArrayOfSize.js +3 -1
- package/lib/matchers/mock/toBeRequestedTimes.js +1 -1
- package/lib/matchers/mock/toBeRequestedWith.js +1 -1
- package/lib/utils.js +24 -8
- package/package.json +1 -1
|
@@ -3,8 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.toBeClickable = void 0;
|
|
4
4
|
const utils_1 = require("../../utils");
|
|
5
5
|
const expectAdapter_1 = require("../../util/expectAdapter");
|
|
6
|
-
function toBeClickableFn(received, options = {}) {
|
|
6
|
+
async function toBeClickableFn(received, options = {}) {
|
|
7
7
|
this.expectation = this.expectation || 'clickable';
|
|
8
|
+
const el = await (0, utils_1.getFirstElement)(received);
|
|
9
|
+
const browser = (0, utils_1.getBrowserObject)(el);
|
|
8
10
|
return browser.call(async () => {
|
|
9
11
|
const result = await utils_1.executeCommandBe.call(this, received, async (el) => {
|
|
10
12
|
try {
|
|
@@ -3,8 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.toBeDisabled = void 0;
|
|
4
4
|
const utils_1 = require("../../utils");
|
|
5
5
|
const expectAdapter_1 = require("../../util/expectAdapter");
|
|
6
|
-
function toBeDisabledFn(received, options = {}) {
|
|
6
|
+
async function toBeDisabledFn(received, options = {}) {
|
|
7
7
|
this.expectation = this.expectation || 'disabled';
|
|
8
|
+
const el = await (0, utils_1.getFirstElement)(received);
|
|
9
|
+
const browser = (0, utils_1.getBrowserObject)(el);
|
|
8
10
|
return browser.call(async () => {
|
|
9
11
|
const result = await utils_1.executeCommandBe.call(this, received, async (el) => !await el.isEnabled(), options);
|
|
10
12
|
return result;
|
|
@@ -3,8 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.toBeDisplayed = void 0;
|
|
4
4
|
const utils_1 = require("../../utils");
|
|
5
5
|
const expectAdapter_1 = require("../../util/expectAdapter");
|
|
6
|
-
function toBeDisplayedFn(received, options = {}) {
|
|
6
|
+
async function toBeDisplayedFn(received, options = {}) {
|
|
7
7
|
this.expectation = this.expectation || 'displayed';
|
|
8
|
+
const el = await (0, utils_1.getFirstElement)(received);
|
|
9
|
+
const browser = (0, utils_1.getBrowserObject)(el);
|
|
8
10
|
return browser.call(async () => {
|
|
9
11
|
const result = await utils_1.executeCommandBe.call(this, received, async (el) => {
|
|
10
12
|
try {
|
|
@@ -3,8 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.toBeDisplayedInViewport = void 0;
|
|
4
4
|
const utils_1 = require("../../utils");
|
|
5
5
|
const expectAdapter_1 = require("../../util/expectAdapter");
|
|
6
|
-
function toBeDisplayedInViewportFn(received, options = {}) {
|
|
6
|
+
async function toBeDisplayedInViewportFn(received, options = {}) {
|
|
7
7
|
this.expectation = this.expectation || 'displayed in viewport';
|
|
8
|
+
const el = await (0, utils_1.getFirstElement)(received);
|
|
9
|
+
const browser = (0, utils_1.getBrowserObject)(el);
|
|
8
10
|
return browser.call(async () => {
|
|
9
11
|
const result = await utils_1.executeCommandBe.call(this, received, async (el) => {
|
|
10
12
|
try {
|
|
@@ -3,8 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.toBeEnabled = void 0;
|
|
4
4
|
const utils_1 = require("../../utils");
|
|
5
5
|
const expectAdapter_1 = require("../../util/expectAdapter");
|
|
6
|
-
function toBeEnabledFn(received, options = {}) {
|
|
6
|
+
async function toBeEnabledFn(received, options = {}) {
|
|
7
7
|
this.expectation = this.expectation || 'enabled';
|
|
8
|
+
const el = await (0, utils_1.getFirstElement)(received);
|
|
9
|
+
const browser = (0, utils_1.getBrowserObject)(el);
|
|
8
10
|
return browser.call(async () => {
|
|
9
11
|
const result = await utils_1.executeCommandBe.call(this, received, el => el.isEnabled(), options);
|
|
10
12
|
return result;
|
|
@@ -3,9 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.toBePresent = exports.toBeExisting = exports.toExist = void 0;
|
|
4
4
|
const utils_1 = require("../../utils");
|
|
5
5
|
const expectAdapter_1 = require("../../util/expectAdapter");
|
|
6
|
-
function toExistFn(received, options = {}) {
|
|
6
|
+
async function toExistFn(received, options = {}) {
|
|
7
7
|
this.expectation = this.expectation || 'exist';
|
|
8
8
|
this.verb = this.verb || '';
|
|
9
|
+
const el = await (0, utils_1.getFirstElement)(received);
|
|
10
|
+
const browser = (0, utils_1.getBrowserObject)(el);
|
|
9
11
|
return browser.call(async () => {
|
|
10
12
|
const result = await utils_1.executeCommandBe.call(this, received, async (el) => {
|
|
11
13
|
try {
|
|
@@ -3,8 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.toBeFocused = void 0;
|
|
4
4
|
const utils_1 = require("../../utils");
|
|
5
5
|
const expectAdapter_1 = require("../../util/expectAdapter");
|
|
6
|
-
function toBeFocusedFn(received, options = {}) {
|
|
6
|
+
async function toBeFocusedFn(received, options = {}) {
|
|
7
7
|
this.expectation = this.expectation || 'focused';
|
|
8
|
+
const el = await (0, utils_1.getFirstElement)(received);
|
|
9
|
+
const browser = (0, utils_1.getBrowserObject)(el);
|
|
8
10
|
return browser.call(async () => {
|
|
9
11
|
const result = await utils_1.executeCommandBe.call(this, received, el => el.isFocused(), options);
|
|
10
12
|
return result;
|
|
@@ -3,8 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.toBeChecked = exports.toBeSelected = void 0;
|
|
4
4
|
const utils_1 = require("../../utils");
|
|
5
5
|
const expectAdapter_1 = require("../../util/expectAdapter");
|
|
6
|
-
function toBeSelectedFn(received, options = {}) {
|
|
6
|
+
async function toBeSelectedFn(received, options = {}) {
|
|
7
7
|
this.expectation = this.expectation || 'selected';
|
|
8
|
+
const el = await (0, utils_1.getFirstElement)(received);
|
|
9
|
+
const browser = (0, utils_1.getBrowserObject)(el);
|
|
8
10
|
return browser.call(async () => {
|
|
9
11
|
const result = await utils_1.executeCommandBe.call(this, received, el => el.isSelected(), options);
|
|
10
12
|
return result;
|
|
@@ -19,9 +19,11 @@ async function conditionAttrAndValue(el, attribute, value, options) {
|
|
|
19
19
|
}
|
|
20
20
|
return (0, utils_1.compareText)(attr, value, options);
|
|
21
21
|
}
|
|
22
|
-
function toHaveAttributeAndValueFn(received, attribute, value, options = {}) {
|
|
22
|
+
async function toHaveAttributeAndValueFn(received, attribute, value, options = {}) {
|
|
23
23
|
const isNot = this.isNot;
|
|
24
24
|
const { expectation = 'attribute', verb = 'have' } = this;
|
|
25
|
+
const el = await (0, utils_1.getFirstElement)(received);
|
|
26
|
+
const browser = (0, utils_1.getBrowserObject)(el);
|
|
25
27
|
return browser.call(async () => {
|
|
26
28
|
let el = await received;
|
|
27
29
|
let attr;
|
|
@@ -41,9 +43,11 @@ function toHaveAttributeAndValueFn(received, attribute, value, options = {}) {
|
|
|
41
43
|
});
|
|
42
44
|
}
|
|
43
45
|
exports.toHaveAttributeAndValueFn = toHaveAttributeAndValueFn;
|
|
44
|
-
function toHaveAttributeFn(received, attribute) {
|
|
46
|
+
async function toHaveAttributeFn(received, attribute) {
|
|
45
47
|
const isNot = this.isNot;
|
|
46
48
|
const { expectation = 'attribute', verb = 'have' } = this;
|
|
49
|
+
const el = await (0, utils_1.getFirstElement)(received);
|
|
50
|
+
const browser = (0, utils_1.getBrowserObject)(el);
|
|
47
51
|
return browser.call(async () => {
|
|
48
52
|
let el = await received;
|
|
49
53
|
const pass = await (0, utils_1.waitUntil)(async () => {
|
|
@@ -18,7 +18,7 @@ async function condition(el, options) {
|
|
|
18
18
|
value: children === null || children === void 0 ? void 0 : children.length
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
|
-
function toHaveChildrenFn(received, expected, options = {}) {
|
|
21
|
+
async function toHaveChildrenFn(received, expected, options = {}) {
|
|
22
22
|
const isNot = this.isNot;
|
|
23
23
|
const { expectation = 'children', verb = 'have' } = this;
|
|
24
24
|
let numberOptions;
|
|
@@ -28,6 +28,8 @@ function toHaveChildrenFn(received, expected, options = {}) {
|
|
|
28
28
|
else if (typeof expected === 'object') {
|
|
29
29
|
numberOptions = expected;
|
|
30
30
|
}
|
|
31
|
+
const el = await (0, utils_1.getFirstElement)(received);
|
|
32
|
+
const browser = (0, utils_1.getBrowserObject)(el);
|
|
31
33
|
return browser.call(async () => {
|
|
32
34
|
let el = await received;
|
|
33
35
|
let children;
|
|
@@ -27,10 +27,12 @@ async function condition(el, attribute, value, options) {
|
|
|
27
27
|
result: valueInClasses
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
|
-
function toHaveElementClassFn(received, className, options = {}) {
|
|
30
|
+
async function toHaveElementClassFn(received, className, options = {}) {
|
|
31
31
|
const isNot = this.isNot;
|
|
32
32
|
const { expectation = 'class', verb = 'have' } = this;
|
|
33
33
|
const attribute = 'class';
|
|
34
|
+
const el = await (0, utils_1.getFirstElement)(received);
|
|
35
|
+
const browser = (0, utils_1.getBrowserObject)(el);
|
|
34
36
|
return browser.call(async () => {
|
|
35
37
|
let el = await received;
|
|
36
38
|
let attr;
|
|
@@ -18,9 +18,11 @@ async function condition(el, property, value, options = {}) {
|
|
|
18
18
|
prop = prop.toString();
|
|
19
19
|
return (0, utils_1.compareText)(prop, value, options);
|
|
20
20
|
}
|
|
21
|
-
function toHaveElementPropertyFn(received, property, value, options = {}) {
|
|
21
|
+
async function toHaveElementPropertyFn(received, property, value, options = {}) {
|
|
22
22
|
const isNot = this.isNot;
|
|
23
23
|
const { expectation = 'property', verb = 'have' } = this;
|
|
24
|
+
const el = await (0, utils_1.getFirstElement)(received);
|
|
25
|
+
const browser = (0, utils_1.getBrowserObject)(el);
|
|
24
26
|
return browser.call(async () => {
|
|
25
27
|
let el = await received;
|
|
26
28
|
let prop;
|
|
@@ -6,9 +6,11 @@ const expectAdapter_1 = require("../../util/expectAdapter");
|
|
|
6
6
|
async function condition(el, style, options) {
|
|
7
7
|
return (0, utils_1.compareStyle)(el, style, options);
|
|
8
8
|
}
|
|
9
|
-
function toHaveStyleFn(received, style, options = {}) {
|
|
9
|
+
async function toHaveStyleFn(received, style, options = {}) {
|
|
10
10
|
const isNot = this.isNot;
|
|
11
11
|
const { expectation = 'style', verb = 'have' } = this;
|
|
12
|
+
const el = await (0, utils_1.getFirstElement)(received);
|
|
13
|
+
const browser = (0, utils_1.getBrowserObject)(el);
|
|
12
14
|
return browser.call(async () => {
|
|
13
15
|
let el = await received;
|
|
14
16
|
let actualStyle;
|
|
@@ -10,9 +10,11 @@ async function condition(el, text, options) {
|
|
|
10
10
|
}
|
|
11
11
|
return (0, utils_1.compareText)(actualText, text, options);
|
|
12
12
|
}
|
|
13
|
-
function toHaveTextFn(received, text, options = {}) {
|
|
13
|
+
async function toHaveTextFn(received, text, options = {}) {
|
|
14
14
|
const isNot = this.isNot;
|
|
15
15
|
const { expectation = 'text', verb = 'have' } = this;
|
|
16
|
+
const el = await (0, utils_1.getFirstElement)(received);
|
|
17
|
+
const browser = (0, utils_1.getBrowserObject)(el);
|
|
16
18
|
return browser.call(async () => {
|
|
17
19
|
let el = await received;
|
|
18
20
|
let actualText;
|
|
@@ -4,7 +4,7 @@ exports.toBeElementsArrayOfSize = void 0;
|
|
|
4
4
|
const utils_1 = require("../../utils");
|
|
5
5
|
const refetchElements_1 = require("../../util/refetchElements");
|
|
6
6
|
const expectAdapter_1 = require("../../util/expectAdapter");
|
|
7
|
-
function toBeElementsArrayOfSizeFn(received, expected, options = {}) {
|
|
7
|
+
async function toBeElementsArrayOfSizeFn(received, expected, options = {}) {
|
|
8
8
|
const isNot = this.isNot;
|
|
9
9
|
const { expectation = 'elements array of size', verb = 'be' } = this;
|
|
10
10
|
let numberOptions;
|
|
@@ -17,6 +17,8 @@ function toBeElementsArrayOfSizeFn(received, expected, options = {}) {
|
|
|
17
17
|
else {
|
|
18
18
|
numberOptions = expected;
|
|
19
19
|
}
|
|
20
|
+
const el = await (0, utils_1.getFirstElement)(received);
|
|
21
|
+
const browser = (0, utils_1.getBrowserObject)(el);
|
|
20
22
|
return browser.call(async () => {
|
|
21
23
|
let elements = await received;
|
|
22
24
|
const arrLength = elements.length;
|
|
@@ -14,7 +14,7 @@ function toBeRequestedTimesFn(received, expected = {}, options = {}) {
|
|
|
14
14
|
else if (typeof expected === 'object') {
|
|
15
15
|
numberOptions = expected;
|
|
16
16
|
}
|
|
17
|
-
return browser.call(async () => {
|
|
17
|
+
return received.browser.call(async () => {
|
|
18
18
|
let actual;
|
|
19
19
|
const pass = await (0, utils_1.waitUntil)(async () => {
|
|
20
20
|
actual = received.calls.length;
|
|
@@ -9,7 +9,7 @@ const KEY_LIMIT = 12;
|
|
|
9
9
|
function toBeRequestedWithFn(received, requestedWith = {}, options = {}) {
|
|
10
10
|
const isNot = this.isNot || false;
|
|
11
11
|
const { expectation = 'called with', verb = 'be' } = this;
|
|
12
|
-
return browser.call(async () => {
|
|
12
|
+
return received.browser.call(async () => {
|
|
13
13
|
let actual;
|
|
14
14
|
const pass = await (0, utils_1.waitUntil)(async () => {
|
|
15
15
|
for (const call of received.calls) {
|
package/lib/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.aliasFn = exports.compareNumbers = exports.waitUntil = exports.executeCommandBe = exports.executeCommand = exports.numberError = exports.enhanceError = exports.wrapExpectedWithArray = exports.updateElementsArray = exports.compareStyle = exports.compareTextWithArray = exports.compareText = void 0;
|
|
3
|
+
exports.getFirstElement = exports.getBrowserObject = exports.aliasFn = exports.compareNumbers = exports.waitUntil = exports.executeCommandBe = exports.executeCommand = exports.numberError = exports.enhanceError = exports.wrapExpectedWithArray = exports.updateElementsArray = exports.compareStyle = exports.compareTextWithArray = exports.compareText = void 0;
|
|
4
4
|
const options_1 = require("./options");
|
|
5
5
|
const executeCommand_1 = require("./util/executeCommand");
|
|
6
6
|
Object.defineProperty(exports, "executeCommand", { enumerable: true, get: function () { return executeCommand_1.executeCommand; } });
|
|
@@ -13,25 +13,31 @@ Object.defineProperty(exports, "numberError", { enumerable: true, get: function
|
|
|
13
13
|
const expectAdapter_1 = require("./util/expectAdapter");
|
|
14
14
|
const config = (0, options_1.getConfig)();
|
|
15
15
|
const { options: DEFAULT_OPTIONS } = config;
|
|
16
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
16
17
|
const waitUntil = async (condition, isNot = false, { wait = DEFAULT_OPTIONS.wait, interval = DEFAULT_OPTIONS.interval } = {}) => {
|
|
17
18
|
if (wait === 0) {
|
|
18
19
|
return await condition();
|
|
19
20
|
}
|
|
20
21
|
try {
|
|
21
22
|
let error;
|
|
22
|
-
|
|
23
|
+
const start = Date.now();
|
|
24
|
+
while (true) {
|
|
25
|
+
if ((Date.now() - start) > wait) {
|
|
26
|
+
throw new Error('timeout');
|
|
27
|
+
}
|
|
23
28
|
error = undefined;
|
|
24
29
|
try {
|
|
25
|
-
|
|
30
|
+
const result = isNot !== await condition();
|
|
31
|
+
if (result) {
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
await sleep(interval);
|
|
26
35
|
}
|
|
27
36
|
catch (err) {
|
|
28
37
|
error = err;
|
|
29
|
-
|
|
38
|
+
await sleep(interval);
|
|
30
39
|
}
|
|
31
|
-
}
|
|
32
|
-
timeout: wait,
|
|
33
|
-
interval
|
|
34
|
-
});
|
|
40
|
+
}
|
|
35
41
|
if (error) {
|
|
36
42
|
throw error;
|
|
37
43
|
}
|
|
@@ -163,3 +169,13 @@ function aliasFn(fn, { verb, expectation } = {}, ...args) {
|
|
|
163
169
|
return fn.apply(context, args);
|
|
164
170
|
}
|
|
165
171
|
exports.aliasFn = aliasFn;
|
|
172
|
+
function getBrowserObject(elem) {
|
|
173
|
+
const elemObject = elem;
|
|
174
|
+
return elemObject.parent ? getBrowserObject(elemObject.parent) : elem;
|
|
175
|
+
}
|
|
176
|
+
exports.getBrowserObject = getBrowserObject;
|
|
177
|
+
async function getFirstElement(received) {
|
|
178
|
+
received = await received;
|
|
179
|
+
return Array.isArray(received) ? received[0] : received;
|
|
180
|
+
}
|
|
181
|
+
exports.getFirstElement = getFirstElement;
|