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.79k stars 1.31k forks source link

Setup options are not passed down to child processes #2959

Closed ianlet closed 2 years ago

ianlet commented 2 years ago

Describe the bug

When running Nightwatch on multiple environments, options passed to the setup function are not passed down to child processes that are running tests in each environments.

Custom runner

run-tests.js

```js // Dynamically starting my local server with a custom URL try { Nightwatch.cli(function(argv) { Nightwatch.CliRunner(argv) .setup({launch_url: WEBAPP_URL}) // Setup options with a custom `launch_url` .runTests() .catch((err) => { throw err; }) }); } catch (ex) { console.log('There was an error while starting the test runner:\n\n'); process.stderr.write(ex.stack + '\n'); process.exit(2); } ```

Sample test

sampleTest.js

```js module.exports = { sampleTest: function(browser) { browser .url(browser.launch_url) // This will be undefined .waitForElementVisible('body', 1000) .assert.containsText('body', 'Log In') .end(); } } ```

Run with command

$ ./run-tests.js --env firefox,chrome

Configuration

nightwatch.json

```js { src_folders: ['tests/ui'], selenium: { start_process: false, host: 'hub-cloud.browserstack.com', port: 443, }, common_capabilities: { 'acceptSslCerts': 'true', 'browserstack.console': 'info', 'browserstack.networkLogs': 'true', 'browserstack.local': true, 'browserstack.debug': true, }, test_settings: { default: {}, chrome: { desiredCapabilities: { browser: 'chrome', browser_version: 'latest', os: 'Windows', os_version: '10', }, }, firefox: { desiredCapabilities: { browser: 'firefox', browser_version: 'latest', os: 'Windows', os_version: '10', }, }, }, } ```

Additional information

This line of code https://github.com/nightwatchjs/nightwatch/blob/main/lib/runner/concurrency/child-process.js#L128 is where a child process is spawned with only the cli arguments but not the setup options.

Your Environment

Executable Version
nightwatch --version 1.7.12
yarn --version 1.22.11
node --version v16.8.0
OS Version
Linux 5.15.4-arch1-1
beatfactor commented 2 years ago

This isn't going to work I'm afraid. But you can easily define the launch_url in your config like this:

{
  src_folders: ['tests/ui'],
  launch_url: '${WEBAPP_URL}'
}  

WEBAPP_URL will be parsed automatically from process.env.WEBAPP_URL.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had any recent activity. If possible, please retry using the latest Nightwatch version and update the issue with any relevant details. If no further activity occurs, it will be closed. Thank you for your contribution.