Nightwatch - Use chromedriver - selenium-chromedriver

So i saw a similar question on stack here but it did not have an accepted answer nor did it provide me with the information i needed..
I am trying to use 'chromedriver' because 'selenium-webdriver' requires a FF version <= 28.
What i've done so far.
nightwatch.js tests running fine in FF
downloaded chromedriver (npm install chromedriver -g) and also npm install chromedriver into my nightwatch project directory
went to nightwatch/bin/nightwatch.json and edited the following code
"selenium" : {
"start_process" : false,
"server_path" : "",
"log_path" : "",
"host" : "127.0.0.1",
"port" : 4444,
"cli_args" : {
"webdriver.chrome.driver" : "/usr/local/bin/chromedriver", <= added this - is this the binary?
"webdriver.ie.driver" : "",
"webdriver.firefox.profile" : ""
}},
also tried to update the settings for selenium to have a start_process=true and server_path
"selenium" : {
"start_process" : true,
"server_path" : "../selenium-server-standalone-2.39.0.jar",
"log_path" : "",
"host" : "127.0.0.1",
"port" : 4444,
"cli_args" : {
"webdriver.chrome.driver" : "/usr/local/bin/chromedriver",
"webdriver.ie.driver" : "",
"webdriver.firefox.profile" : ""
}
},
Not sure if im pointing to the proper chromedriver file/folder
also edited the test settings
"test_settings" : {
"default" : {
"launch_url" : "http://localhost",
"selenium_host" : "127.0.0.1",
"selenium_port" : 4444,
"silent" : true,
"disable_colors": false,
"screenshots" : {
"enabled" : false,
"path" : ""
},
"desiredCapabilities" : {
"browserName" : "chrome", <= changed this from ff to chrome
"javascriptEnabled" : true,
"acceptSslCerts" : true
}
},
If i go to run the test (without a -e <browser>) e.g. nightwatch -g <group>, it launches fine in FF and runs..
If i try to specify the chrome browser (-e chrome) nightwatch -g <group> -e chrome i get the following error
ERROR There was an error while starting the test runner:
Error: Invalid testing environment specified: chrome
at Object.CliRunner.parseTestSettings (/usr/local/lib/node_modules/nightwatch/lib/runner/cli/clirunner.js:354:15)
at Object.CliRunner.init (/usr/local/lib/node_modules/nightwatch/lib/runner/cli/clirunner.js:31:8)
at module.exports.runner.runner (/usr/local/lib/node_modules/nightwatch/lib/index.js:512:19)
at /usr/local/lib/node_modules/nightwatch/bin/runner.js:9:16
at module.exports.cli.cli (/usr/local/lib/node_modules/nightwatch/lib/index.js:504:7)
at Object.<anonymous> (/usr/local/lib/node_modules/nightwatch/bin/runner.js:8:14)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
The questions i have are:
How do i point to the binary file (not sure which it is)
Are my settings in nightwatch.js correct? How is it running in FF if i changed the test_settings 'browserName = Chrome"?
Am i missing something here?
Thanks in advance

First you said
I am trying to use 'chromedriver' because 'selenium-webdriver'
requires a FF version <= 28.
Its because you are using selenium-server-standalone-2.39.0.jar (Old jar) Please download new one from here selenium-server-standalone-2.45.0.jar
Second Download chrome driver from here Chromedriver basis on your environment
Third update your nightwatch.json with below code
{
"src_folders": [
"tests"
],
"selenium": {
"start_process": false,
"server_path": "bin/selenium-server-standalone-2.45.0.jar",
"log_path": "",
"host": "127.0.0.1",
"port": 4444,
"cli_args": {
"webdriver.chrome.driver": "bin/chromedriver",
"webdriver.ie.driver": ""
}
},
"test_settings": {
"default": {
"launch_url": "http://127.0.0.1/",
"selenium_port": 4444,
"selenium_host": "localhost",
"silent": true,
"screenshots": {
"enabled": false,
"path": ""
},
"desiredCapabilities": {
"browserName": "firefox",
"javascriptEnabled": true,
"acceptSslCerts": true
}
},
"chrome": {
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true,
"acceptSslCerts": true
}
}
}
}
Fourth run your group with nightwatch -g -e chrome
Hope It will solve your problem.

Make sure to create a new nightwatch.json file in the root of your project.
The mistake i made was trying to use the nightwatch.json file that came with the package downlaoded from http://nightwatchjs.org/ that resided in nightwatch-0.6.11/bin/nightwatch.json

"selenium": {
"start_process":true,
"server_path": "bin/selenium.jar",
"log_path": "",
"host": "127.0.0.1",
"port": 4444,
"cli_args": {
"webdriver.chrome.driver": "",
"webdriver.ie.driver": ""
}
},
above code helps me to run selenium server by nightwatch

Related

CodeceptJS Puppeteer doesnt close browser window after finish

I am new to codeceptJS and Puppeteer, the bwoser window closes if I run only one sanity test but If I run multiple test cases. All the browser window keeps open and the terminal shows that the command is still running.
I have tried in the last line of the tests but doesnt work as all of them are in sepearte windows.
I.closeOtherTabs();
multiple test cases:
require('./app/stores/Schedule.js');
require('./app/stores/Configuration.js');
require('./app/stores/Submit.js');
codecept config file:
const testUrl = (!process.env.E2E_URL ? "http://localhost:3001" : process.env.E2E_URL);
const testCases = (!process.env.E2E_URL ? "./automation-test/sanity/dev.sanity.e2e.test.js" : "./automation-test/sanity/prod.sanity.e2e.test.js");
exports.config = {
"tests": testCases,
"timeout": 10000,
"output": "./output",
"helpers": {
"Puppeteer": {
"url": testUrl,
"browser": "chrome",
"windowSize": "1280x800",
"show": true,
"switches": {
"ignore-certificate-errors": true
}
}
},
"include": {
"I": "./automation-test/sanity/steps_file.js"
},
"bootstrap": false,
"mocha": {
"timeout": 10
},
"name": "test"
};

How do I get webdriverIO to use a specified chromedriver

I need my webdriver tests use a specified chromedriver in a directory.
The problem is that when I run the tests it always uses a different chromedriver exe that was set as a default.
Command: "wdio run wdio.ci.conf.ts"
I get : "chromedriver: Starting ChromeDriver 97.0.4692.71"
ChromeDriver 97 is found in \node_modules\chromedriver\lib\chromedriver\chromedriver.exe
However in the wdio.ci.conf.ts file I set it to
services:[ ['chromedriver',{
chromeDriverCustomPath:"src\\main\\cucumber-webdriver-io\\node_modules\\webdriver-manager\\selenium\\chromedriver.exe"
}]],
At this location Im expecting it to pick an older version of chrome driver, 95.0.4638.69
I need it to run an older version as the corporate Jenkins environment has upgraded Chrome yet. In Jenkins I get the error:
WARN webdriver: Request failed with status 500 due to session not created: This version of ChromeDriver only supports Chrome version 97
[INFO] [0-0] Current browser version is 95.0.4638.69 with binary path /usr/bin/google-chrome
Thanks for your help
wdio.ci.conf.ts (removed the comments to be more brief)
const report = require('multiple-cucumber-html-reporter');
export const config: WebdriverIO.Config = {
autoCompileOpts: {
autoCompile: true,
tsNodeOpts: {
transpileOnly: true,
project: 'tsconfig.json'
}
}
},
specs: [
'./features/**/*.feature'
],
exclude: [
// 'path/to/excluded/files'
],
maxInstances: 10,
capabilities: [{
maxInstances: 5,
//
browserName: 'chrome',
'goog:chromeOptions':{
args: [ '--disable-dev-shm-usage', '--headless', '--no-sandbox', '--ignore-certificate-errors', '--test-type','--auth-server-whitelist=*bp.com', '--window-size=1440,1024', '--start-maximized']
},
acceptInsecureCerts: true,
}],
logLevel: 'info',
bail: 0,
baseUrl: 'http://localhost',
waitforTimeout: 10000,
connectionRetryTimeout: 120000,
connectionRetryCount: 3,
services:[ ['chromedriver',{
chromeDriverCustomPath:"src\\main\\cucumber-webdriver-io\\node_modules\\webdriver-manager\\selenium\\chromedriver.exe"
}]],
framework: 'cucumber',
reporters: ['cucumberjs-json'],
cucumberOpts: {
// <string[]> (file/dir) require files before executing features
require: ['./features/step-definitions/*-steps.ts'],
// <boolean> show full backtrace for errors
backtrace: false,
// <string[]> ("extension:module") require files with the given EXTENSION after requiring MODULE (repeatable)
requireModule: [],
// <boolean> invoke formatters without executing steps
dryRun: false,
// <boolean> abort the run on first failure
failFast: false,
// <boolean> hide step definition snippets for pending steps
snippets: true,
// <boolean> hide source uris
source: true,
// <boolean> fail if there are any undefined or pending steps
strict: false,
// <string> (expression) only execute the features or scenarios with tags matching the expression
tagExpression: '',
// <number> timeout for step definitions
timeout: 60000,
// <boolean> Enable this config to treat undefined definitions as warnings.
ignoreUndefinedDefinitions: false
},
onComplete: function(exitCode, config, capabilities, results) {
report.generate({
jsonDir: '.tmp/json/',
reportPath: '.tmp/report/'
});
},
}
package.json
{
"name": "cucumber-webdriver-io",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"wdio": "wdio run wdio.conf.ts",
"wdio-ci": "wdio run wdio.ci.conf.ts",
"postinstall": "rimraf -rm node_modules/wdio-html-nice-reporter/node_modules/#wdio/types"
},
"author": "",
"license": "ISC",
"description": "",
"dependencies": {
"cucumber": "^7.0.0-rc.0",
"expect-webdriverio": "^3.1.4",
"multiple-cucumber-html-reporter": "^1.18.3"
},
"devDependencies": {
"#types/chai": "^4.3.0",
"#types/node": "^17.0.12",
"#types/webdriverio": "^5.0.0",
"#wdio/cli": "^7.16.13",
"#wdio/cucumber-framework": "^7.16.13",
"#wdio/local-runner": "^7.16.13",
"#wdio/spec-reporter": "^7.16.13",
"#wdio/types": "^7.16.13",
"chai": "^4.3.6",
"chromedriver": "^97.0.2",
"cucumber-html-reporter": "^5.5.0",
"fs-extra": "^10.0.0",
"ts-node": "^10.4.0",
"typescript": "^4.5.5",
"wdio-chromedriver-service": "^7.2.6",
"wdio-cucumberjs-json-reporter": "^4.2.0",
"webdriver-manager": "^12.1.8",
"webdriverio": "^7.16.13"
}
}
Missed spelled
chromeDriverCustomPath >> chromedriverCustomPath

VSCode Linux tasks.json MQL4 Compilation

I am switching to VSCode from MetaEditor to develop for MetaTrader4.
I'm using MetaTrader4 and MetaEditor in Linux via Wine.
(and MetaEditor runs quite terribly in Wine)
I would like to create a task to compile the code, and hopefully return the same error log to VSCode to further debug the code as if I was using MetaEditor.
I've used this post to figure out what CLI command has been used to compile MQL4:
Compiling MQL4 via command line through wine metaeditor.exe
/usr/bin/wine /path/to/MT4/metaeditor.exe /compile:"Z:\path\to\MT4\MQL4\Experts\Foo\Bar_EA.mq4" /include:"Z:\path\to\MT4\MQL4" /log
My issue is that I don't understand and cannot find any resource that explains what the "commands" inside the tasks.json file does or list of available variables. Like "/include:" or "presentation":, ${file}, etc.
So I took some guesses and I pieced it together to look something like this so far:
{
"version": "2.0.0",
"tasks": [
{
"label": "MQL4 Compile",
"type": "shell",
"command": "/usr/bin/wine /.wine/drive_c/Program Files (x86)/FXChoice MetaTrader 4/metaeditor.exe",
"args": [
"/compile:${file}"
]
}
]
}
Its probably not quite right.
I appreciate your help, thank you
{
"version": "2.0.0",
"tasks":
[
{
"label": "MQL4-Compile",
"group":
{
"kind" : "build",
"isDefault" : true
},
"presentation":
{
"echo" : true,
"reveal": "always",
"focus" : true,
"panel" : "shared"
},
"promptOnClose" : true,
"type" : "process",
"osx" :
{
"command" : "wine",
"args" :
[
"/Users/SVG/.wine/drive_c/Program Files/MetaTrader/metaeditor.exe",
"/compile:${fileBasename}",
"/log:${fileBasenameNoExtension}.log",
]
},
"windows" :
{
"command" : "C:\\Program Files (x86)\\MetaTrader\\metaeditor.exe",
"args" :
[
"/compile:${fileBasename}",
"/log:${fileBasenameNoExtension}.log",
]
},
}
]
}

Nightwatch with Chrome on Windows: Currently Unusable?

Since my chrome update, I cannot make any nightwatch tests work on Windows 10.
At first the system simply couldn't set values. So I updated to the latest nightwatch, then updated to latest chromedriver.exe and latest selenium jar.
Now the test simply shows data: in the url of the driven browser instead of loading the page. There is also a "disable developer mode extensions" popup and a warning that "--ignore-certificate-errors" is no longer supported.
Any ideas what I'm supposed to have done?
Chromedriver.exe version: 2.38
Selenium Standalone Server: selenium-server-standalone-3.9.1.jar
Nightwatch version: nightwatch#0.9.21
Thanks for any help. Here's my config:
{
"src_folders": ["tests"],
"output_folder": "reports",
"custom_commands_path": "",
"custom_assertions_path": "",
"page_objects_path": "pages",
"globals_path": "globals",
"selenium": {
"start_process": true,
"server_path": "./lib/selenium-server-standalone-3.9.1.jar",
"log_path": "./reports",
"host": "127.0.0.1",
"port": 4444,
"cli_args": {
"webdriver.chrome.driver": "./lib/chromedriver.exe"
}
},
"test_settings": {
"default": {
"launch_url": "https://modaquote.com",
"selenium_port": 4444,
"selenium_host": "localhost",
"silent": true,
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true,
"acceptSslCerts": true
}
}
}
}
You have to update Chromedriver to match your new version of Chrome. It should fix there issues.

Selenium 3.1.0 Standalone and chromedriver 2.27

I had Selenium and Chrome working perfectly, but since last week its not working any more. This is what I get:
Caused by: org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: '3.1.0', revision: '86a5d70', time: '2017-02-16 07:57:44 -0800'
System info: host: 'Scs-MacBook-Pro.local', ip: 'fe80:0:0:0:8d7:2cd3:84d5:161%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.12.2', java.version: '1.8.0_51'
Driver info: driver.version: ChromeDriver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:622)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:241)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:128)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:141)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:178)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:146)
... 14 more
Caused by: java.lang.IllegalStateException: The process has not exited yet therefore no result is available ...
at org.apache.commons.exec.DefaultExecuteResultHandler.getException(DefaultExecuteResultHandler.java:76)
at org.openqa.selenium.os.UnixProcess.checkForError(UnixProcess.java:174)
at org.openqa.selenium.os.CommandLine.checkForError(CommandLine.java:183)
at org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:179)
at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:168)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:78)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
... 19 more
13:04:18.947 WARN - Exception: The process has not exited yet therefore no result is available ...
13:04:47.978 INFO - Executing: [new session: Capabilities [{acceptSslCerts=true, name=Incart Fi, browserName=chrome, javascriptEnabled=true, platform=ANY}]])
13:04:47.979 INFO - Creating a new session for Capabilities [{acceptSslCerts=true, name=Incart Fi, browserName=chrome, javascriptEnabled=true, platform=ANY}]
Starting ChromeDriver 2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9) on port 29092
Only local connections are allowed.
Now I am wondering why, since I did not change any settings. It starts the safari browser, but there the waitForElement from nightwatch does not work. So can somebody tell me by the error why I got this issue?
{
"_comment": "./selenium-server-standalone-3.0.1.jar",
"_comment2": "/Users/SCMacBook/node_modules/chromedriver/bin/chromedriver",
"src_folders" : ["tests"],
"output_folder" : "reports",
"custom_commands_path" : "",
"custom_assertions_path" : "",
"page_objects_path" : "",
"globals_path" : "",
"selenium" : {
"start_process" : true,
"server_path" : "./selenium-server-standalone-3.1.0.jar",
"log_path" : "",
"port" : 4444,
"cli_args" : {
"webdriver.chrome.driver" : "/Users/SCMacBook/webdriver/chromedriver",
"webdriver.gecko.driver" : "/Users/SCMacBook/webdriver/geckodriver",
"webdriver.firefox.profile" : "nightwatch"
}
},
"test_settings" : {
"default" : {
"silent": true,
"screenshots" : {
"enabled" : true,
"path" : "./pics/"
},
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true
}
},
"firefox" : {
"desiredCapabilities": {
"browserName": "firefox",
"javascriptEnabled" : true,
"acceptSslCerts" : true
}
},
"safari" : {
"desiredCapabilities": {
"browserName": "safari"
}
},
"edge" : {
"desiredCapabilities": {
"platform": "WIN10",
"browserName": "MicrosoftEdge"
}
},
"ie" : {
"desiredCapabilities": {
"platform": "WIN10",
"browserName": "internet explorer",
"acceptSslCerts" : false
}
}
}
}
My solution was pretty simple and I feel espacially dumb. Somehow my /etc/hosts file was changed (MAMP ? My fault ?) and the
127.0.0.1 localhost
part was missing. So the machine couldn't use the localhost as 127.0.0.1
Hope this helps a poor someone someday :/
I also got the same error when running a nightwatch.js test and my problem was also due to a wrong entry to the /etc/hosts file:
0.0.0.0 localhost
The error went away after the above entry was removed.