在linux上使用nightwatch运行selenium测试

时间:2016-06-03 16:32:55

标签: linux node.js selenium nightwatch.js

我有一个linux盒子,我正试图在它上面运行selenium测试(用nightwatch编写)。我安装了chromedriver http://chromedriver.storage.googleapis.com/index.html?path=2.9/ (linuxx64位一)

我还安装了独立的硒罐

我运行以下命令

DISPLAY=:1 xvfb-run java -jar lib/selenium-server-standalone-2.52.0.jar -Dwebdriver.chrome.driver=lib/chromedriver

这是我的夜班配置:

{
    "src_folders": [
        "tests"
    ],
    "output_folder": "reports",
    "custom_commands_path": "custom_commands",
    "custom_assertions_path": "",
    "page_objects_path": "",
    "live_output" : true,
    "globals_path": "globals.js",
    "selenium": {
        "start_process": true,
        "server_path": "lib/selenium-server-standalone-2.52.0.jar",
        "log_path": "",
        "host": "127.0.0.1",
        "port": 4444,
        "cli_args": {
            "webdriver.chrome.driver": "lib/chromedriver",
            "webdriver.chromeJenkins.driver": "../../tools/chromedriver/chromedriver",
            "webdriver.ie.driver": "lib/IEDriverServer_x64_2.52.2.exe",
            "trustAllSSLCertificates": true
        }
    },
    "test_workers": {
        "enabled": true,
        "workers": "auto"
    },
    "test_settings": {
        "default": {
            "launch_url": "",
            "selenium_port": 4444,
            "selenium_host": "localhost",
            "silent": true,
            "screenshots": {
                "enabled": true,
                "on_failure": true,
                "on_error": true,
                "path": "./screenshots"
            },
            "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"
                    ]
                }
            }
        },
      "jenkins" : {
            "selenium_port"  : 4444,
            "selenium_host"  : "127.0.0.1",
            "cli_args" : {
                "webdriver.chrome.driver" : "lib/chromedriver"
        },
        "chromeOptions" : {
             "args" : ["--no-sandbox"]
        },
            "desiredCapabilities": {
                "browserName": "chrome",
                "javascriptEnabled": true,
                "acceptSslCerts": true,
                "platform" : "LINUX",
            "chromeOptions" : {
                "args" : ["--no-sandbox"]
            } 
            }
    }
}   

然后我运行以下命令

 DISPLAY=:1 xvfb-run --server-args="-screen 0, 1366x768x24" ./nightwatch -e jenkins --test tests/blog.js

测试开始运行,但是当我查看输出时,驱动程序会卡在特定元素上。它试图找到元素,但超时。当我在本地计算机上运行测试时,我没有收到此错误。

我在这里做错了吗?

1 个答案:

答案 0 :(得分:0)

检查浏览器视口大小。它在xvfb中可能比在主屏幕上更小,而且您的测试网站可能会改变不同分辨率下的行为。看到我的第一天。

TL; DR 我的chrome窗口大小相同,但打开调试窗格会改变站点行为。