This repository was archived by the owner on Mar 4, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 427
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add Nightwatch.js as test framework option (#572)
- Loading branch information
Showing
10 changed files
with
438 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
232 changes: 232 additions & 0 deletions
232
packages/cna-template/template/frameworks/nightwatch/nightwatch.conf.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) {} | ||
} |
79 changes: 79 additions & 0 deletions
79
packages/cna-template/template/frameworks/nightwatch/nightwatch_globals.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
// } | ||
} |
9 changes: 9 additions & 0 deletions
9
packages/cna-template/template/frameworks/nightwatch/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
packages/cna-template/template/frameworks/nightwatch/test/e2e/pageObjects/main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
packages/cna-template/template/frameworks/nightwatch/test/e2e/specs/index.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.