Running selenium tests using nightwatch on linux - linux

I have a linux box and I am trying to run selenium tests (written in nightwatch) on it. I installed the chromedriver at
http://chromedriver.storage.googleapis.com/index.html?path=2.9/
(the linuxx64 bit one)
I also installed the standalone selenium jar
I run the following command
DISPLAY=:1 xvfb-run java -jar lib/selenium-server-standalone-2.52.0.jar -Dwebdriver.chrome.driver=lib/chromedriver
Here's my nightwatch configuration:
{
"src_folders": [
"tests"
],
"output_folder": "reports",
"custom_commands_path": "custom_commands",
"custom_assertions_path": "",
"page_objects_path": "",
"live_output" : true,
"globals_path": "globals.js",
"selenium": {
"start_process": true,
"server_path": "lib/selenium-server-standalone-2.52.0.jar",
"log_path": "",
"host": "127.0.0.1",
"port": 4444,
"cli_args": {
"webdriver.chrome.driver": "lib/chromedriver",
"webdriver.chromeJenkins.driver": "../../tools/chromedriver/chromedriver",
"webdriver.ie.driver": "lib/IEDriverServer_x64_2.52.2.exe",
"trustAllSSLCertificates": true
}
},
"test_workers": {
"enabled": true,
"workers": "auto"
},
"test_settings": {
"default": {
"launch_url": "",
"selenium_port": 4444,
"selenium_host": "localhost",
"silent": true,
"screenshots": {
"enabled": true,
"on_failure": true,
"on_error": true,
"path": "./screenshots"
},
"end_session_on_fail": false,
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true,
"acceptSslCerts": true,
"chromeOptions": {
"args": [
"use-fake-device-for-media-stream",
"use-fake-ui-for-media-stream"
]
}
}
},
"jenkins" : {
"selenium_port" : 4444,
"selenium_host" : "127.0.0.1",
"cli_args" : {
"webdriver.chrome.driver" : "lib/chromedriver"
},
"chromeOptions" : {
"args" : ["--no-sandbox"]
},
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true,
"acceptSslCerts": true,
"platform" : "LINUX",
"chromeOptions" : {
"args" : ["--no-sandbox"]
}
}
}
}
Then I run the following command
DISPLAY=:1 xvfb-run --server-args="-screen 0, 1366x768x24" ./nightwatch -e jenkins --test tests/blog.js
The tests start to run, but when I look at the output the driver gets stuck at a particular element. It tries to find the element but times out. When I run the tests on my local machine, I do not get this error.
Am I doing something wrong here?

Check your browser viewport size. It's probably smaller in xvfb than it is on your main screen, and the site your testing may change behavior at different resolutions. Saw that my first day.
TL;DR
My chrome window was the same size, but opening the debugging pane changed site behavior.

Related

Visual Studio (VS-code) code terminal is failing to launch,Overlapping-Directories

I tried to compile a program but terminal is not opening. system : Ubuntu
Overlapping-Directories.
The terminal process failed to launch: Starting directory (cwd) "/home/chinu/Documents/code/react-02//home/chinu/Documents/code/react-02/src" does not exist.
Below is the JSON file of my visual studio code :
{
"workbench.editorAssociations": {
"*.ipynb": "jupyter-notebook"
},
"notebook.cellToolbarLocation": {
"default": "right",
"jupyter-notebook": "left"
},
"editor.suggestSelection": "first",
"vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
"files.exclude": {
"**/.classpath": true,
"**/.project": true,
"**/.settings": true,
"**/.factorypath": true
},
"editor.tabSize": 2,
"editor.insertSpaces": true,
"editor.detectIndentation": false,
"editor.fontSize": 16,
"diffEditor.wordWrap": "on",
"editor.wordWrap": "on",
"liveServer.settings.donotShowInfoMsg": true,
"workbench.colorTheme": "One Dark Pro Darker",
// edit-start
"emmet.includeLanguages": {
"javascript":"javascriptreact"
},
// edit-end
"atomKeymap.promptV3Features": true,
"editor.multiCursorModifier": "ctrlCmd",
"editor.formatOnPaste": true,
"[html]": {
"editor.defaultFormatter": "HookyQR.beautify"
},
"[javascript]": {
"editor.defaultFormatter": "HookyQR.beautify"
},
"terminal.integrated.cwd": "${fileDirname}",
"liveServer.settings.donotVerifyTags": true,
"workbench.iconTheme": "Monokai Pro (Filter Ristretto) Icons",
"window.zoomLevel": 2 }
Code is running in System Terminal.
In a previous session i deleted this
: sudo rm /var/lib/dpkg/lock-frontend

Nightwatch : Unable to create new service : ChromeDriverService

I am trying to automate a simple test case using Nightwatch framework of validating a login. I have followed the steps mentioned on : https://www.softwaretestingmaterial.com/browser-automation-with-nightwatch-and-selenium/
The problem arises when I execute the command node nightwatch tests/bing_test.js in node.js command prompt which results in a error message.
Below is my nightwatch.json configs :
{
"src_folders": ["tests"],
"output_folder": "reports",
"custom_commands_path": "",
"custom_assertions_path": "",
"page_objects_path": "",
"globals_path": "",
"selenium": {
"start_process": true,
"server_path": "./lib/selenium-server-standalone-3.8.1.jar",
"log_path": "./reports",
"host": "127.0.0.1",
"port": 4445,
"cli_args": {
"webdriver.chrome.driver": "./lib/drivers/chromedriver.exe",
"webdriver.gecko.driver": "./lib/drivers/geckodriver.exe",
"webdriver.edge.driver": "./lib/drivers/MicrosoftWebDriver.exe"
}
},
"test_settings": {
"default": {
"launch_url": "http://localhost",
"selenium_port": 4445,
"selenium_host": "localhost",
"silent": true,
"screenshots": {
"enabled": true,
"path": "./reports/screenshots"
},
"desiredCapabilities": {
"browserName": "chrome",
"marionette": true,
"javascriptEnabled": true,
"acceptSslCerts": true
}
},
"chrome": {
"desiredCapabilities": {
"browserName": "chrome"
}
},
"firefox": {
"desiredCapabilities": {
"browserName": "firefox"
}
},
"edge": {
"desiredCapabilities": {
"browserName": "MicrosoftEdge"
}
}
}
}
Error Message :
[Bing Test] Test Suite
======================
Response 500 POST /wd/hub/session (363ms)
{ value:
{ error:
[ "Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T19:05:32.194Z'",
"System info: host: 'PDC2LAP-7173253', ip: '192.168.43.196', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_201'",
'Driver info: driver.version: unknown' ],
message: 'Unable to create new service: ChromeDriverService' },
status: 33 }
An error occurred while retrieving a new session: "Unable to create new service: ChromeDriverService"
at endReadableNT (_stream_readable.js:1129:12)
at processTicksAndRejections (internal/process/next_tick.js:76:17)
_________________________________________________
TEST FAILURE: 1 error during execution 0 tests failed, 0 passed. 2.886s
× bing_test
An error occurred while retrieving a new session: "Unable to create new service: ChromeDriverService"
at endReadableNT (_stream_readable.js:1129:12)
at processTicksAndRejections (internal/process/next_tick.js:76:17)
SKIPPED:
- Bing search test
I have tried to debug the issue by going through the comments on GIT forum by setting "webdriver.chrome.driver": "" and "start_process": false, but none of the two worked.
ChromeDriver Version - v72
Selenium Standalone Jar - 3.8.1
Please feel free to guide me to any existing answer/documentation that persists for this issue.

cannot run nightwatch.js tests in chrome browser on linux machine

I am trying to run nightwatch.js in chrome browser on linux machine.
My nightwatch tests run perfectly on windows machine using windows version of chrome driver.
I updated nightwatch.json file and gave path to linux version of chromedriver but my tests do not run and give error
npm run test-e2e --test tests/regression/testcase1.js
************Command Line Argument:*********************
Starting selenium server... started - PID: 12625
[regression / TEST1] Test Suite
Running: Login to UI
Error retrieving a new session from the selenium server
Error writing log file to: /home/abc/testing/AutomationFramework/logs/selenium-debug.log
Connection refused! Is selenium server started?
{ value:
{ message: 'Unable to create new service: ChromeDriverService\nBuild info: version: \'3.12.0\', revision: \'7c6e0b3\', time: \'2018-05-08T15:15:08.936Z\'\nSystem info: host: \'virtualserver01\', ip: \'127.0.1.1\', os.name: \'Linux\', os.arch: \'amd64\', os.version: \'4.4.0-124-generic\', java.version: \'1.8.0_171\'\nDriver info: driver.version: unknown',
error: 'session not created' },
status: 33 }
I also have Google chrome installed on my linux machine
$ google-chrome --version
Google Chrome 65.0.3325.181
My nightwatch.json file is as follows
{
"src_folders" : ["tests"],
"output_folder" : "reports",
"globals_path" : "nightwatch.global.js",
"custom_commands_path": "./commands",
"selenium" : {
"start_process" : true,
"server_path" : "./bin/selenium-server-standalone-3.12.0.jar",
"log_path" : "./logs",
"port" : 4444,
"cli_args" : {
"webdriver.chrome.driver" : "./bin/chromedriver"
}
},
"test_settings" : {
"default" : {
"launch_url" : "http://localhost",
"use_xpath": true,
"selenium_port" : 4444,
"selenium_host" : "localhost",
"screenshots" :{
"enabled" : true,
"path" : "./screenshots",
"on_failure" : true
},
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true,
"acceptSslCerts": true,
"chromeOptions": {
"args": ["disable-web-security"],
"prefs": {
}
}
}
}
}
}

Run Nightwatch.js tests against a remote Selenium server in Kubernetes environment

I've created automated tests with Nightwatch-Cucumber based on Nightwatch.js. I can start the tests on local machine, the Selenium server starts on local machine and the tests will be executed.
But now I want to integrate the existing tests in a Kubernetes environment. On local machine I want to use minikube, helm, a jenkins chart to start the tests and a selenium chart. But this setup is quiet different to the local one. I want to start the tests on the Jenkins instance and the tests should be executed against the running Selenium server delivered by the selenium chart. So I want to use such a "remote" Selenium server. I don't want to use a local Selenium server that starts on runtime, but a still existing Selenium server somewhere in the Kubernetes environment
But how to configure my nightwatch.conf.js configuration to realize that scenario?
My current configuration looks like this:
const config = {
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,
log_path: "",
host: "127.0.0.1",
port: 4444
},
test_settings: {
default: {
globals: {
waitForConditionTimeout: 30000,
waitForConditionPollInterval: 500
},
screenshots: {
enabled: true,
on_failure: true,
path: "screenshots"
},
//launch_url: "http://localhost:8087",
//selenium_port: 4444,
//selenium_host: "127.0.0.1",
desiredCapabilities: {
browserName: "phantomjs",
javascriptEnabled: true,
acceptSslCerts: true,
"phantomjs.binary.path": phantomjs.path
}
},
First step, make sure your remote Selenium-server is accessable( checking host IP and port )
Secondly, config following :
const config = {
output_folder: "reports",
custom_commands_path: "commands",
// custom_assertions_path: 'assertions',
live_output: false,
page_objects_path: "pageobjects",
disable_colors: false,
selenium: {
start_process: false, // turn this off and comment all below config
// server_path: seleniumServer.path,
// log_path: "",
// host: "127.0.0.1",
// port: 4444
},
test_settings: {
default: {
globals: {
waitForConditionTimeout: 30000,
waitForConditionPollInterval: 500
},
screenshots: {
enabled: true,
on_failure: true,
path: "screenshots"
},
launch_url: "http://localhost:8087",
selenium_port: 4444, // provide your selenium port in 1st step
selenium_host: "127.0.0.1", // provide your selenium address in 1st step
desiredCapabilities: {
browserName: "phantomjs",
javascriptEnabled: true,
acceptSslCerts: true,
"phantomjs.binary.path": phantomjs.path
}
},

Uable to access to localhost:8080 after upgrading NodeJS to 8.1.4

Our development group is starting a new React project and I have been trying to use Nightwatch + Selenium to do the e2e testing. I got it to work when running everything using NodeJS 6.9.4. Now we have been forced to upgrade NodeJS to 8.1.4 and I'm facing an issue that is stopping me to proceed with testing. When using Selenium with Chrome as browser, I keep getting a 'This site can't be reached' message (but the page can be accessed if I open manually a Chrome window. Any idea what can be going on? Here you have the test result log and my nightwatch.conf.js
Test Result:
INFO Request: GET /wd/hub/session/fc36e7a7-4909-4dfd-a853-6d769accb085/element/0/text
- data:
- headers: {"Accept":"application/json"}
INFO Response 200 GET /wd/hub/session/fc36e7a7-4909-4dfd-a853-6d769accb085/element/0/text (16ms) { state: 'success',
sessionId: 'fc36e7a7-4909-4dfd-a853-6d769accb085',
hCode: 972983271,
value: 'This site can’t be reached',
class: 'org.openqa.selenium.remote.Response',
status: 0 }
Nightwatch Conf
const SCREENSHOT_PATH = "./screenshots/";
const BIN_PATH = './node_modules/nightwatch/bin/';
``
// we use a nightwatch.conf.js file so we can include comments and helper functions
module.exports = {
"src_folders": [
"__tests__/e2e/specs"// Where you are storing your Nightwatch e2e tests
],
"output_folder": "./reports", // reports (test outcome) output by nightwatch
"selenium": { // downloaded by selenium-download module (see readme)
"start_process": false, // tells nightwatch to start/stop the selenium process
"server_path": "./node_modules/nightwatch/bin/selenium.jar",
"host": "127.0.0.1",
"port": 4444, // standard selenium port
"cli_args": { // chromedriver is downloaded by selenium-download (see readme)
"webdriver.chrome.driver" : "./node_modules/nightwatch/bin/chromedriver"
}
},
"test_settings": {
"default": {
"screenshots": {
"enabled": true, // if you want to keep screenshots
"path": './screenshots' // save screenshots here
},
"globals": {
"waitForConditionTimeout": 5000 // sometimes internet is slow so wait.
},
"desiredCapabilities": { // use Chrome as the default browser for tests
"browserName": "chrome",
"javascriptEnabled": true, // turn off to test progressive enhancement
"chromeOptions" : {
"args": ['--disable-web-security', 'no-sandbox', '--disable-async-dns']
}
}
},
"chrome": {
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true, // turn off to test progressive enhancement
"chromeOptions" : {
"args": ['--disable-web-security', 'no-sandbox', '--disable-async-dns']
}
}
}
},
"params": {
"baseUrl": "http://localhost:8080/",
}
}
Sorry for having the files attached instead of expanded on the comment but tho I have been using StackOverflow for a long time, this is my first request. StackOverflow
Apparently my localhost is not visible to the Selenium Chrome that is running. Needed to make my localhost accesible from outside my machine in order to get this running

Resources