Skip to content

Commit

Permalink
Merge pull request #54 from Financial-Times/pin-puppeteer
Browse files Browse the repository at this point in the history
Make compatible with Puppeteer 1.0.0
  • Loading branch information
adgad authored Apr 18, 2018
2 parents ccfaf98 + 02a3b92 commit 6fcc5f9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
5 changes: 2 additions & 3 deletions lib/smoke/checks.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ module.exports = {
return { expected: 204, actual: '¯\_(ツ)_/¯ ', result: true };
return true;
} else if (typeof testPage.check.status === 'string') {
const redirectLocation = testPage.redirect.headers()['location'];
return {
expected: `redirect to ${testPage.check.status}`,
actual: `redirect to ${redirectLocation}`,
result: testPage.check.status === redirectLocation
actual: `redirect to ${testPage.redirect.to}`,
result: testPage.check.status === testPage.redirect.to
};
} else {
return { expected: testPage.check.status, actual: testPage.status, result: testPage.status === testPage.check.status || testPage.status === 304 && testPage.check.status === 200 };
Expand Down
15 changes: 10 additions & 5 deletions lib/smoke/puppeteer-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class PuppeteerPage {
this.pageErrors = [];
this.consoleMessages = [];
this.coverageReports = [];
this.redirects = [];
this.requests = [];
this.response = null;

Expand Down Expand Up @@ -139,6 +140,13 @@ class PuppeteerPage {
} else if (!this.response) {
this.response = response;
}
//if this response is a redirect, log it
if(REDIRECT_CODES.includes(status)) {
this.redirects[url] = {
code: status,
to: response.headers().location
};
}
});

const gotoResponse = await this.page.goto(this.url.toString(), { waitUntil: this.waitUntil });
Expand All @@ -153,15 +161,12 @@ class PuppeteerPage {

get status () {
return REDIRECT_CODES.includes(this.check.status) && this.redirect ?
this.redirect.status() :
this.redirects[this.url.toString()].code :
this.response.status();
}

get redirect () {
const redirects = this.response.request().redirectChain();
if(redirects.length) {
return redirects[0].response();
}
return this.redirects[this.url.toString()];
}

async getVisibleElements (selector) {
Expand Down
3 changes: 1 addition & 2 deletions lib/smoke/smoke-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,12 @@ class SmokeTest {
host: this.host
};

const canRunCrossBrowser = await getSeleniumGrid(this.enabledBrowsers);

Object.entries(suiteOpts.urls).forEach(async ([path, urlOpts]) => {

const pageOpts = setupPage(path, urlOpts, suiteOpts, globalOpts);

const canRunCrossBrowser = getSeleniumGrid(this.enabledBrowsers);

if(pageOpts.browsersToRun.length > 1 && !canRunCrossBrowser) {
console.warn('Please set environment variables for Browserstack or Saucelabs to run cross browser tests.');
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"directly": "^2.0.6",
"inquirer": "^5.0.1",
"node-fetch": "^2.1.1",
"puppeteer": "^1.2.0",
"puppeteer": "^1.0.0",
"wdio-sauce-service": "^0.4.8",
"webdriverio": "^4.11.0"
},
Expand Down

0 comments on commit 6fcc5f9

Please sign in to comment.