Skip to content

Commit

Permalink
#2508 fix click api to take co-ordinates as options (#2558)
Browse files Browse the repository at this point in the history
* Fix click API to take co-ordinates, added test and bump version for release

Signed-off-by: saikrishna321 <saikrishna321@yahoo.com>
  • Loading branch information
saikrishna321 committed Mar 19, 2022
1 parent 4a9a956 commit d051717
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/actions/click.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ async function click(selector, options = {}, ...args) {
await simulateInputEvents(options);
return 'Clicked ' + description(selector, true) + ' ' + options.noOfClicks + ' times';
} else {
(options.x = selector.x), (options.y = selector.y);
await simulateInputEvents(options);
return (
'Clicked ' +
Expand Down
48 changes: 48 additions & 0 deletions lib/data/devices.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,54 @@ let DEVICES = {
isLandscape: true,
},
},
'iPhone 11': {
userAgent:
'Mozilla/5.0 (iPhone; CPU iPhone OS 15_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0 Mobile/15E148 Safari/604.1',
viewport: {
width: 414,
height: 896,
deviceScaleFactor: 2,
isMobile: true,
hasTouch: true,
isLandscape: false,
},
},
'iPhone 11 landscape': {
userAgent:
'Mozilla/5.0 (iPhone; CPU iPhone OS 15_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0 Mobile/15E148 Safari/604.1',
viewport: {
width: 896,
height: 414,
deviceScaleFactor: 2,
isMobile: true,
hasTouch: true,
isLandscape: true,
},
},
'iPhone 11 Pro': {
userAgent:
'Mozilla/5.0 (iPhone; CPU iPhone OS 15_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0 Mobile/15E148 Safari/604.1',
viewport: {
width: 375,
height: 812,
deviceScaleFactor: 3,
isMobile: true,
hasTouch: true,
isLandscape: false,
},
},
'iPhone 11 Pro landscape': {
userAgent:
'Mozilla/5.0 (iPhone; CPU iPhone OS 15_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0 Mobile/15E148 Safari/604.1',
viewport: {
width: 812,
height: 375,
deviceScaleFactor: 3,
isMobile: true,
hasTouch: true,
isLandscape: true,
},
},
'Kindle Fire HDX': {
userAgent:
'Mozilla/5.0 (Linux; U; en-us; KFAPWI Build/JDQ39) AppleWebKit/535.19 (KHTML, like Gecko) Silk/3.13 Safari/535.19 Silk-Accelerated=true',
Expand Down
2 changes: 1 addition & 1 deletion lib/eventBus.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ descEvent.on('success', (desc) => {

/*'createdSession' is a valid event that needs more than 10 listeners as all handlers
have to listen to it */
eventHandler.setMaxListeners(20);
eventHandler.setMaxListeners(100);

module.exports = {
eventHandler,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "http://json.schemastore.org/package",
"name": "taiko",
"version": "1.3.1",
"version": "1.3.2",
"description": "Taiko is a Node.js library for automating Chromium based browsers",
"main": "bin/taiko.js",
"bin": {
Expand Down
12 changes: 11 additions & 1 deletion test/unit-tests/click.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ let {
setConfig,
accept,
alert,
evaluate,
} = require('../../lib/taiko');
let { createHtml, removeFile, openBrowserArgs, resetConfig } = require('./test-util');
const test_name = 'Click';
Expand All @@ -23,7 +24,7 @@ describe(test_name, () => {
let innerHtml = `
<span>Click with proximity</span>
<div>
<span onclick="displayText('Click works with text nodes.')">Click on text node</span>
<span id='something' onclick="displayText('Click works with text nodes.')">Click on text node</span>
<span>Click with proximity</span>
</div>
<div>
Expand Down Expand Up @@ -118,6 +119,15 @@ describe(test_name, () => {
await click('on text');
expect(await text('Click works with text nodes.').exists()).to.be.true;
});

it('element click with coordinates', async () => {
const { x, y } = await evaluate(() => {
const { x, y } = document.querySelector('#something').getBoundingClientRect();
return { x, y };
});
await click({ x, y });
expect(await text('Click works with text nodes.').exists()).to.be.true;
});
});

describe('element inside shadow dom', () => {
Expand Down

0 comments on commit d051717

Please sign in to comment.