Skip to content

Commit

Permalink
fix(deps): update to wdio 5 (webdriver.io) (#229)
Browse files Browse the repository at this point in the history
On several machines (including on circle-ci, after upgrading node.js), I saw that webdriver-based tests were failing.

=> Upgrading from webdriver 4 to webdriver 5.

* trying to run tests with webdriverio v5

* use standalone instead of chrome driver

* lint fix

* migrate: browser.waitForVisible() -> $().waitForDisplayed()

* migrate: browser.isExisting() -> $().isExisting()

* migrate: browser.click() -> $().click()

* migrate: browser.setValue() -> $().setValue()

* lint fix

* migrate: browser.scroll() -> $().scrollIntoView()

* migrate: await $() in command, before calling getHTML()

* migrate: browser.getText() -> $().getText()

* migrate: browser.waitForText() -> $().waitForDisplayed()

* remove waitForReady() command

* migrate: browser.isVisible() -> $().isDisplayedInViewport()

* fix waitForLinkWithText() command

* migrate: browser.waitForExist() -> $().waitForExist()

* fix call to browser.execute()

* remove useless logging

* remove test that fails to access chrome's logs

* fix call to waitForContent() command

* migrate: browser.element() -> $() (works for xPath)
  • Loading branch information
adrienjoly committed Oct 1, 2019
1 parent f608092 commit de28437
Show file tree
Hide file tree
Showing 8 changed files with 5,135 additions and 3,686 deletions.
8,268 changes: 4,875 additions & 3,393 deletions package-lock.json

Large diffs are not rendered by default.

15 changes: 9 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,15 @@
"devDependencies": {
"@semantic-release/changelog": "^3.0.0",
"@semantic-release/git": "^7.0.4",
"@wdio/cli": "5.14.1",
"@wdio/dot-reporter": "^5.13.2",
"@wdio/local-runner": "^5.14.0",
"@wdio/mocha-framework": "^5.14.0",
"@wdio/selenium-standalone-service": "^5.13.2",
"@wdio/spec-reporter": "^5.13.2",
"@wdio/sync": "^5.14.0",
"all-contributors-cli": "5.4.0",
"chromedriver": "^77.0.0",
"eslint": "2.9.0",
"eslint-config-airbnb": "^9.0.1",
"eslint-plugin-import": "^1.11.1",
Expand All @@ -80,12 +88,7 @@
"mocha": "5.2.0",
"prettier": "^1.14.2",
"semantic-release": "^15.13.24",
"wdio-dot-reporter": "0.0.8",
"wdio-mocha-framework": "^0.5.10",
"wdio-selenium-standalone-service": "0.0.10",
"wdio-spec-reporter": "^0.1.0",
"wdio-visual-regression-service": "^0.8.0",
"webdriverio": "4.12.0"
"wdio-chromedriver-service": "^5.0.2"
},
"release": {
"branch": "master",
Expand Down
41 changes: 12 additions & 29 deletions test/acceptance-cmds.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,53 +6,38 @@ const WAIT_DURATION = 10000;
// custom wdio / webdriver.io commands

browser.addCommand('injectJS', function async(scriptUrl) {
return browser.execute(function(scriptUrl) {
return browser.execute(function (scriptUrl) {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = scriptUrl;
document.body.appendChild(script);
}, scriptUrl);
});

browser.addCommand('waitForReady', function async() {
return browser.waitUntil(
function() {
return (
browser.execute(function() {
return document.readyState;
}).value === 'complete'
);
},
WAIT_DURATION,
`page should be ready within 5 seconds`,
500 // => will check every 500 milliseconds
);
});

browser.addCommand('waitForLinkWithText', function async(text) {
return browser.waitUntil(
function() {
return browser.execute(function(text) {
return !!$("a:contains('" + text + "')")[0];
}, text).value;
function async() {
return browser.executeAsync(function (text, done) {
done(!!$("a:contains('" + text + "')")[0]);
}, text);
},
WAIT_DURATION,
`a "${text}" link should be in the page within ${WAIT_DURATION /
1000} seconds`,
1000} seconds`,
500 // => will check every 500 milliseconds
);
});

browser.addCommand('clickOnLinkWithText', function async(text) {
return browser.execute(function(text) {
return browser.execute(function (text) {
return $("a:contains('" + text + "')")[0].click();
}, text);
});

browser.addCommand('waitForContent', function async(regex, context) {
return browser.waitUntil(
function async() {
return this.getHTML(context || 'body').then(content => {
return $(context || 'body').then(elem => elem.getHTML()).then(content => {
//console.log(content.length, content.substr(0, 10), regex.toString(), regex.test(content))
return regex.test(content);
});
Expand All @@ -62,15 +47,13 @@ browser.addCommand('waitForContent', function async(regex, context) {
);
});

browser.addCommand('clickOnContent', function(text) {
return browser
.element(`//*[contains(text(), '${text.replace(/'/g, "\\'")}')]`)
.click();
browser.addCommand('clickOnContent', function (text) {
return $(`//*[contains(text(), '${text.replace(/'/g, "\\'")}')]`).click();
});

browser.addCommand('clickOnVisibleSelector', function(selector) {
browser.addCommand('clickOnVisibleSelector', function (selector) {
$$(selector)
.filter(node => node.isVisible())[0]
.filter(node => node.isDisplayedInViewport())[0]
.click();
return browser;
});
Expand Down
Loading

0 comments on commit de28437

Please sign in to comment.