Skip to content

Commit

Permalink
Travis CI: Workarounds for bugs in chrome / chromedriver
Browse files Browse the repository at this point in the history
The previous attempt in c57f244 was not enough
Even browser.init() fails from time to time (something goes wrong in chromedriver). However everything is fine if we retry the init call. The downside is that the test runner keeps running forever, so we need to add --exit to mocha
  • Loading branch information
Joris-van-der-Wel committed Feb 28, 2018
1 parent e9f6d56 commit ab3c2e4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -23,7 +23,7 @@
"test:integration:jsdom": "mocha test/integration/environments/jsdom.js",
"test:integration:karma": "karma start test/integration/environments/karma.conf.js",
"test:integration:karma:watch": "npm run test:integration:karma -- --no-single-run --no-browsers",
"test:integration:webdriver": "mocha test/integration/environments/webdriver.js",
"test:integration:webdriver": "mocha --exit test/integration/environments/webdriver.js",
"test:benchmark:karma": "karma start test/benchmark/environments/karma.conf.js",
"test:benchmark:karma:watch": "npm run test:benchmark:karma -- --no-single-run --no-browsers",
"build": "node build",
Expand Down
53 changes: 39 additions & 14 deletions test/integration/environments/webdriver.js
Expand Up @@ -50,29 +50,54 @@ if (process.env.WD_DEBUG_LOG === '1') {
browser.on('http', (method, path, data) => console.log('WD http: ' + method, path, data));
}

const initBrowser = async () => {
for (let n = 0; n <= 10; n += 10) {
// sometimes chromedriver fails to properly initialize the session, retry it
const TIMEOUT = Symbol();
const initResult = await Promise.race([
browser.init({
pageLoadStrategy: 'none', // do not wait for any kind of document readyState during .get()
}),
Promise.delay(1000 + n * 250).then(() => TIMEOUT),
]);

if (initResult !== TIMEOUT) {
return; // success!
}

console.log('browser.init() timed out, trying again!');
}

throw Error('browser.init() has timed out too many times');
};

const navigateBrowser = async url => {
await browser.get(url);
for (let n = 0; n <= 25; ++n) {
// workaround for chrome bug introduced in recent versions (somewhere around v64)
// in old versions of chrome pageLoadStrategy:'none' would still wait for the actual navigation
// but now browser.get() resolves too early sometimes
const location = await browser.url();
if (!/^data:/.test(location)) {
return; // success!
}
const delay = n * 10;
console.log('Browser is still on "data:,"... sleeping for', delay, 'ms');
await Promise.delay(delay);
}
};

global.BLUEFOX_TEST_ENV = {
environment: 'webdriver',
navigate: async path => {
if (browserActive) {
await global.BLUEFOX_TEST_ENV.closeWindow();
}

await browser.init({
pageLoadStrategy: 'none', // do not wait for any kind of document readyState during .get()
});
await initBrowser();
browserActive = true;
await browser.setAsyncScriptTimeout(30000);
await browser.get(`http://127.0.0.1:8123/${path}`);
for (let delay = 0; delay <= 250; delay += 10) {
// workaround for chrome bug introduced in recent versions (somewhere around v64)
// in old versions of chrome pageLoadStrategy:'none' would still wait for the actual navigation
// but now browser.get() resolves too early sometimes
const location = await browser.url();
if (!/^data:/.test(location)) {
break;
}
await Promise.delay(delay);
}
await navigateBrowser(`http://127.0.0.1:8123/${path}`);
await browser.execute(bluefoxStringified);
await browser.execute(`
(() => {
Expand Down

0 comments on commit ab3c2e4

Please sign in to comment.