'Connection refused! Is selenium server started?\n' while running Nightwatch.js tests against Selenium Grid - selenium

I use Nightwatch-Cucumber based on Nightwatch.js to automate my tests. And now I want to use Selenium Grid with a Selenium hub and several Selenium nodes to execute my tests.
These are my current dependencies I actually use:
"devDependencies": {
"chromedriver": "2.37.0",
"cucumber": "3.0.2",
"geckodriver": "1.11.0",
"nightwatch": "0.9.19",
"nightwatch-cucumber": "9.0.0",
"selenium-server-standalone-jar": "3.9.1",
},
And this is my nightwatch.conf.js:
const config = {
globals_path: "globals.js",
output_folder: "reports",
custom_commands_path: "commands",
// custom_assertions_path: 'assertions',
live_output: false,
page_objects_path: "pageobjects",
disable_colors: false,
selenium: {
start_process: true,
server_path: seleniumServer.path,
host: "127.0.0.1",
port: 4444
},
test_settings: {
default: {
launch_url: "http://mywebsite.com"
},
firefox_grid: {
selenium_host: "127.0.0.1",
selenium_port: 4444,
desiredCapabilities: {
browserName: "firefox"
}
selenium: {
start_process: false
}
}
}
};
module.exports = config;
So, and these are the steps I executed to realize everything:
1. Start the Selenium Hub on localhost
java -jar selenium-server-standalone-3.9.1.jar -port 4444 -role hub
2. Start the Selenium Node on localhost
java -jar selenium-server-standalone-3.9.1.jar -port 5555 -role node
3. Start the Nightwatch tests
./node_modules/.bin/nightwatch --env firefox_grid --tag=myCucumberTag
Current result:
I get an error while executing the Nightwatch tests and I don't know why. It looks like this:
{ Error: Unhandled "error" event. ([object Object])
at ClientManager.emit (events.js:185:19)
at Nightwatch.<anonymous> (/Users/GRme/projects/Aservo/DP/lcm2/testautomation/end2end-web-tests/node_modules/nightwatch/lib/runner/clientmanager.js:68:10)
at Object.onceWrapper (events.js:316:30)
at emitOne (events.js:115:13)
at Nightwatch.emit (events.js:210:7)
at HttpRequest.<anonymous> (/Users/GRme/projects/Aservo/DP/lcm2/testautomation/end2end-web-tests/node_modules/nightwatch/lib/index.js:501:10)
at emitThree (events.js:135:13)
at HttpRequest.emit (events.js:216:7)
at IncomingMessage.<anonymous> (/Users/GRme/projects/Aservo/DP/lcm2/testautomation/end2end-web-tests/node_modules/nightwatch/lib/http/request.js:172:16)
at emitNone (events.js:110:20)
at IncomingMessage.emit (events.js:207:7)
at endReadableNT (_stream_readable.js:1057:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
context:
{ message: 'Connection refused! Is selenium server started?\n',
data: { value: [Object], status: 33 } } }
The request to the Selenium hub seems to be successful from Nightwatch:
21:50:52.393 INFO - Got a request to create a new session: Capabilities {acceptSslCerts: true, browserName: chrome, javascriptEnabled: true}
21:50:52.399 INFO - Trying to create a new session on test slot {seleniumProtocol=WebDriver, se:CONFIG_UUID=037e48a7-b5bc-44f2-a25b-e85c752095a7, browserName=chrome, maxInstances=5, platformName=MAC, platform=MAC}
And the request also was navigated to the Selenium node:
2018-05-03 21:50:52.418:INFO:osjshC.ROOT:qtp1300393335-22: org.openqa.selenium.remote.server.WebDriverServlet-49d904ec: Initialising WebDriverServlet
21:50:52.450 INFO - Found handler: org.openqa.selenium.remote.server.commandhandler.BeginSession#31a65f95
21:50:52.454 INFO - /session: Executing POST on /session (handler: BeginSession)
21:50:52.546 INFO - Capabilities are: Capabilities {acceptSslCerts: true, browserName: chrome, javascriptEnabled: true}
21:50:52.548 INFO - Capabilities {acceptSslCerts: true, browserName: chrome, javascriptEnabled: true} matched class org.openqa.selenium.remote.server.ServicedSession$Factory (provider: org.openqa.selenium.chrome.ChromeDriverService)
So, what I'm doing wrong and how can I fix it? Is it maybe a problem with the Nightwatch.js and/or Selenium Server Standalone Version?

This error message...
message: 'Connection refused!
...implies that the Selenium Grid Node was unable to initiate/spawn a new WebClient i.e. Web Browsing session.
Your main issue is in the command being used to start / initialize Selenium Grid Node. The Selenium Grid Node should be started with the desired WebDriver variant as an argument as follows :
Start the Selenium Grid Hub (default on port 4444):
java -jar selenium-server-standalone-3.9.1.jar -role hub
Start the Selenium Grid Node (default on port 5555):
java -Dwebdriver.chrome.driver=C:/path/to/chromedriver.exe -jar selenium-server-standalone-3.9.1.jar -role node -hub http://localhost:4444/grid/register
You can find a similar detailed discussion in Connection refused! Is selenium server started nightwatch on edge

Related

How to launch protractor tests from remote jenkins?

I am unable to launch my protractor test from remote jenkins.
I am able to launch the test if the jenkins is installed in my local.
I am not sure if it is because of the direct connect. i also tried to launch the protractor test through selenium webdriver but couldnt make it. please help on this.
The error i am getting is
*[16:06:14] I/launcher - Running 1 instances of WebDriver
[16:06:14] I/direct - Using ChromeDriver directly...
[16:16:15] E/launcher - session not created
from timeout: Timed out receiving message from renderer: 600.000
(Session info: chrome=88.0.4324.104)
(Driver info: chromedriver=88.0.4324.96 (68dba2d8a0b149a1d3afac56fa74648032bcf46b-refs/branch-heads/4324#{#1784}),platform=Windows NT 10.0.17763 x86_64)
[16:16:15] E/launcher - SessionNotCreatedError: session not created
from timeout: Timed out receiving message from renderer: 600.000
(Session info: chrome=88.0.4324.104)
(Driver info: chromedriver=88.0.4324.96 (68dba2d8a0b149a1d3afac56fa74648032bcf46b-refs/branch-heads/4324#{#1784}),platform=Windows NT 10.0.17763 x86_64)
at Object.checkLegacyResponse (C:\home\Administrator\workspace\BlueNet_Automation\node_modules\selenium-webdriver\lib\error.js:546:15)
at parseHttpResponse (C:\home\Administrator\workspace\BlueNet_Automation\node_modules\selenium-webdriver\lib\http.js:509:13)
at C:\home\Administrator\workspace\BlueNet_Automation\node_modules\selenium-webdriver\lib\http.js:441:30
at processTicksAndRejections (internal/process/task_queues.js:93:5)
From: Task: WebDriver.createSession()
at Function.createSession (C:\home\Administrator\workspace\BlueNet_Automation\node_modules\selenium-webdriver\lib\webdriver.js:769:24)
at Function.createSession (C:\home\Administrator\workspace\BlueNet_Automation\node_modules\selenium-webdriver\chrome.js:761:15)
at Direct.getNewDriver (C:\home\Administrator\workspace\BlueNet_Automation\node_modules\protractor\built\driverProviders\direct.js:77:33)
at Runner.createBrowser (C:\home\Administrator\workspace\BlueNet_Automation\node_modules\protractor\built\runner.js:195:43)
at C:\home\Administrator\workspace\BlueNet_Automation\node_modules\protractor\built\runner.js:339:29
at _fulfilled (C:\home\Administrator\workspace\BlueNet_Automation\node_modules\q\q.js:834:54)
at C:\home\Administrator\workspace\BlueNet_Automation\node_modules\q\q.js:863:30
at Promise.promise.promiseDispatch (C:\home\Administrator\workspace\BlueNet_Automation\node_modules\q\q.js:796:13)
at C:\home\Administrator\workspace\BlueNet_Automation\node_modules\q\q.js:556:49
at runSingle (C:\home\Administrator\workspace\BlueNet_Automation\node_modules\q\q.js:137:13)
[16:16:15] E/launcher - Process exited with error code 199
npm ERR! Test failed. See above for more details.
Build step 'Execute Windows batch command' marked build as failure
Finished: FAILURE*
my config.ts file is
*export let config: Config = {
// The address of a running selenium server.
//seleniumAddress: 'http://localhost:4444/wd/hub',
directConnect:true,
framework:'custom',
frameworkPath: require.resolve('protractor-cucumber-framework'),
//allScriptsTimeout: 30000,
// Capabilities to be passed to the webdriver instance.
capabilities: {
browserName: 'chrome'
},
// Spec patterns are relative to the configuration file location passed
// to protractor (in this example conf.js).
// They may include glob patterns.
specs: ['../features/MasterEdit.feature'],
cucumberOpts: {
// require step definitions
//tags:"#SmokeTesting",
format:'json:./cucumberreport.json',
require: [
'./stepDefinitions/*.js', // accepts a glob,
]
},
onComplete: () =>{
var options = {
theme: 'bootstrap',
jsonFile: './cucumberreport.json',
output: './cucumber_report.html',
reportSuiteAsScenarios: true,
launchReport: true,
metadata: {
"App Version":"0.3.2",
"Test Environment": "STAGING",
"Browser": "Chrome 54.0.2840.98",
"Platform": "Windows 10",
"Parallel": "Scenarios",
"Executed": "Remote"
}
};
reporter.generate(options);
}*

How to run successfully Protractor e2e test in Cloud Builders?

I'm setting up CI for our project that is in Angular. We are using Google Cloud Platform's Cloud Builder for CI. Everything is going smoothly, we can setup the environment, install packages via npm, build the project using angular-cli and deploy. But the problem is that our test cases (e2e) in Protractor keeps getting an error. What are we missing here?
This is for the Continuous Integration using Google Cloud Builders, we are running the protractor in headless mode, and using the puppeteer's chromium as the chrome's binary path
This is my protractor.conf.js
// Protractor configuration file, see link for more information
// https://github.com/angular/protractor/blob/master/lib/config.ts
const { SpecReporter } = require('jasmine-spec-reporter');
const puppeteer = require('puppeteer');
process.env.CHROME_BIN = puppeteer.executablePath()
exports.config = {
allScriptsTimeout: 1000000,
specs: [
'./e2e/*.e2e-spec.ts',
'../e2e/*.e2e-spec.ts'
],
capabilities: {
// browserName: 'chrome',
browserName: 'chrome',
chromeOptions: {
binary: process.env.CHROME_BIN,
args: ['--headless', '--disable-gpu', '--no-sandbox', '--disable-extensions', '--disable-dev-shm-usage', '--disable-setuid-sandbox']
}
},
// seleniumAddress: 'http://127.0.0.1:4444/wd/hub',
// ignoreUncaughtExceptions: true,
directConnect: true,
},
};
This is the error we are getting in cloud builders
[11:24:12] E/launcher - unknown error: Chrome failed to start: exited abnormally
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /workspace/node_modules/puppeteer/.local-chromium/linux-662092/chrome-linux/chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
(Driver info: chromedriver=2.44.609551 (5d576e9a44fe4c5b6a07e568f1ebc753f1214634),platform=Linux 4.15.0-1033-gcp x86_64)
[11:24:12] E/launcher - WebDriverError: unknown error: Chrome failed to start: exited abnormally
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /workspace/node_modules/puppeteer/.local-chromium/linux-662092/chrome-linux/chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

Protractor test with headless Selenium Webdriver randomly times out

I am having intermittent failures when running Selenium headless in my
server using xvfb. It works most of the times, but ~10% of runs it fails with this message:
[06:35:05] I/direct - Using FirefoxDriver directly...
[06:35:05] I/launcher - Running 1 instances of WebDriver
/opt/e2e/node_modules/protractor/node_modules/selenium-webdriver/http/util.js:83
Error('Timed out waiting for the WebDriver server at ' + url));
^
Error: Timed out waiting for the WebDriver server at http://127.0.0.1:54389/hub
at Error (native)
at onError (/opt/e2e/node_modules/protractor/node_modules/selenium-webdriver/http/util.js:83:11)
at Promise.invokeCallback_ (/opt/e2e/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:1329:14)
at TaskQueue.execute_ (/opt/e2e/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2790:14)
at TaskQueue.executeNext_ (/opt/e2e/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2773:21)
at /opt/e2e/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2652:27
at /opt/e2e/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:639:7
at process._tickCallback (node.js:368:9)
From: Task: WebDriver.createSession()
at acquireSession (/opt/e2e/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver.js:62:22)
at Function.createSession (/opt/e2e/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver.js:295:12)
at Driver (/opt/e2e/node_modules/protractor/node_modules/selenium-webdriver/firefox/index.js:271:38)
at Direct.getNewDriver (/opt/e2e/node_modules/protractor/built/driverProviders/direct.js:71:26)
at Runner.createBrowser (/opt/e2e/node_modules/protractor/built/runner.js:182:43)
at /opt/e2e/node_modules/protractor/built/runner.js:255:30
at _fulfilled (/opt/e2e/node_modules/protractor/node_modules/q/q.js:834:54)
at self.promiseDispatch.done (/opt/e2e/node_modules/protractor/node_modules/q/q.js:863:30)
at Promise.promise.promiseDispatch (/opt/e2e/node_modules/protractor/node_modules/q/q.js:796:13)
at /opt/e2e/node_modules/protractor/node_modules/q/q.js:556:49
[06:35:51] E/launcher - Process exited with error code 1
I am running Selenium Webdriver 2.53.0
My config (using Mozilla Firefox 46.0.1):
exports.config = {
framework: 'jasmine2',
directConnect: true,
specs: ['specs/*.js'],
capabilities: {
browserName: 'firefox'
},
jasmineNodeOpts: {
defaultTimeoutInterval: 40000,
showColors: false
}
};
Test is just opening a browser:
describe('Home page flow test', function() {
it('should load home page', function() {
browser.get('https://www.google.com');
});
});
I am running Protractor with this command:
xvfb-run --server-args="-screen 0 1024x768x24" protractor --verbose
Thanks!

Protractor : ERROR - Unable to start a WebDriver session

I wrote test cases three months back at that time they worked fine now i want to run those test cases in another system so i did basic setup. When i try to run protractor test case now they are failing with 'Unable to start a WebDriver session'. I have tried so many solutions but they didn't work for me.
Here i am attaching my protractor.conf.js file and error details.
protractor.conf.js
'use strict';
exports.config = {
seleniumAddress: 'http://127.0.0.1:4444/wd/hub',
baseUrl: 'http://localhost:' + (process.env.PORT || '3036'),
chromeOnly: true,
// To get the maximimum test screen size
onPrepare: function() {
browser.driver.manage().window().maximize();
},
// list of files / patterns to load in the browser
specs: [
'e2e/attributeSection/search_spec.js', 'e2e/attributeSection/create_spec.js',
'e2e/attributeSection/edit_spec.js', 'e2e/attribute/search_spec.js',
'e2e/attribute/create_spec.js', 'e2e/attribute/edit_spec.js',
'e2e/classification/search_spec.js', 'e2e/classification/create_spec.js',
'e2e/classification/edit_spec.js', 'e2e/classificationGroup/create_spec.js',
'e2e/classificationGroup/edit_spec.js'
],
exclude: [],
capabilities: {
'browserName': 'chrome',
'chromeOptions': {
binary: 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe',
args: [],
extensions: [],
}
},
framework: 'jasmine',
jasmineNodeOpts: {
defaultTimeoutInterval: 60000
}
};
Error in console
Using the selenium server at http://127.0.0.1:4444/wd/hub
[launcher] Running 1 instances of WebDriver
ERROR - Unable to start a WebDriver session.
C:\Users\Cronj- 4\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\http\index.js:145
callback(new Error(message));
^
Error: ECONNREFUSED connect ECONNREFUSED
at ClientRequest.<anonymous> (C:\Users\Cronj-4\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\http\index.js:145:16)
at ClientRequest.emit (events.js:95:17)
at Socket.socketErrorListener (http.js:1552:9)
at Socket.emit (events.js:95:17)
at net.js:441:14
at process._tickCallback (node.js:442:13)
From: Task: WebDriver.createSession()
at Function.webdriver.WebDriver.acquireSession_ (C:\Users\Cronj-4\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\webdriver.js:155:22)
at Function.webdriver.WebDriver.createSession (C:\Users\Cronj-4\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\webdriver.js:129:30)
at [object Object].Builder.build (C:\Users\Cronj-4\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\builder.js:416:22)
at [object Object].DriverProvider.getNewDriver (C:\Users\Cronj-4\AppData\Roaming\npm\node_modules\protractor\lib\driverProviders\driverProvider.js:38:7)
at [object Object].Runner.createBrowser (C:\Users\Cronj-4\AppData\Roaming\npm\node_modules\protractor\lib\runner.js:180:37)
at C:\Users\Cronj-4\AppData\Roaming\npm\node_modules\protractor\lib\runner.js:257:21
at _fulfilled (C:\Users\Cronj-4\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:797:54)
at self.promiseDispatch.done (C:\Users\Cronj-4\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:826:30)
at Promise.promise.promiseDispatch (C:\Users\Cronj-4\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:759:13)
Could anyone help me out? Thanks in advance
I believe the "chromeOnly" option got deprecated in v2.0.0.
chromeOnly: true,
This used to mean use "direct" mode without a selenium server. But since both firefox and chrome support direct mode, the property was renamed to "directConnect". So change that line to:
directConnect: true,
In this mode you don't need a selenium server, so you can drop the seleniumAddress property which is just confusing folks.
See https://github.com/angular/protractor/pull/1933/files
I ran webdriver-manager start in one command prompt and protractor in another command prompt then only test cases started running

WebDriver grid configuration throws error

I have the following setup:
I am running a grid hub on my local pc with the following config:
java -jar selenium-server-standalone-2.42.0.jar -role hub -grid1Yml grid_configuration.yml
the config looks like this:
hub:
port: 4444
remoteControlPollingIntervalInSeconds: 180
sessionMaxIdleTimeInSeconds: 300
newSessionMaxWaitTimeInSeconds: 600
environments:
- name: "Firefox on Windows"
browser: "*firefox"
...
I am starting the node via
java -jar selenium-server -standalone-2.42.0.jar -role node -hub http://localhost:4444/grid/register -port 8888 -browser "browserName=Firefox on windows,maxInstances=1,version=1,platform=WINDOWS"
My Test setup looks like this:
public static void main(String[] args) throws MalformedURLException {
System.setProperty("webdriver.ie.driver","C:\\IEDriverServer.exe");
DesiredCapabilities cap = DesiredCapabilities.firefox();
cap.setBrowserName("*firefox");
RemoteWebDriver remoteWebDriver = new RemoteWebDriver(new URL("http://127.0.0.1:4444" + "/wd/hub"), cap);
}
If i run my test i get the following error:
Exception in thread "main" org.openqa.selenium.WebDriverException: Error forwarding
the new session webdriver new session JSON response body did not contain a session ID
Command duration or timeout: 946 milliseconds
Build info: version: '2.41.0', revision: '3192d8a6c4449dc285928ba024779344f5423c58', time: '2014-03-27 11:29:39'
System info: host: 'CL-CNU416C97F', ip: '10.11.112.158', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_55'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
In the webdriver node i get the important error:
Exception: The path to the driver executable must be set by the webdriver.ie.driver system property...
I have set this property via java and in my windows environment. I do not know why i am still getting this error message.
UPDATE
If i use the grid2 config file (json), how is it possible to set an individual browser by name on each host.
Example:
hub:
port: 4444
remoteControlPollingIntervalInSeconds: 180
sessionMaxIdleTimeInSeconds: 300
newSessionMaxWaitTimeInSeconds: 600
environments:
- name: "MyFireFox on MyMachine1"
browser: "*firefox"
- name: "MyFireFox on MyMachine2"
browser: "*firefox"
If i use this hub config i can start a node by saying it is a "MyFireFox on MyMachine1" Browser. The attribute browser is telling webdriver to use Firefox on the system
If i now use the grid2 config json, i have the following
{
"capabilities":
[
{
"browserName": "MyFireFox on MyMachine1",
"platform": "WINDOWS",
"maxInstances": 1
},
but this will not work, because i think the browserName is what browser was in grid1 config.
this is config from my .bat files. also, why do you change your node port to 8888 ? try to remove '-port 8888' and check again
for hub:
java -jar path_to_selenium-server-standalone-2.41.0.jar -role hub
for node:
java -jar path_to_selenium-server-standalone-2.41.0.jar -role node -hub http://localhost:4444/grid/register -browser browserName=firefox, platform=WINDOWS
here is my json and bat file which 100% works
{
"capabilities":
[
{
"browserName": "firefox",
"platform": "WINDOWS",
"maxInstances": 1
},
{
"browserName": "internet explorer",
"version": "10",
"platform": "WINDOWS",
"maxInstances": 1
}
],
"configuration":
{
"nodeTimeout":120,
"port":5555,
"hubPort":4444,
"hubHost":"192.168.3.104",
"nodePolling":2000,
"registerCycle":10000,
"register":true,
"cleanUpCycle":2000,
"timeout":30000,
"maxSession":1
}
}
and bat to start node from json
java -jar selenium-server-standalone-2.41.0.jar -role node -nodeConfig nodeConfig_win7.json
also in system PATH you should add path to folder with drivers for browsers