Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit

Permalink
feat: add Nightwatch.js as test framework option (#572)
Browse files Browse the repository at this point in the history
  • Loading branch information
astagi authored Oct 19, 2020
1 parent 899aa8e commit 75985e4
Show file tree
Hide file tree
Showing 10 changed files with 438 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ yarn create nuxt-app <my-project>
- [Jest](https://github.com/facebook/jest)
- [AVA](https://github.com/avajs/ava)
- [WebdriverIO](https://webdriver.io)
- [Nightwatch](https://nightwatchjs.org)
1. Rendering mode
- [Universal (SSR / Static)](https://nuxtjs.org/guide/#server-rendered-universal-ssr-)
- [SPA](https://nuxtjs.org/guide/#single-page-applications-spa-)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
// Refer to the online docs for more details: https://nightwatchjs.org/gettingstarted/configuration/
const Services = {}; loadServices()

module.exports = {
// An array of folders (excluding subfolders) where your tests are located;
// if this is not specified, the test source must be passed as the second argument to the test runner.
src_folders: ['test/e2e/specs'],

exclude: [],

// See https://nightwatchjs.org/guide/working-with-page-objects/
page_objects_path: 'test/e2e/pageObjects',

// See https://nightwatchjs.org/guide/extending-nightwatch/#writing-custom-commands
custom_commands_path: '',

// See https://nightwatchjs.org/guide/extending-nightwatch/#writing-custom-assertions
custom_assertions_path: '',

// See https://nightwatchjs.org/guide/#external-globals
globals_path: 'nightwatch_globals.js',

webdriver: {},

test_settings: {
default: {
disable_error_log: false,
launch_url: 'https://nightwatchjs.org',

screenshots: {
enabled: false,
path: 'screens',
on_failure: true
},

desiredCapabilities: {
browserName: 'chrome'
},

webdriver: {
start_process: true,
server_path: 'node_modules/.bin/chromedriver',
port: 9515
}
},

safari: {
desiredCapabilities: {
browserName: 'safari',
alwaysMatch: {
acceptInsecureCerts: false
}
},
webdriver: {
port: 4445,
start_process: true,
server_path: '/usr/bin/safaridriver'
}
},

firefox: {
desiredCapabilities: {
browserName: 'firefox',
alwaysMatch: {
// Enable this if you encounter unexpected SSL certificate errors in Firefox
// acceptInsecureCerts: true,
'moz:firefoxOptions': {
args: [
// '-headless',
// '-verbose'
]
}
}
},
webdriver: {
start_process: true,
// default_path_prefix: '/wd/hub',
use_legacy_jsonwire: true,
port: 4444,
server_path: (Services.geckodriver ? Services.geckodriver.path : ''),
cli_args: [
// very verbose geckodriver logs
// '-vv'
]
}
},

chrome: {
desiredCapabilities: {
browserName: 'chrome',
chromeOptions: {
// This tells Chromedriver to run using the legacy JSONWire protocol (not required in Chrome 78)
// w3c: false,
// More info on Chromedriver: https://sites.google.com/a/chromium.org/chromedriver/
args: [
// '--no-sandbox',
// '--ignore-certificate-errors',
// '--allow-insecure-localhost',
// '--headless'
]
}
},

webdriver: {
start_process: true,
port: 9515,
server_path: (Services.chromedriver ? Services.chromedriver.path : ''),
cli_args: [
// --verbose
]
}
},

// ////////////////////////////////////////////////////////////////////////////////
// Configuration for when using the browserstack.com cloud service |
// |
// Please set the username and access key by setting the environment variables: |
// - BROWSERSTACK_USER |
// - BROWSERSTACK_KEY |
// .env files are supported |
// ////////////////////////////////////////////////////////////////////////////////
browserstack: {
selenium: {
host: 'hub-cloud.browserstack.com',
port: 443
},
// More info on configuring capabilities can be found on:
// https://www.browserstack.com/automate/capabilities?tag=selenium-4
desiredCapabilities: {
'bstack:options': {
local: 'false',
userName: '{BROWSERSTACK_USER}',
accessKey: '{BROWSERSTACK_KEY}'
}
},

disable_error_log: true,
webdriver: {
keep_alive: true,
start_process: false
}
},

'browserstack.chrome': {
extends: 'browserstack',
desiredCapabilities: {
browserName: 'chrome',
chromeOptions: {
// This tells Chromedriver to run using the legacy JSONWire protocol
// More info on Chromedriver: https://sites.google.com/a/chromium.org/chromedriver/
w3c: false
}
}
},

'browserstack.firefox': {
extends: 'browserstack',
desiredCapabilities: {
browserName: 'firefox'
}
},

'browserstack.ie': {
extends: 'browserstack',
desiredCapabilities: {
browserName: 'IE',
browserVersion: '11.0',
'bstack:options': {
os: 'Windows',
osVersion: '10',
local: 'false',
seleniumVersion: '3.5.2',
resolution: '1366x768'
}
}
},

// ////////////////////////////////////////////////////////////////////////////////
// Configuration for when using the Selenium service, either locally or remote, |
// like Selenium Grid |
// ////////////////////////////////////////////////////////////////////////////////
selenium: {
// Selenium Server is running locally and is managed by Nightwatch
selenium: {
start_process: true,
port: 4444,
server_path: (Services.seleniumServer ? Services.seleniumServer.path : ''),
cli_args: {
'webdriver.gecko.driver': (Services.geckodriver ? Services.geckodriver.path : ''),
'webdriver.chrome.driver': (Services.chromedriver ? Services.chromedriver.path : '')
}
}
},

'selenium.chrome': {
extends: 'selenium',
desiredCapabilities: {
browserName: 'chrome',
chromeOptions: {
w3c: false
}
}
},

'selenium.firefox': {
extends: 'selenium',
desiredCapabilities: {
browserName: 'firefox',
'moz:firefoxOptions': {
args: [
// '-headless',
// '-verbose'
]
}
}
}
}
}

function loadServices () {
try {
Services.seleniumServer = require('selenium-server')
} catch (err) {}

try {
Services.chromedriver = require('chromedriver')
} catch (err) {}

try {
Services.geckodriver = require('geckodriver')
} catch (err) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// External Globals doc: https://nightwatchjs.org/guide/#external-globals

module.exports = {
// this controls whether to abort the test execution when an assertion failed and skip the rest
// it's being used in waitFor commands and expect assertions
abortOnAssertionFailure: true,

// this will overwrite the default polling interval (currently 500ms) for waitFor commands
// and expect assertions that use retry
waitForConditionPollInterval: 500,

// default timeout value in milliseconds for waitFor commands and implicit waitFor value for
// expect assertions
waitForConditionTimeout: 5000,

// this will cause waitFor commands on elements to throw an error if multiple
// elements are found using the given locate strategy and selector
throwOnMultipleElementsReturned: false,

// controls the timeout value for async hooks. Expects the done() callback to be invoked within this time
// or an error is thrown
asyncHookTimeout: 10000,

// controls the timeout value for when running async unit tests. Expects the done() callback to be invoked within this time
// or an error is thrown
unitTestsTimeout: 2000,

// controls the timeout value for when executing the global async reporter. Expects the done() callback to be invoked within this time
// or an error is thrown
customReporterCallbackTimeout: 20000,

// Automatically retrying failed assertions - You can tell Nightwatch to automatically retry failed assertions until a given timeout is reached, before the test runner gives up and fails the test.
retryAssertionTimeout: 1000

// 'default' : {
// myGlobal : function() {
// return 'I\'m a method';
// }
// },

// 'test_env' : {
// myGlobal: 'test_global',
// beforeEach : function() {
// }
// },

//
// External before hook is ran at the beginning of the tests run, before creating the Selenium session
// before(cb) {
// cb();
// },

//
// External beforeEach hook ran before each test suite is started
// beforeEach(browser, cb) {
// cb();
// },

//
// External after hook is ran at the very end of the tests run, after closing the Selenium session
// after(cb) {
// cb();
// },

//
// External afterEach hook ran after each test suite is finished
// afterEach(browser, cb) {
// browser.perform(function() {
// //console.log('GLOBAL afterEach')
// cb();
// });
// },

//
// The global reporter is invoked before calling the built-in junit reporter (or a custom reporter specified using the --reporter CLI option).
// reporter(results, cb) {
// cb();
// }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"scripts": {
"test:e2e": "nightwatch"
},
"devDependencies": {
"nightwatch": "^1.3.6",
"chromedriver": "^86.0.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
commands: [],
url: 'http://localhost:3000',
elements: {
docButton: {
selector: '.button--green'
},
githubButton: {
selector: '.button--grey'
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
describe('Example test', () => {
test('open app correctly', (browser) => {
const main = browser.page.main()
main.navigate()
main.assert.visible('@docButton')
main.assert.visible('@githubButton')
browser.end()
})
})
3 changes: 2 additions & 1 deletion packages/create-nuxt-app/lib/prompts.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ module.exports = [
{ name: 'None', value: 'none' },
{ name: 'Jest', value: 'jest' },
{ name: 'AVA', value: 'ava' },
{ name: 'WebdriverIO', value: 'webdriverio' }
{ name: 'WebdriverIO', value: 'webdriverio' },
{ name: 'Nightwatch', value: 'nightwatch' }
],
default: 'none'
},
Expand Down
Loading

0 comments on commit 75985e4

Please sign in to comment.