Skip to content

Commit

Permalink
fix: tap on first element in click command
Browse files Browse the repository at this point in the history
  • Loading branch information
rostik404 committed Sep 22, 2021
1 parent bf89d48 commit 0de9018
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/command-helpers/element-utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ exports.getWebViewSize = async (browser) => {
exports.getElemCoords = async (browser, selector) => {
const [size, location] = await Promise.all([browser.getElementSize(selector), browser.getLocation(selector)]);
const {width, height} = _.isArray(size) ? size[0] : size;
const {x, y} = _.isArray(location) ? location[0] : location;
// wdio returns elements in reverse order, so we need to take the last element in the array to pick first element on the page
// https://github.com/webdriverio/webdriverio/blob/v4.14.1/lib/commands/getLocation.js#L48.
const {x, y} = _.isArray(location) ? location[location.length - 1] : location;

const topToolbarHeight = await exports.getTopToolbarHeight(browser);

Expand Down
6 changes: 4 additions & 2 deletions test/lib/command-helpers/element-utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ describe('"element-utils" helper', () => {
assert.deepEqual(coords, {width: 10, height: 20, x: 1, y: 2});
});

it('should return coords of first found element', async () => {
// wdio returns elements in reverse order, so we need to take last element in array to pick first element on the page
// https://github.com/webdriverio/webdriverio/blob/v4.14.1/lib/commands/getLocation.js#L48.
it('should return coords of last found element', async () => {
browser.getElementSize.withArgs('some-selector').returns(
[{width: 10, height: 20}, {width: 100, height: 200}]
);
Expand All @@ -142,7 +144,7 @@ describe('"element-utils" helper', () => {

const coords = await utils.getElemCoords(browser, 'some-selector');

assert.deepEqual(coords, {width: 10, height: 20, x: 1, y: 2});
assert.deepEqual(coords, {width: 10, height: 20, x: 11, y: 22});
});

it('should increase y coordinate on top toolbar height', async () => {
Expand Down

0 comments on commit 0de9018

Please sign in to comment.