在linux机器上运行nightwatch.js测试?

时间:2016-06-03 14:22:24

标签: linux node.js selenium nightwatch.js

我正在尝试在安装了Centos OS的linux机器上运行nightwatch自动ui测试。我开始时遇到了麻烦。

这是mywatch.json

中的test_settings配置
"test_settings": {
        "default": {
            "launch_url": "",
            "selenium_port": 4444,
            "selenium_host": "localhost",
            "silent": true,
            "screenshots": {
                "enabled": true,
                "on_failure": true,
                "on_error": true,
                "path": "./screenshots"
            },
            "detailed_option": true,
            "end_session_on_fail": false,
            "desiredCapabilities": {
                "browserName": "chrome",
                "javascriptEnabled": true,
                "acceptSslCerts": true,
                "chromeOptions": {
                    "args": [
                        "use-fake-device-for-media-stream",
                        "use-fake-ui-for-media-stream"
                    ]
                }
            }
        },

我安装了linux 64bit chrome驱动程序。然后我安装了selenium standalong服务器。但是,当我想使用节点守夜人进行夜间测试时,我得到一个错误

“拒绝连接!Selenium未启动..”

如何设置linux盒来运行nightwatch自动UI测试?

当我将start_process设置为false并单独运行selenium服务器时,我收到以下错误:

14:23:41.158 WARN - Exception: unknown error: Chrome failed to start: exited abnormally

1 个答案:

答案 0 :(得分:0)

你的nightwatch.json看起来好像丢失了许多对象,特别是selenium服务器设置,它可以解释"Connection is refused! Selenium not started.."。例如,这是我的,其中大部分将特定于您的环境:

{
  "src_folders": ["./tests"],
  "output_folder": "reports",
  "custom_commands_path": [
    "./node_modules/testarmada-magellan-nightwatch/lib/commands",
    "./lib/custom_commands"
  ],
  "custom_assertions_path": [
    "./node_modules/testarmada-magellan-nightwatch/lib/assertions"
  ],

  "page_objects_path": [
    "./lib/pages"
  ],

  "selenium": {
    "start_process": true,
    "server_path": "./node_modules/testarmada-magellan-nightwatch/node_modules/selenium-server/lib/runner/selenium-server-standalone-2.52.0.jar",
    "log_path": "reports",
    "host": "127.0.0.1",
    "port": 4444,
    "cli_args": {
      "webdriver.chrome.driver": "./node_modules/testarmada-magellan-nightwatch/node_modules/chromedriver/lib/chromedriver/chromedriver",
      "webdriver.ie.driver": ""
    }
  },

  "test_settings": {
    "default": {
      "launch_url": "http://127.0.0.1",
      "selenium_port": 4444,
      "selenium_host": "localhost",
      "silent": true,
      "sync_test_names": true,
      "screenshots": {
        "enabled": false,
        "path": ""
      },
      "desiredCapabilities": {
        "browserName": "chrome"
      },
      "globals": {
        "waitForConditionTimeout": 60000
      }
    },

    "phantomjs": {
      "desiredCapabilities": {
        "browserName": "phantomjs",
        "javascriptEnabled": true,
        "acceptSslCerts": true,
        "phantomjs.binary.path": "./node_modules/testarmada-magellan-nightwatch/node_modules/phantomjs/bin/phantomjs"
      }
    },

    "safari": {
      "desiredCapabilities": {
        "browserName": "safari"
      }
    },

    "firefox": {
      "desiredCapabilities": {
        "browserName": "firefox"
      }
    },

    "chrome": {
      "desiredCapabilities": {
        "browserName": "chrome"
      }
    },

    "sauce": {
      "selenium_host": "ondemand.saucelabs.com",
      "selenium_port": 80,
      "username": "myUserName",
      "access_key": "",
      "desiredCapabilities": {
        "browserName": "${SAUCE_BROWSER_NAME}",
        "platform": "${SAUCE_BROWSER_PLATFORM}",
        "version": "${SAUCE_BROWSER_VERSION}",
        "tunnel-identifier": "${SAUCE_TUNNEL_ID}"
      },
      "selenium": {
        "start_process": false
      }
    }
  }
}