Skip to content

Commit

Permalink
feat: add "click" command replacer
Browse files Browse the repository at this point in the history
  • Loading branch information
DudaGod committed Sep 22, 2020
1 parent 7edc54a commit 1f96518
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module.exports = {
safari13: {
commands: [
'url',
'click',
'screenshot',
'orientation',
'swipe',
Expand All @@ -57,6 +58,7 @@ module.exports = {

Wrappers over existing commands:
* **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;
* **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;
* **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);
* **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);
* **swipe** - replaces wdio "swipe" in order to perform swipe by coordinates in native context;
Expand Down
7 changes: 7 additions & 0 deletions lib/commands/click.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

module.exports = (browser) => {
browser.addCommand('click', (selector) => {
return browser.touch(selector);
}, true);
};
1 change: 1 addition & 0 deletions lib/commands/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

module.exports = {
url: require('./url'),
click: require('./click'),
swipe: require('./swipe'),
touch: require('./touch'),
dragAndDrop: require('./dragAndDrop'),
Expand Down
24 changes: 24 additions & 0 deletions test/lib/commands/click.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict';

const addClickCommand = require('lib/commands/click');
const {mkBrowser_} = require('../../utils');

describe('"click" command', () => {
it('should add "click" command', () => {
const browser = mkBrowser_();

addClickCommand(browser);

assert.calledOnceWith(browser.addCommand, 'click', sinon.match.func, true);
});

it('should pass through control to the "touch" command', async () => {
const browser = mkBrowser_();

addClickCommand(browser);

await browser.click('.some-selector');

assert.calledOnceWith(browser.touch, '.some-selector');
});
});
2 changes: 2 additions & 0 deletions test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ exports.mkBrowser_ = () => {

session.executionContext = {};
session.url = sinon.stub().named('url').resolves();
session.click = sinon.stub().named('click').resolves();
session.touch = sinon.stub().named('touch').resolves();
session.touchAction = sinon.stub().named('touchAction').resolves();
session.getElementSize = sinon.stub().named('getElementSize').resolves({});
session.getLocation = sinon.stub().named('getLocation').resolves({});
Expand Down

0 comments on commit 1f96518

Please sign in to comment.