Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

Commit

Permalink
fix: correct implementation of doubleClick action
Browse files Browse the repository at this point in the history
1. There is no `wd.doubleClick` method, there is `doubleclick`
2. It does not accept the button
3. The original code acts on incorrect element
  • Loading branch information
Sergey Tatarintsev committed Dec 5, 2016
1 parent 2aa4bb0 commit f8746a9
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 36 deletions.
2 changes: 1 addition & 1 deletion lib/browser/new-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module.exports = class NewBrowser extends Browser {
'waitFor',
'moveTo',
'click',
'doubleClick',
'doubleclick',
'buttonDown',
'buttonUp',
'keys',
Expand Down
14 changes: 6 additions & 8 deletions lib/tests-api/actions-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,20 +116,18 @@ module.exports = inherit({
return this;
},

doubleClick: function(element, button) {
button = acceptMouseButton(button);

doubleClick: function(element) {
if (isInvalidElement(element)) {
throw new TypeError('.doubleClick() must receive valid element or CSS selector');
}

this._pushAction(this.doubleClick, function(browser) {
return findElement(element, browser)
.then(function() {
return browser.moveTo(element);
})
.then(function() {
return browser.doubleClick(element, button);
.then(function(element) {
return browser.moveTo(element)
.then(function() {
return browser.doubleclick();
});
});
});
return this;
Expand Down
2 changes: 1 addition & 1 deletion test/unit/browser/new-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe('browser/new-browser', () => {

[
'sleep', 'waitForElementByCssSelector', 'waitForElementByCssSelector', 'waitFor', 'moveTo',
'click', 'doubleClick', 'buttonDown', 'buttonUp', 'keys', 'type', 'tapElement', 'execute',
'click', 'doubleclick', 'buttonDown', 'buttonUp', 'keys', 'type', 'tapElement', 'execute',
'setWindowSize', 'getWindowSize', 'getOrientation', 'setOrientation'
].forEach((method) => it(method, () => testExposedWdMethod(method)));

Expand Down
26 changes: 0 additions & 26 deletions test/unit/tests-api/actions-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,32 +110,6 @@ describe('tests-api/actions-builder', () => {
});
});

describe('doubleClick', () => {
beforeEach(() => {
sandbox.stub(browser, 'doubleClick').returns(Promise.resolve());
});

it('should use left button if not specified', () => {
const doubleClick = mkAction('doubleClick', browser);

return doubleClick('.some-selector')
.then(() => assert.calledWith(browser.doubleClick, '.some-selector', 0));
});

it('should use passed button', () => {
const doubleClick = mkAction('doubleClick', browser);

return doubleClick('.some-selector', 1)
.then(() => assert.calledWith(browser.doubleClick, '.some-selector', 1));
});

it('should throw on bad button (not 0, 1 or 2)', () => {
const doubleClick = mkAction('doubleClick', browser);

assert.throws(() => doubleClick('.some-selector', 3), /Mouse button should be/);
});
});

describe('mouseDown', () => {
beforeEach(() => {
sandbox.stub(browser, 'buttonDown').returns(Promise.resolve());
Expand Down

0 comments on commit f8746a9

Please sign in to comment.