nightwatchjs / nightwatch

Integrated end-to-end testing framework written in Node.js and using W3C Webdriver API. Developed at @browserstack
https://nightwatchjs.org
MIT License
11.78k stars 1.31k forks source link

selenium fails to start if either chromedriver or geckodriver is not installed #3046

Closed swrdfish closed 1 year ago

swrdfish commented 2 years ago

Describe the bug

If either chromedriver or geckodriver is not installed, then nightwatch fails to start selenium server. Works fine if both are installed.

Sample test

Follow the quickstart guide to create a new nightwatch project. But instead of installing both chromedriver and geckodriver, install just chromedriver. Also make sure selenium-server and java are installed.

Then execute the following command:

npx nightwatch node_modules/nightwatch/examples/tests/ecosia.js --env selenium.chrome

Verbose output

terminal output

```txt [Ecosia.org Demo] Test Suite ──────────────────────────────────────────────────────── ⠋ Starting Selenium Server on port 4444... ⚠ Failed to start Selenium Server. Wrote log file to: /Users/binayakghosh/projects/nightwatch-test-project/ecosia_selenium-server.log. Selenium Server process closed. ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── TEST FAILURE (360ms): - 1 error during execution; - 0 tests failed; - 0/NA tests passed ┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ │ │ │ Error: Unable to create the Selenium Server process: │ │ Server terminated early with status 1; verify if webdriver is configured correctly; using: │ │ { │ │ start_process: true, │ │ server_path: │ │ '/Users/binayakghosh/projects/nightwatch-test-project/node_modules/selenium-server/lib/runner/selenium-server-standalone-3.141.59.jar', │ │ port: 4444, │ │ host: 'localhost', │ │ ssl: false, │ │ default_path_prefix: '/wd/hub', │ │ proxy: undefined, │ │ cli_args: { │ │ 'webdriver.gecko.driver': '', │ │ 'webdriver.chrome.driver': '/Users/binayakghosh/projects/nightwatch-test-project/node_modules/chromedriver/lib/chromedriver/chromedriver' │ │ } │ │ } │ │ │ │ │ │ │ └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ ✖ 1) ecosia SKIPPED: - Demo test ecosia.org Wrote report file to: tests_output/ecosia.xml. ```

ecosia_selenium-server.log

```txt Exception in thread "main" com.beust.jcommander.ParameterException: Was passed main parameter '-Dwebdriver.gecko.driver' but no main parameter was defined in your arg class at com.beust.jcommander.JCommander.initMainParameterValue(JCommander.java:936) at com.beust.jcommander.JCommander.parseValues(JCommander.java:752) at com.beust.jcommander.JCommander.parse(JCommander.java:340) at com.beust.jcommander.JCommander.parse(JCommander.java:319) at org.openqa.grid.selenium.GridLauncherV3.parse(GridLauncherV3.java:218) at org.openqa.grid.selenium.GridLauncherV3.lambda$buildLaunchers$3(GridLauncherV3.java:241) at org.openqa.grid.selenium.GridLauncherV3.lambda$launch$0(GridLauncherV3.java:86) at java.base/java.util.Optional.map(Optional.java:265) at org.openqa.grid.selenium.GridLauncherV3.launch(GridLauncherV3.java:86) at org.openqa.grid.selenium.GridLauncherV3.main(GridLauncherV3.java:70) ```

Configuration

nightwatch.json

```js // Autogenerated by Nightwatch // Refer to the online docs for more details: https://nightwatchjs.org/gettingstarted/configuration/ const Services = {}; loadServices(); // _ _ _ _ _ _ _ // | \ | |(_) | | | | | | | | // | \| | _ __ _ | |__ | |_ __ __ __ _ | |_ ___ | |__ // | . ` || | / _` || '_ \ | __|\ \ /\ / / / _` || __| / __|| '_ \ // | |\ || || (_| || | | || |_ \ V V / | (_| || |_ | (__ | | | | // \_| \_/|_| \__, ||_| |_| \__| \_/\_/ \__,_| \__| \___||_| |_| // __/ | // |___/ 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: [], // See https://nightwatchjs.org/guide/working-with-page-objects/ page_objects_path: ['node_modules/nightwatch/examples/pages/'], // See https://nightwatchjs.org/guide/extending-nightwatch/#writing-custom-commands custom_commands_path: ['node_modules/nightwatch/examples/custom-commands/'], // 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 : 'firefox' }, webdriver: { start_process: true, server_path: '' } }, safari: { desiredCapabilities : { browserName : 'safari', alwaysMatch: { acceptInsecureCerts: false } }, webdriver: { start_process: true, server_path: '' } }, firefox: { desiredCapabilities : { browserName : 'firefox', alwaysMatch: { acceptInsecureCerts: true, 'moz:firefoxOptions': { args: [ // '-headless', // '-verbose' ] } } }, webdriver: { start_process: true, server_path: '', cli_args: [ // very verbose geckodriver logs // '-vv' ] } }, chrome: { desiredCapabilities : { browserName : 'chrome', 'goog:chromeOptions' : { // More info on Chromedriver: https://sites.google.com/a/chromium.org/chromedriver/ // // w3c:false tells Chromedriver to run using the legacy JSONWire protocol (not required in Chrome 78) w3c: true, args: [ //'--no-sandbox', //'--ignore-certificate-errors', //'--allow-insecure-localhost', //'--headless' ] } }, webdriver: { start_process: true, server_path: '', cli_args: [ // --verbose ] } }, edge: { desiredCapabilities : { browserName : 'MicrosoftEdge', 'ms:edgeOptions' : { w3c: true, // More info on EdgeDriver: https://docs.microsoft.com/en-us/microsoft-edge/webdriver-chromium/capabilities-edge-options args: [ //'--headless' ] } }, webdriver: { start_process: true, // Download msedgedriver from https://docs.microsoft.com/en-us/microsoft-edge/webdriver-chromium/ // and set the location below: server_path: '', cli_args: [ // --verbose ] } }, ////////////////////////////////////////////////////////////////////////////////// // Configuration for when using cucumber-js (https://cucumber.io) | // | // It uses the bundled examples inside the nightwatch examples folder; feel free | // to adapt this to your own project needs | ////////////////////////////////////////////////////////////////////////////////// 'cucumber-js': { src_folders: ['examples/cucumber-js/features/step_definitions'], test_runner: { // set cucumber as the runner type: 'cucumber', // define cucumber specific options options: { //set the feature path feature_path: 'node_modules/nightwatch/examples/cucumber-js/*/*.feature', // start the webdriver session automatically (enabled by default) // auto_start_session: true // use parallel execution in Cucumber // parallel: 2 // set number of workers to use (can also be defined in the cli as --parallel 2 } } }, ////////////////////////////////////////////////////////////////////////////////// // 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' : { userName: '${BROWSERSTACK_USER}', accessKey: '${BROWSERSTACK_KEY}', } }, disable_error_log: true, webdriver: { timeout_options: { timeout: 15000, retry_attempts: 3 }, keep_alive: true, start_process: false } }, 'browserstack.local': { extends: 'browserstack', desiredCapabilities: { 'browserstack.local': true } }, 'browserstack.chrome': { extends: 'browserstack', desiredCapabilities: { browserName: 'chrome', chromeOptions : { w3c: true } } }, 'browserstack.firefox': { extends: 'browserstack', desiredCapabilities: { browserName: 'firefox' } }, 'browserstack.ie': { extends: 'browserstack', desiredCapabilities: { browserName: 'internet explorer', browserVersion: '11.0' } }, 'browserstack.safari': { extends: 'browserstack', desiredCapabilities: { browserName: 'safari' } }, 'browserstack.local_chrome': { extends: 'browserstack.local', desiredCapabilities: { browserName: 'chrome' } }, 'browserstack.local_firefox': { extends: 'browserstack.local', desiredCapabilities: { browserName: 'firefox' } }, ////////////////////////////////////////////////////////////////////////////////// // Configuration for when using the Selenium service, either locally or remote, | // like Selenium Grid | ////////////////////////////////////////////////////////////////////////////////// selenium_server: { // Selenium Server is running locally and is managed by Nightwatch selenium: { start_process: true, port: 4444, server_path: (Services.seleniumServer ? Services.seleniumServer.path : ''), cli_args: { 'webdriver.gecko.driver': (Services.geckodriver ? Services.geckodriver.path : ''), 'webdriver.chrome.driver': (Services.chromedriver ? Services.chromedriver.path : '') } } }, 'selenium.chrome': { extends: 'selenium_server', desiredCapabilities: { browserName: 'chrome', chromeOptions : { w3c: true } } }, 'selenium.firefox': { extends: 'selenium_server', 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) {} } ```

Your Environment

Executable Version
nightwatch --version 2.0.7
npm --version 8.3.1
yarn --version NA
node --version 17.4.0
Browser driver Version
NAME VERSION
chromedriver 98.0.0
selenium-server 3.141.59
OS Version
macOS Monterey 12.1
beatfactor commented 2 years ago

Seems like we just need to removed the 'webdriver.gecko.driver': '', from the cli_args.

swrdfish commented 2 years ago

@beatfactor Same is true if only geckodriver is installed. In that case 'webdriver.chrome.driver' needs to be removed. The bug is in the config generation/merging code I guess.

swrdfish commented 1 year ago

Not reproducible anymore. Tested in v2.5