expect-webdriverio 3.4.0 → 3.5.1

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.
@@ -3,8 +3,9 @@ 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 browser = (0, utils_1.getBrowserObject)(received);
8
9
  return browser.call(async () => {
9
10
  const result = await utils_1.executeCommandBe.call(this, received, async (el) => {
10
11
  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
+ received = await received;
9
+ const browser = (0, utils_1.getBrowserObject)(received);
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
+ received = await received;
9
+ const browser = (0, utils_1.getBrowserObject)(received);
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,9 @@ 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 browser = (0, utils_1.getBrowserObject)(received);
8
9
  return browser.call(async () => {
9
10
  const result = await utils_1.executeCommandBe.call(this, received, async (el) => {
10
11
  try {
@@ -3,8 +3,9 @@ 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 browser = (0, utils_1.getBrowserObject)(received);
8
9
  return browser.call(async () => {
9
10
  const result = await utils_1.executeCommandBe.call(this, received, el => el.isEnabled(), options);
10
11
  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
+ received = await received;
10
+ const browser = (0, utils_1.getBrowserObject)(received);
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,9 @@ 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 browser = (0, utils_1.getBrowserObject)(received);
8
9
  return browser.call(async () => {
9
10
  const result = await utils_1.executeCommandBe.call(this, received, el => el.isFocused(), options);
10
11
  return result;
@@ -3,8 +3,9 @@ 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 browser = (0, utils_1.getBrowserObject)(received);
8
9
  return browser.call(async () => {
9
10
  const result = await utils_1.executeCommandBe.call(this, received, el => el.isSelected(), options);
10
11
  return result;
@@ -19,9 +19,10 @@ 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 browser = (0, utils_1.getBrowserObject)(received);
25
26
  return browser.call(async () => {
26
27
  let el = await received;
27
28
  let attr;
@@ -41,9 +42,10 @@ function toHaveAttributeAndValueFn(received, attribute, value, options = {}) {
41
42
  });
42
43
  }
43
44
  exports.toHaveAttributeAndValueFn = toHaveAttributeAndValueFn;
44
- function toHaveAttributeFn(received, attribute) {
45
+ async function toHaveAttributeFn(received, attribute) {
45
46
  const isNot = this.isNot;
46
47
  const { expectation = 'attribute', verb = 'have' } = this;
48
+ const browser = (0, utils_1.getBrowserObject)(received);
47
49
  return browser.call(async () => {
48
50
  let el = await received;
49
51
  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,7 @@ function toHaveChildrenFn(received, expected, options = {}) {
28
28
  else if (typeof expected === 'object') {
29
29
  numberOptions = expected;
30
30
  }
31
+ const browser = (0, utils_1.getBrowserObject)(received);
31
32
  return browser.call(async () => {
32
33
  let el = await received;
33
34
  let children;
@@ -27,10 +27,11 @@ 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 browser = (0, utils_1.getBrowserObject)(received);
34
35
  return browser.call(async () => {
35
36
  let el = await received;
36
37
  let attr;
@@ -18,9 +18,10 @@ 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 browser = (0, utils_1.getBrowserObject)(received);
24
25
  return browser.call(async () => {
25
26
  let el = await received;
26
27
  let prop;
@@ -6,9 +6,10 @@ 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 browser = (0, utils_1.getBrowserObject)(received);
12
13
  return browser.call(async () => {
13
14
  let el = await received;
14
15
  let actualStyle;
@@ -10,9 +10,10 @@ 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 browser = (0, utils_1.getBrowserObject)(received);
16
17
  return browser.call(async () => {
17
18
  let el = await received;
18
19
  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,7 @@ function toBeElementsArrayOfSizeFn(received, expected, options = {}) {
17
17
  else {
18
18
  numberOptions = expected;
19
19
  }
20
+ const browser = (0, utils_1.getBrowserObject)(received);
20
21
  return browser.call(async () => {
21
22
  let elements = await received;
22
23
  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.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
- await browser.waitUntil(async () => {
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
- return isNot !== await condition();
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
- return false;
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,8 @@ 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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expect-webdriverio",
3
- "version": "3.4.0",
3
+ "version": "3.5.1",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {