webdriverio 5.12.4 → 5.13.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.
@@ -9,7 +9,13 @@ var _utils = require("../../utils");
9
9
 
10
10
  var _getElementObject = require("../../utils/getElementObject");
11
11
 
12
+ var _constants = require("../../constants");
13
+
12
14
  async function $(selector) {
15
+ if (selector && typeof selector[_constants.ELEMENT_KEY] === 'string') {
16
+ return _getElementObject.getElement.call(this, null, selector);
17
+ }
18
+
13
19
  const res = await _utils.findElement.call(this, selector);
14
20
  return _getElementObject.getElement.call(this, selector, res);
15
21
  }
@@ -19,5 +19,5 @@ async function react$$(selector, props = {}, state = {}) {
19
19
  await this.executeScript(resqScript.toString(), []);
20
20
  await this.execute(_resq.waitToLoadReact);
21
21
  const res = await this.execute(_resq.react$$, selector, props, state);
22
- return _getElementObject.getElements.call(this, selector, res);
22
+ return _getElementObject.getElements.call(this, selector, res, true);
23
23
  }
@@ -19,5 +19,5 @@ async function react$(selector, props = {}, state = {}) {
19
19
  await this.executeScript(resqScript.toString(), []);
20
20
  await this.execute(_resq.waitToLoadReact);
21
21
  const res = await this.execute(_resq.react$, selector, props, state);
22
- return _getElementObject.getElement.call(this, selector, res);
22
+ return _getElementObject.getElement.call(this, selector, res, true);
23
23
  }
@@ -5,28 +5,17 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = reloadSession;
7
7
 
8
- var _request = _interopRequireDefault(require("webdriver/build/request"));
9
-
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
8
  async function reloadSession() {
13
9
  const oldSessionId = this.sessionId;
14
10
  await this.deleteSession();
15
- const {
16
- w3cCaps,
17
- jsonwpCaps
18
- } = this.options.requestedCapabilities;
19
- const sessionRequest = new _request.default('POST', '/session', {
20
- capabilities: w3cCaps,
21
- desiredCapabilities: jsonwpCaps
22
- });
23
- const response = await sessionRequest.makeRequest(this.options);
24
- const newSessionId = response.sessionId || response.value && response.value.sessionId;
25
- this.sessionId = newSessionId;
11
+
12
+ const ProtocolDriver = require(this.options.automationProtocol).default;
13
+
14
+ await ProtocolDriver.reloadSession(this);
26
15
 
27
16
  if (Array.isArray(this.options.onReload) && this.options.onReload.length) {
28
- await Promise.all(this.options.onReload.map(hook => hook(oldSessionId, newSessionId)));
17
+ await Promise.all(this.options.onReload.map(hook => hook(oldSessionId, this.sessionId)));
29
18
  }
30
19
 
31
- return newSessionId;
20
+ return this.sessionId;
32
21
  }
@@ -9,7 +9,13 @@ var _utils = require("../../utils");
9
9
 
10
10
  var _getElementObject = require("../../utils/getElementObject");
11
11
 
12
+ var _constants = require("../../constants");
13
+
12
14
  async function $(selector) {
15
+ if (selector && typeof selector[_constants.ELEMENT_KEY] === 'string') {
16
+ return _getElementObject.getElement.call(this, null, selector);
17
+ }
18
+
13
19
  const res = await _utils.findElement.call(this, selector);
14
20
  return _getElementObject.getElement.call(this, selector, res);
15
21
  }
@@ -19,14 +19,15 @@ async function isDisplayed() {
19
19
  let browser = (0, _utils.getBrowserObject)(this);
20
20
 
21
21
  if (!this.elementId) {
22
- this.elementId = (await this.parent.$(this.selector)).elementId;
22
+ const method = this.isReactElement ? 'react$' : '$';
23
+ this.elementId = (await this.parent[method](this.selector)).elementId;
23
24
  }
24
25
 
25
26
  if (!this.elementId) {
26
27
  return false;
27
28
  }
28
29
 
29
- return browser.isW3C && !browser.isMobile && noW3CEndpoint.includes(browser.capabilities.browserName.toLowerCase()) ? await browser.execute(_isElementDisplayed.default, {
30
+ return browser.isDevTools || browser.isW3C && !browser.isMobile && noW3CEndpoint.includes(browser.capabilities.browserName.toLowerCase()) ? await browser.execute(_isElementDisplayed.default, {
30
31
  [_constants.ELEMENT_KEY]: this.elementId,
31
32
  ELEMENT: this.elementId
32
33
  }) : await this.isElementDisplayed(this.elementId);
@@ -6,5 +6,6 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = isExisting;
7
7
 
8
8
  function isExisting() {
9
- return this.parent.$$(this.selector).then(res => res.length > 0);
9
+ const method = this.isReactElement ? 'react$$' : '$$';
10
+ return this.parent[method](this.selector).then(res => res.length > 0);
10
11
  }
@@ -13,9 +13,10 @@ var _isFocused = _interopRequireDefault(require("../../scripts/isFocused"));
13
13
 
14
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
15
 
16
- function isFocused() {
17
- return (0, _utils.getBrowserObject)(this).execute(_isFocused.default, {
16
+ async function isFocused() {
17
+ const isFocused = await (0, _utils.getBrowserObject)(this).execute(_isFocused.default, {
18
18
  [_constants.ELEMENT_KEY]: this.elementId,
19
19
  ELEMENT: this.elementId
20
20
  });
21
+ return Boolean(isFocused);
21
22
  }
@@ -19,5 +19,5 @@ async function react$$(selector, props = {}, state = {}) {
19
19
  await this.executeScript(resqScript.toString(), []);
20
20
  await this.execute(_resq.waitToLoadReact);
21
21
  const res = await this.execute(_resq.react$$, selector, props, state, this);
22
- return _getElementObject.getElements.call(this, selector, res);
22
+ return _getElementObject.getElements.call(this, selector, res, true);
23
23
  }
@@ -19,5 +19,5 @@ async function react$(selector, props = {}, state = {}) {
19
19
  await this.executeScript(resqScript.toString(), []);
20
20
  await this.execute(_resq.waitToLoadReact);
21
21
  const res = await this.execute(_resq.react$, selector, props, state, this);
22
- return _getElementObject.getElement.call(this, selector, res);
22
+ return _getElementObject.getElement.call(this, selector, res, true);
23
23
  }
@@ -11,5 +11,10 @@ async function selectByAttribute(attribute, value) {
11
11
  value = typeof value === 'number' ? value.toString() : value;
12
12
  const normalized = `[normalize-space(@${attribute.trim()}) = "${value.trim()}"]`;
13
13
  const optionElement = await this.findElementFromElement(this.elementId, 'xpath', `./option${normalized}|./optgroup/option${normalized}`);
14
+
15
+ if (optionElement && optionElement.error === 'no such element') {
16
+ throw new Error(`Option with attribute "${attribute}=${value}" not found.`);
17
+ }
18
+
14
19
  return this.elementClick((0, _utils.getElementFromResponse)(optionElement));
15
20
  }
@@ -15,5 +15,10 @@ async function selectByVisibleText(text) {
15
15
  const spaceFormat = `[normalize-space(text()) = ${formatted}]`;
16
16
  const selections = [`./option${dotFormat}`, `./option${spaceFormat}`, `./optgroup/option${dotFormat}`, `./optgroup/option${spaceFormat}`];
17
17
  const optionElement = await this.findElementFromElement(this.elementId, 'xpath', selections.join('|'));
18
+
19
+ if (optionElement && optionElement.error === 'no such element') {
20
+ throw new Error(`Option with text "${text}" not found.`);
21
+ }
22
+
18
23
  return this.elementClick((0, _utils.getElementFromResponse)(optionElement));
19
24
  }
@@ -24,17 +24,33 @@ const HOOK_DEFINITION = {
24
24
  const ELEMENT_KEY = 'element-6066-11e4-a52e-4f735466cecf';
25
25
  exports.ELEMENT_KEY = ELEMENT_KEY;
26
26
  const WDIO_DEFAULTS = {
27
+ automationProtocol: {
28
+ default: 'webdriver',
29
+ type: param => {
30
+ if (typeof param !== 'string') {
31
+ throw new Error('the "automationProtocol" option needs to from type strings');
32
+ } else if (!['webdriver', 'devtools'].includes(param.toLowerCase())) {
33
+ throw new Error(`Currently only "webdriver" and "devtools" is supproted as automationProtocol, you set "${param}"`);
34
+ }
35
+
36
+ try {
37
+ require.resolve(param);
38
+ } catch (e) {
39
+ throw new Error('Automation protocol package is not installed!\n' + `Please install it via \`npm install ${param}\``);
40
+ }
41
+ }
42
+ },
27
43
  specs: {
28
44
  type: param => {
29
45
  if (!Array.isArray(param)) {
30
- throw new Error('the "specs" options needs to be a list of strings');
46
+ throw new Error('the "specs" option needs to be a list of strings');
31
47
  }
32
48
  }
33
49
  },
34
50
  exclude: {
35
51
  type: param => {
36
52
  if (!Array.isArray(param)) {
37
- throw new Error('the "exclude" options needs to be a list of strings');
53
+ throw new Error('the "exclude" option needs to be a list of strings');
38
54
  }
39
55
  }
40
56
  },
package/build/index.js CHANGED
@@ -9,6 +9,8 @@ var _path = _interopRequireDefault(require("path"));
9
9
 
10
10
  var _webdriver = _interopRequireDefault(require("webdriver"));
11
11
 
12
+ var _logger = _interopRequireDefault(require("@wdio/logger"));
13
+
12
14
  var _config = require("@wdio/config");
13
15
 
14
16
  var _multiremote = _interopRequireDefault(require("./multiremote"));
@@ -19,6 +21,8 @@ var _utils = require("./utils");
19
21
 
20
22
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
23
 
24
+ const log = (0, _logger.default)('webdriverio');
25
+
22
26
  const remote = async function (params = {}, remoteModifier) {
23
27
  const config = (0, _config.validateConfig)(_constants.WDIO_DEFAULTS, params);
24
28
 
@@ -40,14 +44,22 @@ const remote = async function (params = {}, remoteModifier) {
40
44
  }
41
45
 
42
46
  const prototype = (0, _utils.getPrototype)('browser');
43
- const instance = await _webdriver.default.newSession(params, modifier, prototype, _config.wrapCommand);
44
- const origAddCommand = instance.addCommand.bind(instance);
47
+ log.info(`Initiate new session using the ${config.automationProtocol} protocol`);
48
+
49
+ const ProtocolDriver = require(config.automationProtocol).default;
50
+
51
+ const commandWrapper = params.runner ? _config.wrapCommand : (_, origFn) => origFn;
52
+ const instance = await ProtocolDriver.newSession(params, modifier, prototype, commandWrapper);
53
+
54
+ if (params.runner) {
55
+ const origAddCommand = instance.addCommand.bind(instance);
45
56
 
46
- instance.addCommand = (name, fn, attachToElement) => origAddCommand(name, (0, _config.runFnInFiberContext)(fn), attachToElement);
57
+ instance.addCommand = (name, fn, attachToElement) => origAddCommand(name, (0, _config.runFnInFiberContext)(fn), attachToElement);
47
58
 
48
- const origOverwriteCommand = instance.overwriteCommand.bind(instance);
59
+ const origOverwriteCommand = instance.overwriteCommand.bind(instance);
49
60
 
50
- instance.overwriteCommand = (name, fn, attachToElement) => origOverwriteCommand(name, (0, _config.runFnInFiberContext)(fn), attachToElement);
61
+ instance.overwriteCommand = (name, fn, attachToElement) => origOverwriteCommand(name, (0, _config.runFnInFiberContext)(fn), attachToElement);
62
+ }
51
63
 
52
64
  return instance;
53
65
  };
@@ -64,18 +76,8 @@ exports.attach = attach;
64
76
  const multiremote = async function (params = {}) {
65
77
  const multibrowser = new _multiremote.default();
66
78
  const browserNames = Object.keys(params);
67
- await Promise.all(browserNames.map(browserName => {
68
- const config = (0, _config.validateConfig)(_constants.WDIO_DEFAULTS, params[browserName]);
69
-
70
- const modifier = (client, options) => {
71
- Object.assign(options, config);
72
- return client;
73
- };
74
-
75
- const prototype = (0, _utils.getPrototype)('browser');
76
-
77
- const instance = _webdriver.default.newSession(params[browserName], modifier, prototype, _config.wrapCommand);
78
-
79
+ await Promise.all(browserNames.map(async browserName => {
80
+ const instance = await remote(params[browserName]);
79
81
  return multibrowser.addInstance(browserName, instance);
80
82
  }));
81
83
  const prototype = (0, _utils.getPrototype)('browser');
@@ -9,13 +9,13 @@ var _lodash = _interopRequireDefault(require("lodash.zip"));
9
9
 
10
10
  var _lodash2 = _interopRequireDefault(require("lodash.clonedeep"));
11
11
 
12
- var _webdriver = require("webdriver");
12
+ var _utils = require("@wdio/utils");
13
13
 
14
14
  var _config = require("@wdio/config");
15
15
 
16
16
  var _middlewares = require("./middlewares");
17
17
 
18
- var _utils = require("./utils");
18
+ var _utils2 = require("./utils");
19
19
 
20
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
21
 
@@ -65,11 +65,11 @@ class MultiRemote {
65
65
  }
66
66
 
67
67
  static elementWrapper(instances, result, propertiesObject) {
68
- const prototype = _objectSpread({}, propertiesObject, {}, (0, _lodash2.default)((0, _utils.getPrototype)('element')), {
68
+ const prototype = _objectSpread({}, propertiesObject, {}, (0, _lodash2.default)((0, _utils2.getPrototype)('element')), {
69
69
  scope: 'element'
70
70
  });
71
71
 
72
- const element = (0, _webdriver.webdriverMonad)({}, client => {
72
+ const element = (0, _utils.webdriverMonad)({}, client => {
73
73
  for (const [i, identifier] of Object.entries(Object.keys(instances))) {
74
74
  client[identifier] = result[i];
75
75
  }
@@ -5,13 +5,13 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.getElements = exports.getElement = void 0;
7
7
 
8
- var _webdriver = require("webdriver");
8
+ var _utils = require("@wdio/utils");
9
9
 
10
10
  var _config = require("@wdio/config");
11
11
 
12
12
  var _lodash = _interopRequireDefault(require("lodash.clonedeep"));
13
13
 
14
- var _utils = require("../utils");
14
+ var _utils2 = require("../utils");
15
15
 
16
16
  var _middlewares = require("../middlewares");
17
17
 
@@ -25,15 +25,15 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
25
25
 
26
26
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
27
27
 
28
- const getElement = function findElement(selector, res) {
29
- const browser = (0, _utils.getBrowserObject)(this);
28
+ const getElement = function findElement(selector, res, isReactElement = false) {
29
+ const browser = (0, _utils2.getBrowserObject)(this);
30
30
 
31
- const prototype = _objectSpread({}, (0, _lodash.default)(browser.__propertiesObject__), {}, (0, _utils.getPrototype)('element'), {
31
+ const prototype = _objectSpread({}, (0, _lodash.default)(browser.__propertiesObject__), {}, (0, _utils2.getPrototype)('element'), {
32
32
  scope: 'element'
33
33
  });
34
34
 
35
- const element = (0, _webdriver.webdriverMonad)(this.options, client => {
36
- const elementId = (0, _utils.getElementFromResponse)(res);
35
+ const element = (0, _utils.webdriverMonad)(this.options, client => {
36
+ const elementId = (0, _utils2.getElementFromResponse)(res);
37
37
 
38
38
  if (elementId) {
39
39
  client.elementId = elementId;
@@ -50,6 +50,7 @@ const getElement = function findElement(selector, res) {
50
50
  client.selector = selector;
51
51
  client.parent = this;
52
52
  client.emit = this.emit.bind(this);
53
+ client.isReactElement = isReactElement;
53
54
  return client;
54
55
  }, prototype);
55
56
  const elementInstance = element(this.sessionId, (0, _middlewares.elementErrorHandler)(_config.wrapCommand));
@@ -67,11 +68,11 @@ const getElement = function findElement(selector, res) {
67
68
 
68
69
  exports.getElement = getElement;
69
70
 
70
- const getElements = function getElements(selector, res) {
71
- const browser = (0, _utils.getBrowserObject)(this);
71
+ const getElements = function getElements(selector, res, isReactElement = false) {
72
+ const browser = (0, _utils2.getBrowserObject)(this);
72
73
  const elements = res.map((res, i) => {
73
- const element = (0, _webdriver.webdriverMonad)(this.options, client => {
74
- const elementId = (0, _utils.getElementFromResponse)(res);
74
+ const element = (0, _utils.webdriverMonad)(this.options, client => {
75
+ const elementId = (0, _utils2.getElementFromResponse)(res);
75
76
 
76
77
  if (elementId) {
77
78
  client.elementId = elementId;
@@ -89,8 +90,9 @@ const getElements = function getElements(selector, res) {
89
90
  client.parent = this;
90
91
  client.index = i;
91
92
  client.emit = this.emit.bind(this);
93
+ client.isReactElement = isReactElement;
92
94
  return client;
93
- }, _objectSpread({}, (0, _lodash.default)(browser.__propertiesObject__), {}, (0, _utils.getPrototype)('element'), {
95
+ }, _objectSpread({}, (0, _lodash.default)(browser.__propertiesObject__), {}, (0, _utils2.getPrototype)('element'), {
94
96
  scope: 'element'
95
97
  }));
96
98
  const elementInstance = element(this.sessionId, (0, _middlewares.elementErrorHandler)(_config.wrapCommand));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "webdriverio",
3
3
  "description": "Next-gen WebDriver test automation framework for Node.js",
4
- "version": "5.12.4",
4
+ "version": "5.13.1",
5
5
  "homepage": "https://webdriver.io",
6
6
  "author": "Christian Bromann <christian@saucelabs.com>",
7
7
  "license": "MIT",
@@ -45,7 +45,7 @@
45
45
  "testingbot"
46
46
  ],
47
47
  "types": "./webdriverio.d.ts",
48
- "typeScriptVersion": "3.2.1",
48
+ "typeScriptVersion": "3.5.1",
49
49
  "scripts": {
50
50
  "build": "run-s clean compile",
51
51
  "clean": "rimraf ./build",
@@ -55,9 +55,10 @@
55
55
  "test:unit": "jest"
56
56
  },
57
57
  "dependencies": {
58
- "@wdio/config": "^5.12.1",
58
+ "@wdio/config": "^5.13.0-alpha.0",
59
59
  "@wdio/logger": "^5.12.1",
60
- "@wdio/repl": "^5.12.1",
60
+ "@wdio/repl": "^5.13.0-alpha.0",
61
+ "@wdio/utils": "^5.13.0",
61
62
  "archiver": "^3.0.0",
62
63
  "css-value": "^0.0.1",
63
64
  "grapheme-splitter": "^1.0.2",
@@ -68,7 +69,7 @@
68
69
  "resq": "^1.6.0",
69
70
  "rgb2hex": "^0.1.0",
70
71
  "serialize-error": "^4.1.0",
71
- "webdriver": "^5.12.1"
72
+ "webdriver": "^5.13.1"
72
73
  },
73
- "gitHead": "3786d36b4ad1cf79e3759ccdcb8414fb9d166d6a"
74
+ "gitHead": "545fdcc3ca20842417ca17b490df2546b0806922"
74
75
  }
@@ -291,7 +291,7 @@ declare namespace WebdriverIO {
291
291
  selector: string | Function
292
292
  ): Element[];
293
293
  $(
294
- selector: string | Function
294
+ selector: string | Function | object
295
295
  ): Element;
296
296
  debug(): void;
297
297
  deleteCookies(