Skip to content

Commit

Permalink
Merge pull request #90 from Financial-Times/maintenance
Browse files Browse the repository at this point in the history
Maintenance
  • Loading branch information
adgad authored Oct 2, 2018
2 parents 194c273 + 47506f1 commit 4b6f3fb
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 24 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# n-test
Runs smoke tests with Puppeteer (and optionally Saucelabs). Define a set of URLs and expected behaviour in JSON, without the toil of writing full blown tests.
Runs smoke tests with Puppeteer (and optionally Browserstack). Define a set of URLs and expected behaviour in JSON, without the toil of writing full blown tests.

[![CircleCI](https://circleci.com/gh/Financial-Times/n-test.svg?style=svg&circle-token=d042713e08cb5920c4c2b462e63867d4906a7a66)](https://circleci.com/gh/Financial-Times/n-test)
[![Node.js version support][shield-node]](#)
Expand Down Expand Up @@ -228,10 +228,9 @@ smoke.run(['basic']);
```

### Cross Browser Testing [Experimental]
You can also run your test suite against Browserstack (or Saucelabs).
You can also run your test suite against Browserstack .

Browserstack: you must have `BROWSERSTACK_USER` and `BROWSERSTACK_KEY` environment variables set, and enable cross browser tests on a suite/url basis.
Saucelabs: you must have `SAUCE_USER` and `SAUCE_KEY` environment variables set, and enable cross browser tests on a suite/url basis.

*Note* Browserstack supports running off a local host. If your host is local, it will spin up Browserstack Local and proxy through.
*Caveat* sometimes browserstack local might not clean up properly after itself!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,6 @@ module.exports = async (browserName, isLocal) => {
user: process.env.BROWSERSTACK_USER,
key: process.env.BROWSERSTACK_KEY
};
} else if(process.env.SAUCE_USER && process.env.SAUCE_KEY) {
return {
desiredCapabilities: { browserName },
user: process.env.SAUCE_USER,
key: process.env.SAUCE_KEY,
host: 'ondemand.saucelabs.com',
services: ['sauce']
};
}

};
Expand Down
2 changes: 1 addition & 1 deletion lib/smoke/puppeteer-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class PuppeteerPage {
await setSessionCookies(this.page, this.url.toString(), tokens);
}

this.page.setViewport(this.dimensions);
await this.page.setViewport(this.dimensions);


if(this.check.cssCoverage) {
Expand Down
8 changes: 4 additions & 4 deletions lib/smoke/screenshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const filterConfigs = require('./filter-configs');
const setupPage = require('./setup-page');
const PuppeteerPage = require('./puppeteer-page');
const WebdriverPage = require('./webdriver-page');
const getSeleniumGrid = require('./get-selenium-grid');
const getBrowserstackConfig = require('./get-browserstack-config');

const takeScreenshot = (pageOpts, browser, headlessBrowser, viewingBrowser) => async () => {
const pageInstance = browser === 'chrome' ? new PuppeteerPage(pageOpts) : new WebdriverPage(pageOpts, browser);
Expand Down Expand Up @@ -59,9 +59,9 @@ module.exports = async (globalOpts, sets) => {
Object.keys(suiteOpts.urls).forEach(async (path) => {
let urlOpts = suiteOpts.urls[path];
const pageOpts = setupPage(path, urlOpts, Object.assign({ browsers: true }, suiteOpts), globalOpts);
const canRunCrossBrowser = await getSeleniumGrid(this.enabledBrowsers);
const canRunCrossBrowser = await getBrowserstackConfig(this.enabledBrowsers);
if(pageOpts.browsersToRun.filter(browser => browser.toLowerCase() !== 'chrome').length && !canRunCrossBrowser) {
console.warn('Please set environment variables for Browserstack or Saucelabs to run cross browser tests.');
console.warn('Please set environment variables for Browserstack to run cross browser tests.');
return;
}

Expand All @@ -81,7 +81,7 @@ module.exports = async (globalOpts, sets) => {
const cleanup = async (code) => {
viewingBrowser && viewingBrowser.close();
headlessBrowser && headlessBrowser.close();
await getSeleniumGrid.cleanup();
await getBrowserstackConfig.cleanup();
process.exit(code);
};

Expand Down
8 changes: 4 additions & 4 deletions lib/smoke/smoke-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const setupPage = require('./setup-page');
const verifyUrl =require('./verify-url');
const PuppeteerPage = require('./puppeteer-page');
const WebdriverPage = require('./webdriver-page');
const getSeleniumGrid = require('./get-selenium-grid');
const getBrowserstackConfig = require('./get-browserstack-config');

const ERROR_THRESHOLD=2;

Expand Down Expand Up @@ -49,12 +49,12 @@ class SmokeTest {

async cleanup () {
this.browser && this.browser.close();
return await getSeleniumGrid.cleanup();
return await getBrowserstackConfig.cleanup();
}

async compileTests (sets) {
const configsToRun = await filterConfigs(this.configFile, sets, this.isInteractive);
const canRunCrossBrowser = await getSeleniumGrid(this.enabledBrowsers);
const canRunCrossBrowser = await getBrowserstackConfig(this.enabledBrowsers);
const globalOptions = {
headers: this.globalHeaders,
browsers: this.browsers,
Expand All @@ -80,7 +80,7 @@ class SmokeTest {
const pageOptions = setupPage(path, urlOptions, suiteOptions, globalOptions);

if (pageOptions.browsersToRun.length > 1 && !canRunCrossBrowser) {
console.warn('Please set environment variables for Browserstack or Saucelabs to run cross browser tests.');
console.warn('Please set BROWSERSTACK_KEY and BROWSERSTACK_USER environment variables to run cross browser tests.');
}

if (suiteOptions.user && !pageOptions.user) {
Expand Down
4 changes: 2 additions & 2 deletions lib/smoke/webdriver-page.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const webdriverio = require('webdriverio');
const getSeleniumGrid = require('./get-selenium-grid');
const getBrowserstackConfig = require('./get-browserstack-config');


const DIMENSIONS = require('../helpers/dimensions');
Expand All @@ -26,7 +26,7 @@ class WebdriverPage {

async init () {

this.browserOptions = await getSeleniumGrid(this.type, this.url.host.startsWith('local'));
this.browserOptions = await getBrowserstackConfig(this.type, this.url.host.startsWith('local'));
if(!this.browserOptions || //skip if no environment variables
this.isAutomatedTest && !(this.check.elements || this.check.screenshot)) {
return;
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
"directly": "^2.0.6",
"inquirer": "^5.0.1",
"node-fetch": "^2.1.1",
"puppeteer": "1.5.0",
"wdio-sauce-service": "^0.4.8",
"puppeteer": "^1.8.0",
"webdriverio": "^4.11.0"
},
"devDependencies": {
Expand Down

0 comments on commit 4b6f3fb

Please sign in to comment.