webdriverio 5.22.1 → 5.23.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.
@@ -10,14 +10,22 @@ var _utils = require("../../utils");
10
10
  const ACTION_BUTTON = 0;
11
11
 
12
12
  async function dragAndDrop(target, duration = 100) {
13
- if (!target || target.constructor.name !== 'Element') {
13
+ if (!target || target.constructor.name !== 'Element' && (!target.x || !target.y)) {
14
14
  throw new Error('command dragAndDrop requires an WebdriverIO Element as first parameter');
15
15
  }
16
16
 
17
+ const moveToElement = target.constructor.name === 'Element';
18
+
17
19
  if (!this.isW3C) {
18
20
  await this.moveTo();
19
21
  await this.buttonDown(ACTION_BUTTON);
20
- await target.moveTo();
22
+
23
+ if (moveToElement) {
24
+ await target.moveTo();
25
+ } else {
26
+ await this.moveToElement(null, target.x, target.y);
27
+ }
28
+
21
29
  return this.buttonUp(ACTION_BUTTON);
22
30
  }
23
31
 
@@ -26,11 +34,19 @@ async function dragAndDrop(target, duration = 100) {
26
34
  scrollY
27
35
  } = await (0, _utils.getScrollPosition)(this);
28
36
  const sourceRect = await (0, _utils.getElementRect)(this);
29
- const targetRect = await (0, _utils.getElementRect)(target);
30
37
  const sourceX = parseInt(sourceRect.x - scrollX + sourceRect.width / 2, 10);
31
38
  const sourceY = parseInt(sourceRect.y - scrollY + sourceRect.height / 2, 10);
32
- const targetX = parseInt(targetRect.x - scrollX + targetRect.width / 2, 10) - sourceX;
33
- const targetY = parseInt(targetRect.y - scrollY + targetRect.height / 2, 10) - sourceY;
39
+ let targetX, targetY;
40
+
41
+ if (moveToElement) {
42
+ const targetRect = await (0, _utils.getElementRect)(target);
43
+ targetX = parseInt(targetRect.x - scrollX + targetRect.width / 2, 10) - sourceX;
44
+ targetY = parseInt(targetRect.y - scrollY + targetRect.height / 2, 10) - sourceY;
45
+ } else {
46
+ targetX = target.x;
47
+ targetY = target.y;
48
+ }
49
+
34
50
  return this.performActions([{
35
51
  type: 'pointer',
36
52
  id: 'finger1',
@@ -63,7 +63,7 @@ class MultiRemote {
63
63
  }
64
64
 
65
65
  static elementWrapper(instances, result, propertiesObject) {
66
- const prototype = _objectSpread({}, propertiesObject, {}, (0, _lodash2.default)((0, _utils2.getPrototype)('element')), {
66
+ const prototype = _objectSpread(_objectSpread(_objectSpread({}, propertiesObject), (0, _lodash2.default)((0, _utils2.getPrototype)('element'))), {}, {
67
67
  scope: 'element'
68
68
  });
69
69
 
@@ -13,14 +13,16 @@ function isElementClickable(elem) {
13
13
  const isOldEdge = !!window.StyleMedia;
14
14
  const scrollIntoViewFullSupport = !(window.safari || isOldEdge);
15
15
 
16
- function getOverlappingElement(elem, context = document) {
16
+ function getOverlappingElement(elem, context) {
17
+ context = context || document;
17
18
  const elemDimension = elem.getBoundingClientRect();
18
19
  const x = elemDimension.left + elem.clientWidth / 2;
19
20
  const y = elemDimension.top + elem.clientHeight / 2;
20
21
  return context.elementFromPoint(x, y);
21
22
  }
22
23
 
23
- function getOverlappingRects(elem, context = document) {
24
+ function getOverlappingRects(elem, context) {
25
+ context = context || document;
24
26
  const elems = [];
25
27
  const rects = elem.getClientRects();
26
28
  const rect = rects[0];
@@ -31,7 +33,7 @@ function isElementClickable(elem) {
31
33
  }
32
34
 
33
35
  function getOverlappingElements(elem, context) {
34
- return [getOverlappingElement(elem, context), ...getOverlappingRects(elem, context)];
36
+ return [getOverlappingElement(elem, context)].concat(getOverlappingRects(elem, context));
35
37
  }
36
38
 
37
39
  function nodeContains(elem, otherNode) {
@@ -57,20 +59,27 @@ function isElementClickable(elem) {
57
59
  }
58
60
 
59
61
  function isOverlappingElementMatch(elementsFromPoint, elem) {
60
- if (elementsFromPoint.some(elementFromPoint => elementFromPoint === elem || nodeContains(elem, elementFromPoint))) {
62
+ if (elementsFromPoint.some(function (elementFromPoint) {
63
+ return elementFromPoint === elem || nodeContains(elem, elementFromPoint);
64
+ })) {
61
65
  return true;
62
66
  }
63
67
 
64
- let elemsWithShadowRoot = [...new Set(elementsFromPoint)];
65
- elemsWithShadowRoot = elemsWithShadowRoot.filter(x => x && x.shadowRoot && x.shadowRoot.elementFromPoint);
68
+ let elemsWithShadowRoot = [].concat(elementsFromPoint);
69
+ elemsWithShadowRoot = elemsWithShadowRoot.filter(function (x) {
70
+ return x && x.shadowRoot && x.shadowRoot.elementFromPoint;
71
+ });
66
72
  let shadowElementsFromPoint = [];
67
73
 
68
- for (let shadowElement of elemsWithShadowRoot) {
69
- shadowElementsFromPoint.push(...getOverlappingElements(elem, shadowElement.shadowRoot));
74
+ for (let i = 0; i < elemsWithShadowRoot.length; ++i) {
75
+ let shadowElement = elemsWithShadowRoot[i];
76
+ shadowElementsFromPoint = shadowElementsFromPoint.concat(getOverlappingElements(elem, shadowElement.shadowRoot));
70
77
  }
71
78
 
72
- shadowElementsFromPoint = [...new Set(shadowElementsFromPoint)];
73
- shadowElementsFromPoint = shadowElementsFromPoint.filter(x => !elementsFromPoint.includes(x));
79
+ shadowElementsFromPoint = [].concat(shadowElementsFromPoint);
80
+ shadowElementsFromPoint = shadowElementsFromPoint.filter(function (x) {
81
+ return !elementsFromPoint.includes(x);
82
+ });
74
83
 
75
84
  if (shadowElementsFromPoint.length === 0) {
76
85
  return false;
@@ -5,6 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = newWindow;
7
7
 
8
- function newWindow(url, windowName = 'new window', windowFeatures = '') {
9
- window.open(url, windowName, windowFeatures);
8
+ function newWindow(url, windowName, windowFeatures) {
9
+ window.open(url, windowName || 'new window', windowFeatures || '');
10
10
  }
@@ -11,7 +11,9 @@ const waitToLoadReact = function waitToLoadReact() {
11
11
 
12
12
  exports.waitToLoadReact = waitToLoadReact;
13
13
 
14
- const react$ = function react$(selector, props = {}, state = {}, reactElement) {
14
+ const react$ = function react$(selector, props, state, reactElement) {
15
+ props = props || {};
16
+ state = state || {};
15
17
  let element = window.resq.resq$(selector, reactElement);
16
18
 
17
19
  if (Object.keys(props).length) {
@@ -26,7 +26,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
26
26
  const getElement = function findElement(selector, res, isReactElement = false) {
27
27
  const browser = (0, _utils2.getBrowserObject)(this);
28
28
 
29
- const propertiesObject = _objectSpread({}, (0, _lodash.default)(browser.__propertiesObject__), {}, (0, _utils2.getPrototype)('element'), {
29
+ const propertiesObject = _objectSpread(_objectSpread(_objectSpread({}, (0, _lodash.default)(browser.__propertiesObject__)), (0, _utils2.getPrototype)('element')), {}, {
30
30
  scope: 'element'
31
31
  });
32
32
 
@@ -69,7 +69,7 @@ exports.getElement = getElement;
69
69
  const getElements = function getElements(selector, elemResponse, isReactElement = false) {
70
70
  const browser = (0, _utils2.getBrowserObject)(this);
71
71
 
72
- const propertiesObject = _objectSpread({}, (0, _lodash.default)(browser.__propertiesObject__), {}, (0, _utils2.getPrototype)('element'), {
72
+ const propertiesObject = _objectSpread(_objectSpread(_objectSpread({}, (0, _lodash.default)(browser.__propertiesObject__)), (0, _utils2.getPrototype)('element')), {}, {
73
73
  scope: 'element'
74
74
  });
75
75
 
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.22.1",
4
+ "version": "5.23.0",
5
5
  "homepage": "https://webdriver.io",
6
6
  "author": "Christian Bromann <christian@saucelabs.com>",
7
7
  "license": "MIT",
@@ -56,10 +56,10 @@
56
56
  "test:unit": "jest"
57
57
  },
58
58
  "dependencies": {
59
- "@wdio/config": "5.18.4",
59
+ "@wdio/config": "5.22.4",
60
60
  "@wdio/logger": "5.16.10",
61
- "@wdio/repl": "5.18.6",
62
- "@wdio/utils": "5.18.6",
61
+ "@wdio/repl": "5.23.0",
62
+ "@wdio/utils": "5.23.0",
63
63
  "archiver": "^3.0.0",
64
64
  "css-value": "^0.0.1",
65
65
  "grapheme-splitter": "^1.0.2",
@@ -70,7 +70,7 @@
70
70
  "resq": "^1.6.0",
71
71
  "rgb2hex": "^0.1.0",
72
72
  "serialize-error": "^5.0.0",
73
- "webdriver": "5.22.1"
73
+ "webdriver": "5.23.0"
74
74
  },
75
- "gitHead": "35907149e4faa3f84e3cb4803b54606ab31b11fa"
75
+ "gitHead": "a9b8098ad18074e05a72c0458a7845a41a40aa93"
76
76
  }
@@ -195,6 +195,11 @@ declare namespace WebdriverIO {
195
195
  y?: number
196
196
  }
197
197
 
198
+ type DragAndDropCoordinate = {
199
+ x: number,
200
+ y: number
201
+ }
202
+
198
203
  interface Element {
199
204
  selector: string;
200
205
  elementId: string;
@@ -300,7 +305,7 @@ declare namespace WebdriverIO {
300
305
  * Drag an item to a destination element.
301
306
  */
302
307
  dragAndDrop(
303
- target: Element,
308
+ target: Element | DragAndDropCoordinate,
304
309
  duration?: number
305
310
  ): void;
306
311
 
@@ -585,7 +590,7 @@ declare namespace WebdriverIO {
585
590
  script?: number
586
591
  }
587
592
 
588
- interface Browser {
593
+ interface Browser extends WebDriver.BaseClient {
589
594
  config: Config;
590
595
  options: RemoteOptions;
591
596
 
@@ -195,6 +195,11 @@ declare namespace WebdriverIO {
195
195
  y?: number
196
196
  }
197
197
 
198
+ type DragAndDropCoordinate = {
199
+ x: number,
200
+ y: number
201
+ }
202
+
198
203
  interface Element {
199
204
  selector: string;
200
205
  elementId: string;
@@ -300,7 +305,7 @@ declare namespace WebdriverIO {
300
305
  * Drag an item to a destination element.
301
306
  */
302
307
  dragAndDrop(
303
- target: Element,
308
+ target: Element | DragAndDropCoordinate,
304
309
  duration?: number
305
310
  ): Promise<void>;
306
311
 
@@ -585,7 +590,7 @@ declare namespace WebdriverIO {
585
590
  script?: number
586
591
  }
587
592
 
588
- interface Browser {
593
+ interface Browser extends WebDriver.BaseClient {
589
594
  config: Config;
590
595
  options: RemoteOptions;
591
596
 
package/webdriverio.d.ts CHANGED
@@ -42,7 +42,7 @@ type ElementStatic = Pick<WebdriverIO.Element,
42
42
  >;
43
43
 
44
44
  // Browser commands that should be wrapper with Promise
45
- type BrowserPromise = Omit<WebdriverIO.Browser, 'addCommand' | 'overwriteCommand' | 'options' | 'config' | '$' | '$$' | 'touchAction'>;
45
+ type BrowserPromise = Omit<WebdriverIO.Browser, 'addCommand' | 'overwriteCommand' | 'options' | 'config' | '$' | '$$' | 'touchAction' | 'sessionId' | 'capabilities' | 'requestedCapabilities' | 'isMobile' | 'isIOS' | 'isAndroid'>;
46
46
 
47
47
  // Browser commands wrapper with Promise
48
48
  type BrowserAsync = {
@@ -72,6 +72,10 @@ declare namespace WebdriverIOAsync {
72
72
  interface TouchAction extends TouchActionSync {
73
73
  element?: Element
74
74
  }
75
+ type DragAndDropCoordinate = {
76
+ x: number,
77
+ y: number
78
+ }
75
79
  type TouchActions = string | TouchAction | TouchAction[];
76
80
  interface Browser extends BrowserAsync, BrowserStatic {
77
81
  waitUntil(
@@ -95,7 +99,7 @@ declare namespace WebdriverIOAsync {
95
99
  }
96
100
 
97
101
  interface Element extends ElementAsync, ElementStatic {
98
- dragAndDrop(target: Element, duration?: number): Promise<void>;
102
+ dragAndDrop(target: Element | DragAndDropCoordinate, duration?: number): Promise<void>;
99
103
  touchAction(action: TouchActions): Promise<void>;
100
104
  }
101
105
  interface ElementArray extends Array<Element> {
@@ -107,7 +111,7 @@ declare namespace WebdriverIOAsync {
107
111
 
108
112
  interface Config { }
109
113
 
110
- interface BrowserObject extends WebDriver.ClientOptions, WebDriver.ClientAsync, WebdriverIOAsync.Browser { }
114
+ interface BrowserObject extends WebDriver.ClientOptions, WebDriver.BaseClient, WebdriverIOAsync.Browser { }
111
115
  }
112
116
 
113
117
  declare namespace WebdriverIO {
@@ -120,4 +124,4 @@ declare var $$: $$;
120
124
 
121
125
  declare module "webdriverio" {
122
126
  export = WebdriverIOAsync
123
- }
127
+ }