Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No error while running selenium-server locally without installing Java first. #3105

Open
garg3133 opened this issue Mar 16, 2022 · 5 comments · May be fixed by #4271
Open

No error while running selenium-server locally without installing Java first. #3105

garg3133 opened this issue Mar 16, 2022 · 5 comments · May be fixed by #4271

Comments

@garg3133
Copy link
Member

Describe the bug

Nightwatch does not throw any error while running selenium-server locally if Java is not installed on the system.

image

Sample test

sampleTest.js

// Any test would do

Run with command

$ npx nightwatch --env selenium_server

Verbose output

debug.log

<!-- Include the verbose output, if possible (run nightwatch with `--verbose` argument) -->

Configuration

nightwatch.json

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: 'http://localhost',

      screenshots: {
        enabled: false,
        path: 'screens',
        on_failure: true
      },

      desiredCapabilities: {
        browserName: 'firefox'
      },

      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
        ]
      }
    },
    
    //////////////////////////////////////////////////////////////////////////////////
    // Configuration for 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.browserstack.com',
        port: 4444
      },
      // 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.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
      // More info on setting up Selenium Server locally:
      // https://nightwatchjs.org/guide/getting-started/installation.html#install-selenium-server
      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'
          ]
        }
      }
    }
  }
};

Your Environment

Executable Version
nightwatch --version 2.0.10
npm --version 8.3.0
yarn --version VERSION
node --version 17.3.1
Browser driver Version
geckodriver 3.0.1
OS Version
macOS Monterey 12.1
@subhajit20
Copy link
Contributor

subhajit20 commented Feb 26, 2024

hey @garg3133 is this the correct file to be changed ?

let java = 'java';
if (process.env['JAVA_HOME']) {
java = path.join(process.env['JAVA_HOME'], 'bin/java');
}

@SubstantialCattle5
Copy link

SubstantialCattle5 commented Feb 26, 2024

I've added a condition which throws an error if the variable doesn't exist.

 let java = 'java';
    if (process.env['JAVA_HOME']) {
      java = path.join(process.env['JAVA_HOME'], 'bin/java');
    } else {
      throw new Error(
        'Java is not installed or JAVA_HOME environment variable is not set.'
      );
    }

Is this fine?
@garg3133 @AutomatedTester

@zei-ZZ
Copy link

zei-ZZ commented Mar 28, 2024

hello, is this issue still unfixed? if so can i work on it?

@nikhil-babar
Copy link

Could you please assign this issue to me, @garg3133?

@ritankarsaha
Copy link

@garg3133 I have fixed this issue and linked a PR #4271 for the same.

Thank You.

Harshit-7373 added a commit to Harshit-7373/nightwatch that referenced this issue Oct 30, 2024
No error while running selenium-server locally without installing Java first. nightwatchjs#3105....

github-Harshit-7373.

1. Terminal Check for Java: I added a command  to verify Java’s presence before running Nightwatch.

2. Made the necessary changes in the nightwatch.json file......
@Harshit-7373 Harshit-7373 mentioned this issue Oct 30, 2024
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants