Skip to content

Drag slider for WebDriver #1505

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
## 2.0.4

* [WebDriver][Protractor][Nightmare][Puppeteer] `grabAttributeFrom` returns an array when multiple elements matched. By @PeterNgTr
* [autoLogin plugin] Fixed merging users config by @nealfennimore
* [autoDelay plugin] Added WebDriver to list of supported helpers by @mattin4d
* [Appium] Fixed using locators in `waitForElement`, `waitForVisible`, `waitForInvisible`. By @eduardofinotti
* [allure plugin] Add tags to allure reports by @Vorobeyko
* [allure plugin] Add skipped tests to allure reports by @Vorobeyko
* Fixed `Logged Test name | [object Object]` when used Data().Scenario(). By @Vorobeyko
* Fixed Data().only.Scenario() to run for all datasets. By @Vorobeyko
* [WebDriver] `attachFile` to work with hidden elements. Fixed in [#1460](https://github.com/Codeception/CodeceptJS/pull/1460) by @tsuemura



## 2.0.3

* [**autoLogin plugin**](https://codecept.io/plugins#autologin) added. Allows to log in once and reuse browser session. When session expires - automatically logs in again. Can persist session between runs by saving cookies to file.
Expand Down
5 changes: 3 additions & 2 deletions docs/webapi/dragSlider.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ For fuzzy locators, fields are matched by label text, the "name" attribute, CSS,
I.dragSlider('#slider', 30);
I.dragSlider('#slider', -70);
```
@param field located by label|name|CSS|XPath|strict locator.
@param value position to drag.

@param locator located by label|name|CSS|XPath|strict locator.
@param offsetX position to drag.
23 changes: 23 additions & 0 deletions lib/helper/WebDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -1479,6 +1479,29 @@ class WebDriver extends Helper {
return sourceEl.dragAndDrop(destEl);
}

/**
* {{> ../webapi/dragSlider }}
*/
async dragSlider(locator, offsetX = 0) {
const browser = this.browser;
await this.moveCursorTo(locator);

// for chrome
if (browser.isW3C) {
return browser.performActions([
{ type: 'pointerDown', button: 0 },
{
type: 'pointerMove', origin: 'pointer', duration: 1000, x: offsetX, y: 0,
},
{ type: 'pointerUp', button: 0 },
]);
}

await browser.buttonDown(0);
await browser.moveToElement(null, offsetX, 0);
await browser.buttonUp(0);
}


/**
* Close all tabs except for the current one.
Expand Down
2 changes: 1 addition & 1 deletion test/helper/Puppeteer_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ describe('Puppeteer', function () {

describe('#dragSlider', () => {
it('should drag scrubber to given position', async () => {
await I.amOnPage(`file://${path.resolve(__dirname, '../data/sandbox/page_slider.html')}`);
await I.amOnPage('/form/page_slider');
await I.seeElementInDOM('#slidecontainer input');
const before = await I.grabValueFrom('#slidecontainer input');
await I.dragSlider('#slidecontainer input', 20);
Expand Down
12 changes: 12 additions & 0 deletions test/helper/WebDriver_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -638,4 +638,16 @@ describe('WebDriver', function () {
it('should attach to invisible input element', () => wd.amOnPage('/form/file')
.then(() => wd.attachFile('hidden', '/app/avatar.jpg')));
});


describe('#dragSlider', () => {
it('should drag scrubber to given position', async () => {
await wd.amOnPage('/form/page_slider');
await wd.seeElementInDOM('#slidecontainer input');
const before = await wd.grabValueFrom('#slidecontainer input');
await wd.dragSlider('#slidecontainer input', 20);
const after = await wd.grabValueFrom('#slidecontainer input');
assert.notEqual(before, after);
});
});
});