linux - 在 linux box 上运行 nightwatch.js 测试?

标签 linux node.js selenium nightwatch.js

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

这是我在 nightwatch.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 64 位 chrome 驱动程序。然后我安装了 selenium 独立服务器。但是当我想要使用 node nightwatch 进行 nightwatch 测试时,我得到一个错误

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

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

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

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

最佳答案

您的 nightwatch.json 看起来缺少许多对象,特别是 selenium 服务器设置,这将解释 “连接被拒绝!Selenium 未启动..”。例如,这是我的,其中大部分将特定于您的环境:

{
  "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
      }
    }
  }
}

关于linux - 在 linux box 上运行 nightwatch.js 测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37616881/

相关文章:

c - 在哪里查看 shell 返回值说明

javascript - 将文件添加到目录时在 node.js 中获取通知

javascript - AppJS 拖放事件从未触发

internet-explorer - 当用户使用 Selenium 代理 BrowserMob 时无法在 IE 中打开 https 站点

linux - 将视频与入点/出点拼接在一起

linux - 如何在 Ubuntu 终端中退出 emacs 文本编辑器?

c - 让后台进程监听键盘输入

node.js - 如何使用 loopback.io 在 REST 中包含相关实体

java - 如何捕获 Selenium 中多个段落标签的所有换行文本?

internet-explorer - 通过在 webdriver/protractor 中传递参数来关闭 Internet Explorer 上的自动更正?