In Nightwatchjs, how to use maximum or defined number of instances of browser in a node using Selenium Grid till execution completed - selenium-grid

When I execute more than 280 testsuites with 3000+ test cases in parallel using NightwatchJs via Selenium Grid. I have allocated 26 node(running on AWS Fargate) and configured my node to supports 5 instance where total instances are 130 available.
then configured worker=43 in nightwatch.json file like:
{
"src_folders": [
"tests"
],
"output_folder": "reports",
"custom_commands_path": "./custom/commands",
"custom_assertions_path": "",
"page_objects_path": "pages",
"globals_path": "./custom/globals.js",
"live_output": true,
"detailed_output": false,
"selenium": {
"start_process": false,
"server_path": "lib/drivers/selenium-server-standalone-3.9.1.jar",
"selenium_port": 4444,
"screenshots": {
"enabled": false,
"on_failure": false,
"on_error": false,
"path": "screenshots/"
},
"cli_args": {
"webdriver.chrome.driver": ""
}
},
"test_settings": {
"default": {
"launch_url": "someWebsite.com",
"selenium_port": 4444,
"selenium_host": "selenium-abc.selenium.xyz.com",
"silent": true,
"use_xpath": true,
"end_session_on_fail": false,
"skip_testcases_on_fail": false,
"request_timeout_options": {
"timeout": 120000
},
"screenshots": {
"enabled": true,
"path": "screenshots/chrome/",
"on_failure": true,
"on_error": true
},
"desiredCapabilities": {
"browserName": "chrome",
"goog:chromeOptions": {
"w3c": false,
"args": [
"--use-fake-ui-for-media-stream",
"--window-size=1920,1080",
"--disable-gpu",
"--disable-dev-shm-usage",
"--disable-extensions",
"--no-sandbox",
"disable-infobars",
"--start-maximized",
"--whitelisted-ips"
]
}
}
},
"dev": {
"launch_url": "someWebsite.com"
},
"local-chrome": {
"desiredCapabilities": {
"browserName": "chrome",
"chromeOptions": {
"w3c": false,
"args": [
"disable-web-security",
"ignore-certificate-errors",
"--test-type"
]
}
}
},
"edge": {
"desiredCapabilities": {
"browserName": "MicrosoftEdge"
}
}
},
"parallel_process_delay": 10000,
"test_workers": {
"enabled": true,
"workers": 43
}
}
nightwatch.conf.js file look like
module.exports = (function (settings) {
//setting up selenium grid server hostname based on arguments passed
if (process.argv.includes("--selenium_host")) {
let arguments = process.argv;
let hostFoundInArgs = false;
arguments.forEach((string, index) => {
if (string.includes("selenium_host") && arguments[index + 1] != undefined) {
hostFoundInArgs = true;
settings.test_settings.default.selenium_host = arguments[index + 1];
}
if (string.includes("workers") && arguments[index + 1] != undefined) {
hostFoundInArgs = true;
let workerStringObject = "{\"enabled\" : true, \"workers\" : "+arguments[index + 1]+"}"
let workers = JSON.parse(workerStringObject);
settings.test_workers = workers;
}
})
}
return settings;
})(require('./nightwatch.json'));
So that it will use 43 browser instances while executions through Jenkins but this is not the case.
At starting it uses around 30 instances but after some time it went down to 4 to 5 instances only or even low because after first batch of testsuites execution completed, it is not able to utilize the rest or free instances available. Due to which our execution time went to around 2 and half hours.
So here is my question, is there any way to utilize all the instances available till completion of execution. So that my resource will not go waste.
Please let me know if more information needed.

Related

How do I keep the browser open on a failed test using Selenium+Nightwatch+Chromedriver?

I'm using Nightwatch, Selenium, and Chrome Driver to conduct automated UI testing. Sometimes there are test failures on any number of remote environments. To debug the failures locally, I would like to keep the browser open on test failure.
I used to be able to do this using config settings in nightwatch.json and nightwatch.conf.js, but I lost my config settings cheat-sheet in a hard drive failure, and despite my best efforts on google I can't seem to find the right combination again.
If I remember correctly, it wasn't any kind of keepBrowserOpen: true type flag. If memory serves, it was some type of timeout set to a silly high number combined with something else like detachDriver. I've checked the Selenium documentation with specific focus on the Chrome Driver Options, and the list of Chrome Driver options, but I haven't found any working combinations.
What am I missing?
Here is my nightwatch.json
{
"output_folder": "tests/automation/reports",
"end_session_on_fail": false,
"test_settings": {
"default": {
"selenium_port": 4444,
"screenshots": {
"enabled": true,
"path": "tests/automation/reports/screenshots"
},
"javascriptEnabled": true,
"acceptSslCerts": true,
"acceptInsecureCerts": true,
"globals": {
"waitForConditionTimeout": 10000
}
},
"chrome": {
"extends": "default",
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true,
"acceptSslCerts": true,
"acceptInsecureCerts": true,
"chromeOptions": {
"args": [
"--no-sandbox",
"--disable-gpu"
]
}
}
}
}
}
And my nightwatch.conf.js
const geckoDriver = require('geckodriver');
const chromeDriver = require('chromedriver');
const seleniumServer = require('selenium-server');
module.exports = (function (settings) {
settings.selenium = {
start_process: true,
server_path: seleniumServer.path,
log_path: 'tests/automation/reports/',
host: 'localhost',
port: 4444,
cli_args: {
'webdriver.chrome.driver': chromeDriver.path,
'webdriver.gecko.driver': geckoDriver.path,
'webdriver.edge.driver': 'C:\\windows\\system32\\MicrosoftWebDriver.exe',
'webdriver.port': '4444'
}
};
return settings;
})(require('./nightwatch.json'));
Selenium Version is 2.35.1
This is not an elegant solution but close to what you are looking for. Basically, we can check the value of browser.currentTest.results.errors in afterEach() and in case if the value is more than 0, then we can just pause the test there, keeping the browser session alive.
afterEach: function(browser) {
if(browser.currentTest.results.errors > 0) {
browser.pause()
}

Webdriver-manager error: Unable to create session with *my config*

I run into the following problem after updating webdriver-manager:
E/launcher - SessionNotCreatedError: Unable to create session from
my config is printed here
webdriver-manager Version: 12.1.5
Node Version: 10.15.3
Protractor Version: 5.4.2
Browser(s): Chrome
Operating System and Version: Win 7 / Ubuntu
This is my config file which worked for the last 1.5 years:
exports.config = {
"seleniumAddress": "http://localhost:4444/wd/hub",
"seleniumPort": "4444",
"capabilities": {
"browserName": "chrome",
"unexpectedAlertBehaviour": "accept",
"perform": "ANY",
"version": "ANY",
"chromeOptions": {
"perfLoggingPrefs": {
"traceCategories": "blink.console,devtools.timeline,disabled-by-default-devtools.timeline,toplevel,disabled-by-default-devtools.timeline.frame,benchmark"
},
"prefs": {
"credentials_enable_service": false
},
"args": ["--headless", "--window-size=800,1080", "--disable-blink-features=BlockCredentialedSubresources", "--no-sandbox", "--test-type=browser", "--disable-dev-shm-usage", "--enable-gpu-benchmarking", "--enable-thread-composting" , "--start-maximized"]
},
"loggingPrefs": { "performance": "ALL" }
},
"jasmineNodeOpts": {
"showColors": true,
"defaultTimeoutInterval": 9999999
},
"allScriptsTimeout": 200000,
"params": {
"perf": {
"selenium": { "protocol": "http:", "slashes": true, "auth": null, "host": "localhost:4444", "port": 4444, "hostname": "localhost", "hash": null, "search": null, "query": null, "pathname": "/wd/hub", "path": "/wd/hub", "href": "http://localhost:4444/wd/hub" },
"browsers": [{
"browserName": "chrome",
"chromeOptions": {
"perfLoggingPrefs": {
"traceCategories": "blink.console,devtools.timeline,disabled-by-default-devtools.timeline,toplevel,disabled-by-default-devtools.timeline.frame,benchmark"
},
"args": ["--headless", "--disable-gpu", "--disable-blink-features=BlockCredentialedSubresources", "--no-sandbox", "--test-type=browser", "--disable-dev-shm-usage"]
},
"loggingPrefs": { "performance": "ALL" }
}],
"debugBrowser": false,
"actions": ["scroll"],
"metrics": ["TimelineMetrics", "ChromeTracingMetrics", "RafRenderingStats", "NetworkTimings", "NetworkResources"],
"metricOptions": {}
},
"warmup": false,
"agilar" : false
}
}
I know the file is a mess and it's more or less googled together, but it worked. Can you point me to what is causing this problem?
Is selenium server up and running at default address
"http://localhost:4444/wd/hub" . If it's not , start it by running : webdriver-manager start. Assuming you have webdriver-manager installed already.
Also I dont think you need to define seleniumPort when you have selenium address property given already in config. So remove this property "seleniumPort": "4444" from config.

Aurelia bundling not overwriting on bundle

When I try to create an aurelia bundle and one already exists, I get an error basically saying it failed because a file already exists. The problem is that my force:true is set. Any help with this would be greatly appreciated.
var gulp = require('gulp'),
aureliaBundle = require('aurelia-bundler').bundle;
var aureliaBundleConfig = {
"force": true,
"baseUrl": ".",
"configPath": "js/config.js",
"bundles": {
"js/aurelia-bundle.min": {
"includes": [
"[js/**/*.js]",
"Templates/**/*.html!text"
],
"options": {
"inject": true,
"minify": true,
"depCache": false
}
},
"js/vendor-bundle": {
"includes": [
"lib/github/components/jquery#2.2.4",
"lib/github/signalr/bower-signalr#2.2.0",
"lib/npm/aurelia-bootstrapper#1.0.0-rc.1.0.1",
"lib/npm/aurelia-fetch-client#1.0.0-rc.1.0.1",
"lib/npm/aurelia-framework#1.0.0-rc.1.0.2",
"lib/npm/aurelia-router#1.0.0-rc.1.0.1",
"lib/npm/aurelia-animator-css#1.0.0-rc.1.0.0",
"lib/npm/aurelia-http-client#1.0.0-rc.1.0.0",
"lib/npm/aurelia-kendoui-bridge#0.11.8",
"lib/npm/aurelia-event-aggregator#1.0.0-rc.1.0.0",
"lib/npm/aurelia-templating-binding#1.0.0-rc.1.0.1",
"lib/npm/aurelia-templating-resources#1.0.0-rc.1.0.1",
"lib/npm/aurelia-templating-router#1.0.0-rc.1.0.1",
"lib/npm/aurelia-templating#1.0.0-rc.1.0.1",
"lib/npm/aurelia-loader-default#1.0.0-rc.1.0.0",
"lib/npm/aurelia-history-browser#1.0.0-rc.1.0.0",
"lib/npm/aurelia-logging-console#1.0.0-rc.1.0.0"
],
"options": {
"inject": true,
"minify": true,
"depCache": false
}
}
}
};
gulp.task('bundle:aurelia', function () {
return aureliaBundle(aureliaBundleConfig);
});

Sort icon not changing in Datatable server side processing

When I use server side processing in datatable the sorting works but the sort icon does not change and stays in same direction. Below is the code snippet of my datatable configuration.
$('#dtSearchResult').DataTable({
"filter": false,
"pagingType": "simple_numbers",
"orderClasses": false,
"order": [[0, "asc"]],
"info": true,
"scrollY": "450px",
"scrollCollapse": true,
"bLengthChange": false,
"searching": true,
"bStateSave": false,
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": VMCreateExtraction.AppSecurity.websiteNode() + "/api/Collection/SearchCustIndividual",
"fnServerData": function (sSource, aoData, fnCallback) {
aoData.push({ "name": "ccUid", "value": ccUid });
//Below i am getting the echo that i will be sending to Server side
var echo = null;
for (var i = 0; i < aoData.length; i++) {
switch (aoData[i].name) {
case 'sEcho':
echo = aoData[i].value;
break;
default:
break;
}
}
$.ajax({
"dataType": 'json',
"contentType": "application/json; charset=utf-8",
"type": "GET",
"url": sSource,
"data": aoData,
success: function (msg, a, b) {
$.unblockUI();
var mappedCusNames = $.map(msg.Table, function (Item) {
return new searchGridListObj(Item);
});
var data = {
"draw": echo,
"recordsTotal": msg.Table2[0].TOTAL_NUMBER_OF_RECORDS,
"recordsFiltered": msg.Table1[0].FILTERED_RECORDS,
"data": mappedCusNames
};
fnCallback(data);
$("#dtSearchResult").show();
ko.cleanNode($('#dtSearchResult')[0]);
ko.applyBindings(VMCreateExtraction, $('#dtSearchResult')[0]);
}
})
},
"aoColumns": [{
"mDataProp": "C_UID"
}, {
"mDataProp": "C_LAST_NAME"
}, {
"mDataProp": "C_FIRST_NAME"
}, {
"mDataProp": "C_USER_ID"
}, {
"mDataProp": "C_EMAIL"
}, {
"mDataProp": "C_COMPANY"
}],
"aoColumnDefs": [{ "defaultContent": "", "targets": "_all" },
//I create a link in 1 st column
]
});
There is some configuration that I am missing here. I read on datatable forums and the only issue highlighted by people was that draw should be same as what we send on server side.
For anyone looking for an answer to this. Sad but i had to write my own function as below:
function sortIconHandler(thArray, sortCol, sortDir) {
for (i = 0; i < thArray.length; i++) {
if (thArray[i].classList.contains('sorting_asc')) {
thArray[i].classList.remove('sorting_asc');
thArray[i].classList.add("sorting");
}
else if (thArray[i].classList.contains('sorting_desc')) {
thArray[i].classList.remove('sorting_desc');
thArray[i].classList.add("sorting");
}
if (i == sortCol) {
if (sortDir == 'asc') {
thArray[i].classList.remove('sorting');
thArray[i].classList.add("sorting_asc");
}
else {
thArray[i].classList.remove('sorting');
thArray[i].classList.add("sorting_desc");
}
}
}
}
tharrray-> The array of all row headers(You can just write a jquery selector for this).
sortCol->Column on which sort is clicked (Datatable param iSortCol_0)
sortDir -> Sorting direction (Datatable param sSortDir_0)
I know this is an old thread, but make sure you don't have an .off() somewhere associated with the tables capture group in jQuery. I had a click event that (for some reason) I attached an off function to.. Took me 3 days to find it.

Run web server and the selenium server with Gulp + nightwatch.js

I'm trying to run some nightwatch.js e2e tests using Gulp.
At the moment I have to do the following:
Run the selenium server manually
Set the path of selenium-server-standalone-2.47.1.jar and phantomjs.exe
Run the web server manually
My gulp task looks as follows:
gulp.task("run-e2e-tests", function () {
return gulp.src('')
.pipe(nightwatch({
configFile: "nightwatch.json",
cliArgs: {
env: "phantomjs"
}
}));
});
My nightwatch.js configuration looks as follows:
{
"src_folders" : [
"bundle/e2e_test/"
],
"output_folder": false,
"selenium" : {
"start_process" : false,
"server_path" : "./selenium-binaries/selenium-server-standalone-2.47.1.jar"
},
"test_settings" : {
"default" : {
"silent": true,
"screenshots" : {
"enabled" : false
},
"desiredCapabilities": {
"browserName": "phantomjs",
"javascriptEnabled" : true,
"acceptSslCerts" : false
}
},
"phantomjs" : {
"desiredCapabilities": {
"browserName": "phantomjs",
"javascriptEnabled" : true,
"acceptSslCerts" : false,
"phantomjs.binary.path" : "phantomjs.exe"
}
},
"chrome" : {
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true,
"acceptSslCerts": false
}
}
}
}
If I change "start_process" to true I get the following error:
[17:10:04] Using gulpfile ~\Desktop\CPIC.UI.Web\gulpfile.js
[17:10:04] Starting 'run-e2e-tests'...
[17:10:04] log file
[17:10:04] Starting nightwatch...
[CPIC E2e Test] Test Suite
==========================
Running: CPIC integration
Error retrieving a new session from the selenium server
Error: connect ECONNREFUSED 127.0.0.1:4444
at Object.exports._errnoException (util.js:874:11)
at exports._exceptionWithHostPort (util.js:897:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1063:14)
Connection refused! Is selenium server started?
[17:10:06] 'run-e2e-tests' errored after 1.5 s
[17:10:06] Error in plugin 'gulp-nightwatch'
Message:
nightwatch exited with code 1
The e2e test run as expected but I would like to run both the web server and the selenium server from Gulp automatically as part of my CI process.
I got it to work! Basically if you install selenium and phantomjs via npm something is wrong so you have to manually download them and set the paths int the nightwatch.js configuration file:
{
"src_folders" : [
"bundle/e2e_test/"
],
"output_folder": false,
"selenium" : {
"start_process" : true,
"server_path" : "./selenium-binaries/selenium-server-standalone-2.47.1.jar"
},
"test_settings" : {
"default" : {
"silent": true,
"screenshots" : {
"enabled" : false
},
"desiredCapabilities": {
"browserName": "phantomjs",
"javascriptEnabled" : true,
"acceptSslCerts" : false
}
},
"phantomjs" : {
"desiredCapabilities": {
"browserName": "phantomjs",
"javascriptEnabled" : true,
"acceptSslCerts" : false,
"phantomjs.binary.path" : "./selenium-binaries/phantomjs.exe"
}
}
}
}
To run the web server and kill it I used 3 tasks ans run-sequence:
gulp.task("run-e2e-tests", function (cb) {
runSequence(
"run-http-server",
"run-nightwatch",
"kill-http-server",
cb);
});
gulp.task("run-nightwatch", function () {
return gulp.src('')
.pipe(nightwatch({
configFile: "nightwatch.json",
cliArgs: {
env: "phantomjs"
}
}));
});
gulp.task("run-http-server", function () {
return connect.server({
port: 8888
});
});
gulp.task("kill-http-server", function () {
return connect.serverClose();
});