From 539c742fbea1b904144efe0efcbb20c2bfa4f4ee Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Wed, 15 Apr 2020 16:38:51 +0200 Subject: [PATCH] test: refactor e2e config --- e2e/browserstack-send-status.js | 6 ++-- e2e/nightwatch.config.js | 56 +++++++++++++++++---------------- e2e/runner.js | 4 +-- package.json | 4 +-- 4 files changed, 36 insertions(+), 34 deletions(-) diff --git a/e2e/browserstack-send-status.js b/e2e/browserstack-send-status.js index ca26ce08..c840d277 100644 --- a/e2e/browserstack-send-status.js +++ b/e2e/browserstack-send-status.js @@ -21,9 +21,9 @@ function shouldSkipBrowserstackReporting(client) { } /** - * Generates an object with beforeEach and afterEach functions to be added - * to every test suite. It cannot be added globably because these must be - * executed before each test (instead of each test suite as it does in globalModules) + * Generates an object with beforeEach and afterEach functions to be added to + * every test suite. It cannot be added globally because these must be executed + * before each test (instead of each test suite as it does in globalModules) */ module.exports = function sendStatus() { const sessionMap = Object.create(null) diff --git a/e2e/nightwatch.config.js b/e2e/nightwatch.config.js index ef6a400f..b188db04 100644 --- a/e2e/nightwatch.config.js +++ b/e2e/nightwatch.config.js @@ -1,5 +1,18 @@ // yarn nightwatch -e chrome,safari,firefox +/** @type {import('nightwatch').NightwatchTestSettingScreenshots} */ +const browserDefaults = { + selenium_port: 4444, + selenium_host: 'localhost', + silent: true, + screenshots: { + enabled: true, + on_failure: true, + on_error: false, + path: 'e2e/screenshots', + }, +} + /** @type {import('nightwatch').NightwatchOptions} */ module.exports = { src_folders: ['e2e/specs'], @@ -11,38 +24,27 @@ module.exports = { selenium: { start_process: true, - server_path: require('selenium-server').path, + start_session: true, host: '127.0.0.1', port: 4444, + server_path: require('selenium-server').path, cli_args: { 'webdriver.chrome.driver': require('chromedriver').path, - // 'webdriver.gecko.driver': require('geckodriver').path + // 'webdriver.gecko.driver': require('geckodriver').path, }, }, + webdriver: { + start_process: false, + }, + test_settings: { default: { - selenium_port: 4444, - selenium_host: 'localhost', - silent: true, - screenshots: { - enabled: true, - on_failure: true, - on_error: false, - path: 'e2e/screenshots', - }, - desiredCapabilities: { - browserName: 'chrome', - acceptSslCerts: true, - chromeOptions: { - // https://github.com/nightwatchjs/nightwatch/releases/tag/v1.1.12 - w3c: false, - args: ['window-size=1280,800'], - }, - }, + launch_url: 'https://nightwatchjs.org', }, chrome: { + ...browserDefaults, desiredCapabilities: { browserName: 'chrome', acceptSslCerts: true, @@ -54,8 +56,8 @@ module.exports = { }, }, - // TODO: generate these and add skip tags 'chrome-headless': { + ...browserDefaults, desiredCapabilities: { browserName: 'chrome', acceptSslCerts: true, @@ -67,22 +69,22 @@ module.exports = { }, safari: { + ...browserDefaults, desiredCapabilities: { browserName: 'safari', acceptSslCerts: true, }, }, + // TODO: not working firefox: { + ...browserDefaults, desiredCapabilities: { browserName: 'firefox', acceptSslCerts: true, - }, - }, - - ie: { - desiredCapabilities: { - browser: 'internet explorer', + 'moz:firefoxOptions': { + args: [], + }, }, }, }, diff --git a/e2e/runner.js b/e2e/runner.js index 11fb6540..759eaee5 100644 --- a/e2e/runner.js +++ b/e2e/runner.js @@ -42,10 +42,10 @@ const NW_CONFIG = isLocal ? resolve(__dirname, './nightwatch.browserstack.js') : resolve(__dirname, './nightwatch.config.js') -// check -c option is passed when usig multiple environments +// check -c option is passed when using multiple environments if (args.indexOf('-c') < 0) { // check if multiple envs are provided. The way Nightwatch works - // requires to explicitely provide the conf + // requires to explicitly provide the conf const envs = args[args.indexOf('-e') + 1] if (envs && envs.indexOf(',') > -1) { console.warn( diff --git a/package.json b/package.json index af27e142..768fe220 100644 --- a/package.json +++ b/package.json @@ -28,8 +28,8 @@ "test:types": "tsc --build tsconfig.json", "test:unit": "jest --coverage", "test": "yarn run test:types && yarn run test:unit", - "test:e2e": "node e2e/runner.js", - "test:e2e:ci": "node e2e/runner.js --local -e ie,android44 -c e2e/nightwatch.browserstack.js e2e/specs/basic.js" + "test:e2e": "node e2e/runner.js -e chrome", + "test:e2e:ci": "node e2e/runner.js --local -e ie,android44 -c e2e/nightwatch.browserstack.js e2e/specs/encoding.js" }, "gitHooks": { "pre-commit": "lint-staged", -- 2.39.5