Skip to content

Commit 1f96518

Browse files
committed
feat: add "click" command replacer
1 parent 7edc54a commit 1f96518

File tree

5 files changed

+36
-0
lines changed

5 files changed

+36
-0
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ module.exports = {
3838
safari13: {
3939
commands: [
4040
'url',
41+
'click',
4142
'screenshot',
4243
'orientation',
4344
'swipe',
@@ -57,6 +58,7 @@ module.exports = {
5758

5859
Wrappers over existing commands:
5960
* **url** - wrapper over wdio "url" in order to wait until the page is completely open (used timeout from [`hermione.pageLoadTimeout`](https://github.com/gemini-testing/hermione#pageloadtimeout) or `30000` ms). In [appium-xcuitest-driver](https://github.com/appium/appium-xcuitest-driver) page is open with using the `xcrun` utility - `xcrun simctl openurl` which just tells the simulator to open the page and does not wait anything;
61+
* **click** - replaces wdio "click" in order to perform real touch click (by default it emits only events on passed element). Should be used with **touch** command;
6062
* **screenshot** - wrapper of wdio "screenshot" in order to cut the native elements from the final image ([calibration](https://github.com/gemini-testing/hermione#calibrate) must be turned off);
6163
* **orientation** - wrapper of wdio "orientation" in order to recalculate size of native elements for "screenshot" command (turns on automatically when you specify a screenshot command);
6264
* **swipe** - replaces wdio "swipe" in order to perform swipe by coordinates in native context;

lib/commands/click.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict';
2+
3+
module.exports = (browser) => {
4+
browser.addCommand('click', (selector) => {
5+
return browser.touch(selector);
6+
}, true);
7+
};

lib/commands/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
module.exports = {
44
url: require('./url'),
5+
click: require('./click'),
56
swipe: require('./swipe'),
67
touch: require('./touch'),
78
dragAndDrop: require('./dragAndDrop'),

test/lib/commands/click.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'use strict';
2+
3+
const addClickCommand = require('lib/commands/click');
4+
const {mkBrowser_} = require('../../utils');
5+
6+
describe('"click" command', () => {
7+
it('should add "click" command', () => {
8+
const browser = mkBrowser_();
9+
10+
addClickCommand(browser);
11+
12+
assert.calledOnceWith(browser.addCommand, 'click', sinon.match.func, true);
13+
});
14+
15+
it('should pass through control to the "touch" command', async () => {
16+
const browser = mkBrowser_();
17+
18+
addClickCommand(browser);
19+
20+
await browser.click('.some-selector');
21+
22+
assert.calledOnceWith(browser.touch, '.some-selector');
23+
});
24+
});

test/utils.js

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ exports.mkBrowser_ = () => {
2121

2222
session.executionContext = {};
2323
session.url = sinon.stub().named('url').resolves();
24+
session.click = sinon.stub().named('click').resolves();
25+
session.touch = sinon.stub().named('touch').resolves();
2426
session.touchAction = sinon.stub().named('touchAction').resolves();
2527
session.getElementSize = sinon.stub().named('getElementSize').resolves({});
2628
session.getLocation = sinon.stub().named('getLocation').resolves({});

0 commit comments

Comments
 (0)