Nightwatch parallel for two browser run only default for browserstack - nightwatch.js

I have configured several test settings and I want to run parallel chrome and ie.
When I run
./node_modules/.bin/nightwatch --env chrome
test for chrome runs
./node_modules/.bin/nightwatch --env ie
test for ie runs
./node_modules/.bin/nightwatch --env ie,chrome
test for firefox runs (as I guess this run only default ones and nothing more)
Nightwatch 1.0.18
{
"src_folders": [
"test"
],
"output_folder": "reports",
"live_output" : true,
"custom_commands_path": "config/commands",
"test_runner": {
"type" : "mocha",
"options" : {
"grep": "#acc"
}
},
"test_settings": {
"default": {
"selenium_host": "hub-cloud.browserstack.com",
"selenium_port": 80,
"launch_url": "localhost",
"browserstack.key": "KEY",
"browserstack.user": "USER",
"browserstack.local": "true"
},
"chrome-local": {
"default_path_prefix": "",
"launch_url": "localhost",
"screenshots": {
"enabled": true,
"on_failure": true,
"on_success": true,
"on_error": true,
"path": "./screenshots"
},
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true,
"chromeOptions": {
"args": [
"--no-sandbox",
"headless",
"window-size=1920,1200"
]
},
"acceptSslCerts": true,
"acceptInsecureCerts": true,
"elementScrollBehavior": 1
}
},
"chrome": {
"desiredCapabilities": {
"browser": "chrome"
}
},
"ie": {
"desiredCapabilities": {
"browserName": "ie",
}
}
}
}

for running parallel tests using Nightwatch refer - https://github.com/browserstack/nightwatch-browserstack
As you need to run parallel tests on Chrome and IE browsers you need to make changes to the line https://github.com/browserstack/nightwatch-browserstack/blob/master/package.json#L10 as follows-
"parallel": "./node_modules/.bin/nightwatch -c conf/parallel.conf.js
-e ie,chrome"

Related

Cypress multi reporters: using mochawesome with autoset-status-cypress-testrail-reporter

I need to use two reporters with my Cypress tests: mochawesome to generate html reports, and autoset-status-cypress-testrail-reporter to publish test results to Testrail.
The main tool I could find that would enable me to use multiple reporters is cypress-multi-reporters.
However, If I try to use cypress-multi-reporters with autoset-status-cypress-testrail-reporter, alone or in conjunction with mochawesome as below (in cypress.json), it does not work. It will not print out any errors, but it just will not publish the results to Testrail, and it will not generate the mochawesome reports.
{
"reporterEnabled": "mochawesome, autoset-status-cypress-testrail-reporter",
"mochawesomeReporterOptions": {
"reportDir": "cypress/reports",
"overwrite": false,
"html": true,
"json": false
},
"autosetStatusCypressTestrailReporterReporterOptions": {
"host": "https://xxxxxx/",
"username": "xxxxx",
"password": "xxxx",
"projectId": 1,
"runId": 1234
}
}
Can anyone tell me why the above is not working, or suggest a similar tool that would work with both mochawesome and autoset-status-cypress-testrail-reporter?
Got this to work in the end. The solution was
OPTION 1 - to include only the below in cypress.json:
"reporter": "cypress-multi-reporters",
"reporterOptions": {
"configFile": "reporter-config.json"
}
Then to create a new file called reporter-config.json, and add the config for each reporter in there:
{
"reporterEnabled": "mochawesome, autoset-status-cypress-testrail-reporter",
"mochawesomeReporterOptions": {
"reportDir": "cypress/reports",
"overwrite": false,
"html": true,
"json": false
},
"autosetStatusCypressTestrailReporterReporterOptions": {
"host": "https://xxxxxx/",
"username": "xxxxx",
"password": "xxxx",
"projectId": 1,
"runId": 1234
}
}
OPTION 2 - to have everything inside cypress.json, like so:
"reporter": "cypress-multi-reporters",
"reporterOptions": {
"reporterEnabled": "mochawesome, autoset-status-cypress-testrail-reporter",
"mochawesomeReporterOptions": {
"reportDir": "cypress/reports",
"overwrite": false,
"html": true,
"json": false
},
"autosetStatusCypressTestrailReporterReporterOptions": {
"host": "https://xxxxxx/",
"username": "xxxxx",
"password": "xxxx",
"projectId": 1,
"runId": 1234
}
}

How to launch Windows Terminal with Multiple Tabs?

I am attempting to use startupActions to launch a second tab when Windows Terminal launches with no luck.
My default shell is WSL, so I have the following in my settings.json:
"startupActions": "; new-tab -p PowerShell",
I've tried it without the semi-colon and without the -p flag as well.
Here is the settings.json minus the color schemes:
{
"$help": "https://aka.ms/terminal-documentation",
"$schema": "https://aka.ms/terminal-profiles-schema",
"actions":
[
{
"command":
{
"action": "copy",
"singleLine": false
},
"keys": "ctrl+c"
},
{
"command": "paste",
"keys": "ctrl+v"
},
{
"command": "find",
"keys": "ctrl+shift+f"
},
{
"command":
{
"action": "splitPane",
"split": "auto",
"splitMode": "duplicate"
},
"keys": "alt+shift+d"
}
],
"centerOnLaunch": true,
"copyFormatting": "none",
"copyOnSelect": false,
"defaultProfile": "{2c4de342-38b7-51cf-b940-2309a097f518}",
"initialCols": 98,
"initialRows": 24,
"showTerminalTitleInTitlebar": false,
"startupActions": "; new-tab -p PowerShell",
"useAcrylicInTabRow": true,
"profiles":
{
"defaults":
{
"colorScheme": "Dracula",
"cursorShape": "filledBox",
"elevate": true,
"font":
{
"face": "MesloLGS NF",
"size": 12
},
"startingDirectory": null
},
"list":
[
{
"antialiasingMode": "cleartype",
"experimental.retroTerminalEffect": false,
"guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
"hidden": false,
"name": "Command Prompt",
"opacity": 75,
"useAcrylic": true
},
{
"guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
"hidden": true,
"name": "Azure Cloud Shell",
"opacity": 75,
"source": "Windows.Terminal.Azure",
"useAcrylic": true
},
{
"antialiasingMode": "cleartype",
"experimental.retroTerminalEffect": false,
"font":
{
"size": 12
},
"guid": "{2c4de342-38b7-51cf-b940-2309a097f518}",
"hidden": false,
"name": "Ubuntu",
"opacity": 75,
"scrollbarState": "visible",
"source": "Windows.Terminal.Wsl",
"startingDirectory": "\\\\wsl$\\Ubuntu\\home\\steve",
"suppressApplicationTitle": true,
"tabColor": "#BD93F9",
"tabTitle": "Ubuntu 20.04",
"useAcrylic": true
},
{
"antialiasingMode": "cleartype",
"experimental.retroTerminalEffect": false,
"font":
{
"face": "Fira Code Retina"
},
"guid": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
"hidden": false,
"name": "PowerShell",
"opacity": 75,
"source": "Windows.Terminal.PowershellCore",
"tabColor": "#6272A4",
"useAcrylic": true
}
]
}
}
"elevate": true is your culprit here. You can't have mixed-elevation of tabs in the same window. Admin and non-admin windows need to stay separate. So when you launch those startupActions, the Terminal automatically creates a new admin window to host the powershell tab (which you've set to always run as admin).
Removing that setting from your powershell profile should work.

Running Tests in Parallel in Night watch

Need some help in figuring out how to run tests in parallel.
Here is how the project is configured and the command I use to run a test.
On the terminal window in run the command - 'npm run test-qa' whoch actually call the 'package.json' which has a script tag to called 'test-qa'.
Here is how my package.json looks like:
{
"name": "Project",
"version": "2.0.0",
"dependencies": {
"babel-core": "^6.8.0",
"babel-eslint": "^7.2.3",
"babel-loader": "^7.1.2",
"babel-polyfill": "^6.8.0",
"babel-preset-es2015": "^6.6.0",
"babel-preset-react": "^6.5.0",
"babel-preset-react-hmre": "^1.1.1",
"babel-preset-stage-0": "^6.5.0",
"babel-register": "^6.26.0",
"eslint-loader": "^1.9.0",
"gulp": "^3.9.1",
"gulp-eslint": "^4.0.0",
"gulp-nightwatch": "^0.2.6",
"handlebars": "^4.0.10",
"json-parser": "^1.1.5",
"json-stringify": "^1.0.0",
"oracledb": "^1.13.1",
"webpack-nightwatch-plugin": "^1.0.0"
},
"scripts": {
"test-local": "eslint . && gulp local:e2e --compilers js:babel-core/register --require babel-polyfill",
"test-dev": "eslint . && gulp dev:e2e --compilers js:babel-core/register --require babel-polyfill",
***"test-qa": "eslint . && gulp qa:e2e --compilers js:babel-core/register --require babel-polyfill --env local",***
},
"devDependencies": {
"gulp": "^3.9.1",
"moment-timezone": "^0.5.20",
"selenium-server-standalone-jar": "2.47.1"
}
}
The test-qa tag from package.json, in turn, calls gulpfile.js to execute the actual task(qa:e2e) in this case. Here is my gulp file code :
const gulp = require('gulp');
const nightwatch = require('gulp-nightwatch');
const eslint = require('gulp-eslint');
gulp.task('qa:e2e', function qaSpec() {
process.env.seleniumon = 'qa';
return gulp.src('')
.pipe(nightwatch({
configFile: 'nightwatch.json',
cliArgs: ['--env local', '--reporter html-reporter.js']
}));
});
gulp.task('local:e2e', function localSpec() {
process.env.seleniumon = 'local';
return gulp.src('')
.pipe(nightwatch({
configFile: 'nightwatch.json',
cliArgs: ['--env local', '', '--reporter html-reporter.js']
}));
});
gulp.task('dev:e2e', function devSpec() {
process.env.seleniumon = 'dev';
return gulp.src('')
.pipe(nightwatch({
configFile: 'nightwatch.json',
cliArgs: ['--env local', '--reporter html-reporter.js']
}));
});
gulp.task('lint', function srcSpec() {
return gulp.src(['**/*.js', '!node_modules/**'])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
gulp.task('default', ['lint']);
the qa:e2e task from gulpfile.js now calls nightwatch.json file to get settings and continue with the execution. Here is my nightwatch.json file:
{
"src_folders": ["tests"],
"output_folder": "reports",
"custom_commands_path": [ "commons/util", "commons/up", "commons/searchPane", "commons/EditorValidations", "commons/model"],
"custom_assertions_path": "",
"page_objects_path": ["pages/admin", "pages/UP", "pages/searchPane", "pages/EditorValidations/CMO", "pages/EditorValidations/CPO", "pages/EditorValidations/GMO", "pages/EditorValidations/GPO", "pages/model"],
"globals_path": "",
"selenium" : {
"start_process" : true,
"server_path" : "./node_modules/selenium-server-standalone-jar/jar/selenium-server-standalone-2.47.1.jar",
"host" : "127.0.0.1",
"port" : 4444,
"cli_args" : {
"webdriver.chrome.driver" : "drivers/chromedriver",
"webdriver.ie.driver" : ""
}
},
"test_settings": {
"chrome": {
"selenium_port": 4444,
"selenium_host": "selenium-hub.nikedev.com",
"skip_testcases_on_fail": true,
"end_session_on_fail":false,
"globals": {
"platform": "desktop"
},
"screenshots": {
"enabled": true,
"on_failure": true,
"on_error": true,
"path": "screenshots/chrome"
},
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true,
"acceptSslCerts": true
}
},
"local": {
"selenium_port": 4444,
"selenium_host": "127.0.0.1",
"skip_testcases_on_fail": true,
"end_session_on_fail":false,
"globals": {
"platform": "desktop"
},
"screenshots": {
"enabled": true,
"on_failure": true,
"on_error": true,
"path": "screenshots/chrome"
},
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true,
"acceptSslCerts": true
}
}
}
}
This setup is able to execute seamlessly.
I wanted to run test cases parallel and for the I added the following line to my nightwatch.json after "global_path"
"test_workers" : {"enabled" : true, "workers" : "auto"},
After this configuration change the tests never initiated with an error ' throw new Error('Invalid testing environment specified: ' + envs[i]);' even though my gulp file has mention for the environment we want it to run.
cliArgs: ['--env local', '--reporter html-reporter.js']
Can someone help me understand what changes do I need to make to run the test cases parallel?
The workers option configures how many child processes can run concurrently.
• "auto" - determined by number of CPUs e.g. 4 CPUs means 4 workers
• {number} - specifies an exact number of workers
Test concurrency is done at the file level. Each test file will fill a test worker slot. Individual tests/steps in a test file will not run concurrently.
Version 0.9 brings improved support for displaying output when running tests in parallel. recommend setting detailed_output to false in your test settings for improved output readability.
Refer to this link:
https://github.com/nightwatchjs/nightwatch-docs/blob/master/guide/running-tests/run-parallel.md

Nightwatchjs folder structure

What's the simplest folder structure I can use with Nightwatchjs? It will be used locally and for continuous integration. Currently I can't even get the demo to work. I have six errors:
module.js:469:15
module.js:417:25
bootstrap_node.js:604.10
bootstrap_node.js:394:7
bootstrap_node.js:149:9
bootstrap_node.js:509:3.
I realize this is a beginner question. I've been using Telerik and TestComplete for a few years and now we want to do CI properly so Selenium is the way to go. I'm comfortable with javascript but kind of bad at file path stuff.
What's the simplest folder structure I can use with Nightwatchjs?
The simplest NightwatchJS folder structure is:
To have 2 files (a configuration file and a file which contain you tests):
nightwatch.json
app.js (you can rename it as you want)
Example
1) nightwatch.json
{
"src_folders": [
"app.js"
],
"live_output": false,
"tests_output": "test/tests_output/",
"detailed_output": true,
"selenium": {
"start_process": false,
"host": "hub.browserstack.com",
"port": 80
},
"test_workers": {
"enabled": false,
"workers": "auto"
},
"test_settings": {
"chrome": {
"selenium_port": 80,
"selenium_host": "hub.browserstack.com",
"silent": true,
"desiredCapabilities": {
"os": "Windows",
"os_version": "10",
"browserName": "chrome",
"resolution": "1024x768",
"javascriptEnabled": true,
"acceptSslCerts": true,
"browserstack.video": "true",
"browserstack.debug": "true",
"browserstack.user": "<yourUsername>",
"browserstack.key": "<yourPassword>"
}
}
}
}
2) app.js
module.exports = {
'Does-stackoverflow-works': function (browser) {
browser
.url("http://stackoverflow.com/questions")
.waitForElementPresent('body', 2000, "Display latest Stackoverflow questions")
.end()
}
};
Run
$> nightwatch --env chrome
Output

How to use saucelabs with nightwatch?

I have the following configuration in my nightwatch.json file
"saucelabsChrome": {
"selenium_host": "ondemand.saucelabs.com",
"selenium_port": 80,
"username": "example",
"access_key": "--REDACTED---",
"desiredCapabilities": {
"acceptsSslCerts": true,
"name": "chrome",
"browserName": "chrome",
"platform": "OS X 10.11",
"version": "45.0"
}
},
However, when I run nightwatch with sauce labs
node nightwatch ---args '{"beta": "true", "env": "stage"}' --test tests/example.js -e saucelabsChrome
I get an error
Couldn't find element signUpAdobe
Two questions
Where can I see the nightwatch command running on Saucelabs?
What is the best way to integrate saucelabs with nightwatch?
Here is an example of my nightwatch.json file configured to run parallel tests on Sauce Labs.
{
"src_folders" : ["tests"],
"output_folder" : "reports",
"custom_commands_path" : "custom_commands",
"custom_assertions_path" : "",
"page_objects_path" : "",
"globals_path" : "",
"selenium" : {
"start_process" : false,
"server_path" : "",
"log_path" : "",
"host" : "127.0.0.1",
"port" : 4444,
"cli_args" : {
"webdriver.chrome.driver" : "",
"webdriver.ie.driver" : ""
}
},
"test_workers" : {"enabled" : true, "workers" : "auto"},
"test_settings" : {
"default" : {
"launch_url" : "http://localhost",
"selenium_port" : 80,
"selenium_host" : "ondemand.saucelabs.com",
"silent": true,
"screenshots" : {
"enabled" : false,
"path" : ""
},
"username" : "${SAUCE_USERNAME}",
"access_key" : "${SAUCE_ACCESS_KEY}",
"desiredCapabilities": {
"javascriptEnabled": true,
"acceptSslCerts": true
}
},
"chrome": {
"desiredCapabilities": {
"platform": "XP",
"browserName": "chrome",
"version": "41"
}
},
"firefox" : {
"desiredCapabilities": {
"platform": "XP",
"browserName": "firefox",
"version": "33"
}
},
"internet_explorer_10" : {
"desiredCapabilities": {
"platform": "Windows 7",
"browserName": "internet explorer",
"version": "10"
}
}
}
}
Here is a link to the entire project if you would like to take a look:
https://github.com/saucelabs-sample-test-frameworks/JS-Nightwatch.js
As to your second question. You can see the tests running in the Sauce Labs dashboard. Login at www.saucelabs.com and click on the tests tab in the top left corner.
I realize it's been a few years, but when I was searching I came across this post and found a newer guide for how to use SauceLabs with Nightwatch
Hopefully this helps anyone ending up here like I did :D

Resources