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

Bug: Can not start firefox test if default test_settings contains "chromeOptions" #1985

Closed bes closed 5 years ago

bes commented 5 years ago

Hi,

I am running nightwatch 1.0.18 and if I have chromeOptions in the default test_settings, it always starts chrome, even if I start it using e.g. -e firefox_tests

const selenium = require('selenium-server-standalone-jar');
const chromedriver = require('chromedriver');
const geckodriver = require('geckodriver');

function createTestSettings(launchUrl, desiredCapabilities) {
    return {
        launch_url: launchUrl,
        selenium_port: 4444,
        selenium_host: "localhost",
        default_path_prefix: "/wd/hub",
        silent: true,

        screenshots: {
            enabled: true,
            on_failure: true,
            on_error: true,
            path: "./build/reports/screenshots",
        },

        desiredCapabilities: desiredCapabilities,
    };
}

module.exports = {
    src_folders: ["./build/dist/tests/e2e"],
    output_folder: "./build/reports",
    custom_commands_path: "./build/dist/commands",
    custom_assertions_path: "./build/dist/assertions",
    page_objects_path: "./build/dist/pages",
    globals_path: "./build/dist/tests/globalsModule.js",
    selenium: {
        start_process: true,
        server_path: selenium.path,
        port: 4444,
        log_path: "./build/reports",
        cli_args: {
            "webdriver.chrome.driver": chromedriver.path,
            "webdriver.gecko.driver": geckodriver.path,
        },
    },
    test_settings: {
        default: createTestSettings("http://localhost:8101/", {
            browserName: "chrome",
            chromeOptions: {
                args: [
                    "window-size=1280,800",
                ],
            },
        }),
        firefox_tests: createTestSettings("http://localhost:8101/", {
            browserName: "firefox",
            marionette: true,
            javascriptEnabled: true,
            acceptSslCerts: true,
            "moz:firefoxOptions": {
                args: [
                    '--headless',
                ],
            },
        }),
};

P.S: The documentation is really not clear on how different sections in nightwatch.conf.js are merged - maybe I am overspecifying different blocks because of that. If there is something I can improve please let me know =)

Similar to https://github.com/nightwatchjs/nightwatch/issues/1737

BR Erik

beatfactor commented 5 years ago

"An environment inherits all the base settings and all the settings defined under the "default" environment." - http://nightwatchjs.org/guide/#test-environments

Feel free to make any change suggestions by submitting a PR to our docs repo: https://github.com/nightwatchjs/nightwatch-docs.

So in your case, you will need to clear the chromeOptions for now and I think you can write your config like below:

const selenium = require('selenium-server-standalone-jar');
const chromedriver = require('chromedriver');
const geckodriver = require('geckodriver');

module.exports = {
  src_folders: ['./build/dist/tests/e2e'],
  output_folder: './build/reports',
  custom_commands_path: './build/dist/commands',
  custom_assertions_path: './build/dist/assertions',
  page_objects_path: './build/dist/pages',
  globals_path: './build/dist/tests/globalsModule.js',
  selenium: {
    start_process: true,
    server_path: selenium.path,
    port: 4444,
    log_path: './build/reports',
    cli_args: {
      'webdriver.chrome.driver': chromedriver.path,
      'webdriver.gecko.driver': geckodriver.path,
    },
  },
  test_settings: {
    default: {
      default_path_prefix: '/wd/hub',
      silent: true,

      screenshots: {
        enabled: true,
        on_failure: true,
        on_error: true,
        path: './build/reports/screenshots',
      },
      desiredCapabilities: {
        browserName: 'chrome',
        chromeOptions: {
          args: [
            'window-size=1280,800',
          ],
        },
      },
      launch_url: 'http://localhost:8101/'
    },

    firefox_tests: {
      desiredCapabilities: {
        browserName: 'firefox',
        marionette: true,
        chromeOptions: null,
        'moz:firefoxOptions': {
          args: [
            '--headless',
          ],
        },
      }
    }
  }
};
stale[bot] commented 5 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.