在Kubernetes环境中对远程Selenium服务器运行Nightwatch.js测试

时间:2017-09-20 07:47:30

标签: node.js selenium jenkins kubernetes nightwatch.js

我已根据Nightwatch-Cucumber使用Nightwatch.js创建了自动化测试。我可以在本地机器上启动测试,Selenium server在本地机器上启动,测试将被执行。

但是现在我想在Kubernetes环境中集成现有的测试。在本地计算机上,我想使用minikubehelmjenkins chart来启动测试,并使用selenium chart。但是这种设置与当地设置不同。我想在Jenkins实例上开始测试,并且应该针对Selenium server提供的正在运行的selenium chart执行测试。所以我想使用这样一个"遥控器" Selenium server。我不想使用在运行时启动的本地Selenium server,但在Kubernetes环境中的某个地方仍然存在Selenium server

但是如何配置我的nightwatch.conf.js配置以实现该方案?

我目前的配置如下:

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
      }
    },

1 个答案:

答案 0 :(得分:0)

第一步,确保您的远程Selenium服务器可访问(检查主机IP和端口) 其次,配置如下:

    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
      }
    },