Run Nightwatch.js tests against a remote Selenium server in Kubernetes environment

9/20/2017

I've created automated tests with Nightwatch-Cucumber based on Nightwatch.js. I can start the tests on local machine, the Selenium server starts on local machine and the tests will be executed.

But now I want to integrate the existing tests in a Kubernetes environment. On local machine I want to use minikube, helm, a jenkins chart to start the tests and a selenium chart. But this setup is quiet different to the local one. I want to start the tests on the Jenkins instance and the tests should be executed against the running Selenium server delivered by the selenium chart. So I want to use such a "remote" Selenium server. I don't want to use a local Selenium server that starts on runtime, but a still existing Selenium server somewhere in the Kubernetes environment

But how to configure my nightwatch.conf.js configuration to realize that scenario?

My current configuration looks like this:

const config = {
  output_folder: "reports",
  custom_commands_path: "commands",
  // custom_assertions_path: 'assertions',
  live_output: false,
  page_objects_path: "pageobjects",
  disable_colors: false,
  selenium: {
    start_process: true,
    server_path: seleniumServer.path,
    log_path: "",
    host: "127.0.0.1",
    port: 4444
  },
  test_settings: {
    default: {
      globals: {
        waitForConditionTimeout: 30000,
        waitForConditionPollInterval: 500
      },
      screenshots: {
        enabled: true,
        on_failure: true,
        path: "screenshots"
      },
      //launch_url: "http://localhost:8087",
      //selenium_port: 4444,
      //selenium_host: "127.0.0.1",
      desiredCapabilities: {
        browserName: "phantomjs",
        javascriptEnabled: true,
        acceptSslCerts: true,
        "phantomjs.binary.path": phantomjs.path
      }
    },
-- Martin
jenkins
kubernetes
nightwatch.js
node.js
selenium

1 Answer

10/9/2017

First step, make sure your remote Selenium-server is accessable( checking host IP and port ) Secondly, config following :

    const config = {
  output_folder: "reports",
  custom_commands_path: "commands",
  // custom_assertions_path: 'assertions',
  live_output: false,
  page_objects_path: "pageobjects",
  disable_colors: false,
  selenium: {
    start_process: false, // turn this off and comment all below config
//    server_path: seleniumServer.path,
//    log_path: "",
//    host: "127.0.0.1",
//    port: 4444
  },
  test_settings: {
    default: {
      globals: {
        waitForConditionTimeout: 30000,
        waitForConditionPollInterval: 500
      },
      screenshots: {
        enabled: true,
        on_failure: true,
        path: "screenshots"
      },
       launch_url: "http://localhost:8087",
       selenium_port: 4444, // provide your selenium port in 1st step
       selenium_host: "127.0.0.1", // provide your selenium address in 1st step 
      desiredCapabilities: {
        browserName: "phantomjs",
        javascriptEnabled: true,
        acceptSslCerts: true,
        "phantomjs.binary.path": phantomjs.path
      }
    },
-- Bao Tran
Source: StackOverflow