First, I start Selenium:
nohup java -jar selenium/selenium-server-standalone-2.47.1.jar -role hub -port 4455&
Then add PhantomJS driver:
nohup phantomjs --webdriver=8080 --webdriver-selenium-grid-hub=http://127.0.0.1:4455&
Output in nohup.out looks... successful?:
13:22:52.127 INFO - Launching Selenium Grid hub
2015-12-07 13:22:52.789:INFO:osjs.Server:jetty-7.x.y-SNAPSHOT
2015-12-07 13:22:52.833:INFO:osjsh.ContextHandler:started o.s.j.s.ServletContextHandler{/,null}
2015-12-07 13:22:52.845:INFO:osjs.AbstractConnector:Started SocketConnector#0.0.0.0:4455
13:22:52.846 INFO - Nodes should register to http://192.168.10.67:4455/grid/register/
13:22:52.846 INFO - Selenium Grid hub is up and running
PhantomJS is launching GhostDriver...
[INFO - 2015-12-07T13:22:56.097Z] GhostDriver - Main - running on port 8080
[INFO - 2015-12-07T13:22:56.097Z] GhostDriver - Main - registering to Selenium HUB 'http://127.0.0.1:4455' using '127.0.0.1:8080'
13:22:56.177 INFO - Registered a node http://127.0.0.1:8080
[INFO - 2015-12-07T13:22:56.184Z] HUB Register - register - Registered with grid hub: http://127.0.0.1:4455/ (ok)
versions in package.json include:
"devDependencies": {
"grunt": "^0.4.5",
"grunt-nightwatch": "^0.4.8",
"phantomjs": "^1.9.19"
},
My Grunt task config for Nightwatch looks like:
module.exports = {
options: { // default
standalone: false,
globals_path: 'test/globals.js',
custom_commands_path: 'test/commands',
custom_assertions_path: 'test/asserts',
page_objects_path: 'test/pages',
src_folders: ['test/specs'],
output_folder: 'test/report',
test_settings: {
"default": {
"desiredCapabilities": {
"browserName": "firefox"
}
},
"firefox": {
"desiredCapabilities": {
"browserName": "firefox"
}
},
"chrome": {
"desiredCapabilities": {
"browserName": "chrome"
}
},
"phantomjs": {
"desiredCapabilities": {
"browserName": "phantomjs",
"javascriptEnabled": true,
"acceptSslCerts": true,
"phantomjs.binary.path": "node_modules/phantomjs/bin"
}
}
},
selenium: {
"start_process": false
}
}
};
At this point I can:
grunt nightwatch:phantomjs
Which gives me:
Connection refused! Is selenium server started?
What's wrong? How do I debug it? Is it something to do with it saying nodes should register to 192.168.10.67 (my machine's local network IP), but GhostDriver is registering to 127.0.0.1 ?
I think the problem is this line:
selenium: {
"start_process": false
}
that should be changed to:
selenium: {
"start_process": true
}
In your Grunt task config for Nightwatch.This will start the Selenium process automatically when runnning the tests. If this is set to false you have to start the Selenium process manually.
Related
When I run the test, Opera opens, but the test does not run and an error falls into the console
[Facebook\WebDriver\Exception\SessionNotCreatedException] Unable to create session from {
"desiredCapabilities": {
"browserName": "opera"
},
"capabilities": {
"firstMatch": [
{
"browserName": "opera"
}
]
}
}
Driver info: driver.version: unknown
I start the server with this command:
java "-Dwebdriver.opera.driver=C:\Users\user\Desktop\Auto\qa-tests\Codeception\operadriver.exe" -jar "C:\Users\user\Desktop\Auto\qa-tests\Codeception\selenium-server-standalone-3.14.0.jar"
My acceptance.suite.yaml
opera:
modules:
config:
PhpBrowser:
url: 'https://sample.com/'
WebDriver:
url: 'https://samlpe.com/'
window_size: 1900x1080 # for fullscreen shots
port: 17570
browser: opera # 'chrome' or 'firefox' java "-Dwebdriver.opera.driver=C:\Users\user\Desktop\Auto\qa-tests\Codeception\operadriver.exe" -jar "C:\Users\user\Desktop\Auto\qa-tests\Codeception\selenium-server-standalone-3.14.0.jar" -port 17570 - для MicrosoftEdge
#capabilities:
args: [ '--no-sandbox' ]
I have been attempting to setup an automated testing framework for my job, and nodejs testing has seemed to be the best option for future scalability. Plus, I am attempting to stretch myself into new areas of QA.
I have setup my Nightwatch framework with npm install commands and manually installed the most up-to-date chrome drivers, and selenium standalone executables. I have attempted to ensure that my nightwatch.conf.js file is completely setup to run my first test with google chrome, but I get this error:
⚠ Error connecting to localhost on port 4444.
_________________________________________________
TEST FAILURE: 1 error during execution; 0 tests failed, 0 passed (249ms)
✖ GoogleTest
An error occurred while retrieving a new session
Error: An error occurred while retrieving a new session
at endReadableNT (internal/streams/readable.js:1327:12)
at processTicksAndRejections (internal/process/task_queues.js:80:21)
Error: An error occurred while retrieving a new session
at endReadableNT (internal/streams/readable.js:1327:12)
at processTicksAndRejections (internal/process/task_queues.js:80:21)
SKIPPED:
- Basic Google search
Which seems to be pretty generic. As per normal Nightwatch setup, I created a root folder called 'Automation' where I stuck my bin folder for the drivers and selenium framework. Inside of the 'Automation' folder I also have my nightwatch.conf.js file that I've setup (Let me know if its more helpful if I paste its code in here). In order to run my test, I use the npx nightwatch command, but I continue to get this error.
From what I can tell it may be due to me trying to run the tests locally, but I can't think of a way that I would configure the selenium service to accept local ports other than how it's been setup.
I don't know if this is a well formatted description of the problem, so I apologize in advance if this is super vague. If there's anything else I can do to help clear it up let me know.
Thank you!
Update Conf.js File
// Autogenerated by Nightwatch
// 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: ["tests"],
// See https://nightwatchjs.org/guide/working-with-page-objects/
page_objects_path: '',
// 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 : '',
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: (Services.chromedriver ? Services.chromedriver.path : '.Automation/bin/chromedriver.exe')
}
},
safari: {
desiredCapabilities : {
browserName : 'safari',
alwaysMatch: {
acceptInsecureCerts: false
}
},
webdriver: {
port: 4444,
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,
port: 4444,
server_path: (Services.geckodriver ? Services.geckodriver.path : './Automation/bin/geckodriver.exe'),
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: true,
//More info on Chromedriver: https://sites.google.com/a/chromium.org/chromedriver/
args: ['disable-gpu', 'no-sandbox', 'headless']
}
},
webdriver: {
start_process: true,
port: 9515,
server_path: (Services.chromedriver ? Services.chromedriver.path : './Automation/bin/chromedriver.exe'),
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: true,
args: ['disable-gpu', 'no-sandbox', 'headless']
}
}
},
'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 : './Automation/bin/selenium-server-standalone-3.141.59.jar'),
cli_args: {
'webdriver.gecko.driver': (Services.geckodriver ? Services.geckodriver.path : './Automation/bin/geckodriver.exe'),
'webdriver.chrome.driver': (Services.chromedriver ? Services.chromedriver.path : './Automation/bin/chromedriver.exe')
}
}
},
'selenium.chrome': {
extends: 'selenium',
desiredCapabilities: {
browserName: 'chrome',
chromeOptions : {
w3c: true,
args: ['disable-gpu', 'no-sandbox', 'headless']
}
}
},
'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) {}
}
What I will suggest is to create a create a new file for Nightwatch.conf.js and then start adding rest of the configuration from there. Below is an example which works for me:
module.exports = {
src_folders: ["tests"],
skip_testcases_on_fail: false,
page_objects_path: "pageObjects",
custom_commands_path: "./commands",
screenshots: {
enabled: true,
path: "./screenshots",
on_failure: true,
on_error: true
},
test_settings: {
default: {
desiredCapabilities: {
browserName: 'chrome',
chromeOptions: {
prefs: {
download: {
default_directory: require('path').resolve(__dirname + '/download')
}
}
},
},
webdriver: {
start_process: true,
port: 4444,
server_path: require('chromedriver').path,
}
},
test_workers: {
enabled: true,
workers: 'auto'
},
safari: {
desiredCapabilities: {
browserName: 'safari',
alwaysMatch: {
acceptInsecureCerts: false
}
},
webdriver: {
port: 4445,
start_process: true,
server_path: '/usr/bin/safaridriver'
}
},
firefox: {
desiredCapabilities: {
browserName: 'firefox'
},
webdriver: {
start_process: true,
port: 4446,
server_path: require('geckodriver').path
}
}
}
}
The Nightwatch JS, chromedriver, geckodriver are installed using the npm commands. Since I am using a mac I just needed to enable the safari webdriver.
npm install nightwatch --save-dev
npm install geckodriver --save-dev
npm install chromedriver --save-dev
safaridriver --enable
This is the full repo if you want to have a look: https://github.com/alapanme/NightwatchJS
Also if you need the detailed steps how I setup Nightwatch on my machine you can refer: https://testersdock.com/nightwatch-js-installation/
I am trying to run e2e tests for chrome and firefox and I am unable to load the chrome browser with following configuration ,any comment is much appreciated , thanks
var HtmlReporter = require('protractor-beautiful-reporter');
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: [ **some spec**
],
multiCapabilities: [{
"browserName": "firefox"
},
{
"browserName": "chrome",
}
],
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 180000
},
allScriptsTimeout: 200000,
onPrepare: function () {
browser.manage().timeouts().implicitlyWait(20000);
jasmine.getEnv().addReporter(new HtmlReporter({
baseDirectory: 'test-result',
preserveDirectory: false,
takeScreenShotsOnlyForFailedSpecs: true,
screenshotsSubfolder: 'images'
}).getJasmine2Reporter());
}
};
try directConnect: true instead of using seleniumAddress: http://localhost:4444/wd/hub
or make sure your grid server is up and running and also selenium server is up and running
command to start selenium server webdriver-manager start
We are trying to execute Protractor tests in CentOS 7 vm in headless mode using chromedriver.
Versions:
Protractor- 5.4.0
Node - v6.14.3
cucumber-js - 4.2.1
Google Chrome version - Google Chrome 68.0.3440.84
Webdriver-manager running and showing following information
[bpmuser#bg-bpm-qa-jbpm6 ~]$ ps -eaf | grep java
root 3692 3685 5 17:19 pts/0 00:00:01 java -
Djava.security.egd=file:///dev/./urandom -Dwebdriver.chrome.driver=/usr/lib/node_modules/protractor/node_modules/webdriver-manager/selenium/chromedriver_2.41 -Dwebdriver.gecko.driver=/usr/lib/node_modules/protractor/node_modules/webdriver-manager/selenium/geckodriver-v0.21.0 -jar /usr/lib/node_modules/protractor/node_modules/webdriver-manager/selenium/selenium-server-standalone-3.14.0.jar -port 4444
protractor.conf.js:
var Cucumber = require("./node_modules/cucumber");
var { defineSupportCode } = require("./node_modules/cucumber");
var reporter = require('./node_modules/cucumber-html-reporter');
var report = require("./node_modules/cucumber-html-report");
var cucumberReportOptions = {
source: './reports/results.json',
dest: './reports/results',
name: "report_detailed.html",
title: "CDocs Automation Report",
};
var cucumberReporteroptions = {
theme: 'Bootstrap',
jsonFile: './reports/results.json',
output: './reports/results/report.html',
screenshotsDirectory: './reports/screenshots/',
storeScreenshots: true,
reportSuiteAsScenarios: true,
launchReport: false,
metadata: {
"App Version":"Angular 2.0",
"Test Environment": "QA",
"Browser": "Chrome",
"Platform": process.platform,
//"Parallel": "Scenarios",
"Scenarios" : "TestCases",
"Executed": "Local"
}
};
exports.config = {
//directConnect: true,
useAllAngular2AppRoots: true,
seleniumAddress: 'http://127.0.0.1:4444/wd/hub',
getPageTimeout: 60000,
allScriptsTimeout: 500000,
framework: "custom",
// path relative to the current config file
frameworkPath: require.resolve('./node_modules/protractor-cucumber- framework'),
//restartBrowserBetweenSuites: true,
capabilities: {
browserName: 'chrome',
chromeOptions: {
args: [ 'headless' ]
},
acceptSslCerts: true,
},
// Spec patterns are relative to this directory.
specs: ['./features/ChangeView.feature',
],
//baseURL: 'http://localhost:8080/',
onPrepare: function () {
browser.baseUrl = "http://localhost:8080/";
},
onComplete: () => {
reporter.generate(cucumberReporteroptions); //invoke cucumber-html-reporter
report
.create(cucumberReportOptions)
.then(function() {
//invoke cucumber-html-report
// creating two reports(optional) here, cucumber-html-report gives
directory already exists as cucumber-html-reporter already creates the html dir!
// suggestion- use either one of the reports based on your needs
console.log("cucumber_report.html created successfully!");
})
},
cucumberOpts: {
format: ['json:reports/results.json', 'pretty'],
require: ['./features/step_definitions/content_step_definitions.js'],
tags: true,
profile: false,
'no-source': true
}
};
However, running Protractor still does not work:
[bpmuser#bg-bpm-qa-jbpm6 bin]$ pwd
/usr/lib/node_modules/protractor/bin
[bpmuser#bg-bpm-qa-jbpm6 bin]$ ./protractor /home/bpmuser/docs/CDocsAutomation/protractor.conf.js
[18:10:33] I/launcher - Running 1 instances of WebDriver
[18:10:33] I/hosted - Using the selenium server at http://127.0.0.1:4444/wd/hub
Its not progressing after this step. Not sure where i am doing wrong.
Try using this in your config
capabilities: {
browserName: 'chrome',
chromeOptions: {
args: [ "--headless", "--disable-gpu", "--window-size=800,600" ]
}
}
hope this helps
I have generated a VueJS project using vue-cli, including end to end tests with Nightswatch.js.
I'm using the following .gitlab-ci.yml file
services:
- selenium/standalone-chrome
stages:
- test
- pages
test:
image: node:6.11
stage: test
before_script:
- node -v
- npm -v
script:
- npm install
- npm test
pages:
image: node:6.11
stage: pages
before_script:
- node -v
- npm -v
script:
- npm install
- npm run build
- cp -R ./dist ./public
- cd ./public
- ls
artifacts:
paths:
- public
only:
- master
This is the nightswatch.conf.js file
require('babel-register')
var config = require('../../config')
// http://nightwatchjs.org/gettingstarted#settings-file
module.exports = {
src_folders: ['test/e2e/specs'],
output_folder: 'test/e2e/reports',
custom_assertions_path: ['test/e2e/custom-assertions'],
selenium: {
start_process: true,
server_path: require('selenium-server').path,
host: '127.0.0.1',
port: 4444,
cli_args: {
'webdriver.chrome.driver': require('chromedriver').path
}
},
test_settings: {
default: {
selenium_port: 4444,
selenium_host: 'localhost',
silent: true,
globals: {
devServerURL: 'http://localhost:' + (process.env.PORT || config.dev.port)
}
},
chrome: {
desiredCapabilities: {
browserName: 'chrome',
javascriptEnabled: true,
acceptSslCerts: true
}
},
firefox: {
desiredCapabilities: {
browserName: 'firefox',
javascriptEnabled: true,
acceptSslCerts: true
}
}
}
}
In Gitlab-CI, the job passes but looking at the log only the unit tests are passing, not the end to end tests.
> node test/e2e/runner.js
Starting selenium server...
An error occurred while trying to start Selenium. Check if JAVA is installed on your machine.
{ Error: spawn java ENOENT
at exports._errnoException (util.js:1020:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:197:32)
at onErrorNT (internal/child_process.js:376:16)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickCallback (internal/process/next_tick.js:104:9)
at Module.runMain (module.js:606:11)
at run (bootstrap_node.js:383:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:496:3
code: 'ENOENT',
errno: 'ENOENT',
syscall: 'spawn java',
path: 'java',
spawnargs:
[ '-Dwebdriver.chrome.driver=/builds/Overdrivr/frontend/node_modules/chromedriver/lib/chromedriver/chromedriver',
'-jar',
'/builds/Overdrivr/frontend/node_modules/selenium-server/lib/runner/selenium-server-standalone-3.8.1.jar',
'-port',
4444 ] }
INFO Selenium process finished.
Job succeeded
How can I properly configure gitlab-ci or nightswatch to run e2e tests in Gitlab-CI ?
Ok, now that I looked at your config and your compose file some more I think I see your issue. First thing you need to do is give your selenium/standalone-chrome service a name in the .yml file. The problem is you are trying to launch selenium standalone in your tests container (the node image) which doesn't have java installed. However, the selenium/standalone-chrome image does and this is where you want to point your tests instead of localhost
services:
"chrome"
- selenium/standalone-chrome
#...rest of file can stay the same
The second thing you need to do is remove the selenium section entirely from your nightwatch config and point selenium_host under test_settings at your chrome service.
selenium_host: 'chrome',
Here is a nightwatch.json and docker-compose.yml that is working for me.
docker-compose.yml
version: '3'
services:
chrome:
image: selenium/standalone-chrome
tests:
image: nightwatch-tests
environment:
- ENV_PASS=${ENV_PASS}
depends_on:
- chrome
nightwatch.json
{
"src_folders": [
"nw_tests"
],
"output_folder": "nw_reports",
"page_objects_path": "./nw_tests/pages",
"globals_path": "globals.js",
"test_workers": false,
"test_settings": {
"default": {
"launchUrl": "https://mylaunchurl/login",
"selenium_port": 4444,
"selenium_host": "chrome",
"silent": true,
"screenshots": {
"enabled": true,
"path": "nw_screenshots"
},
"desiredCapabilities": {
"browserName": "chrome",
"chromeOptions" : {
"args": ["deny-permission-prompts"],
"prefs": {
"profile.default_content_settings.popups": 0,
"download.prompt_for_download": false
}
}
}
}
}
}