nightwatch.js互联网浏览器

DSD*_*ev7 1 javascript selenium nightwatch.js e2e-testing

我正在使用守夜来测试我的javascript应用程序。我需要能够在本地计算机上运行跨浏览器测试。Chrome和Firefox可以,但是在IE上运行测试时出现错误:

Running:  google.com
    TypeError: undefined is not a function
    at pass (C:\Users\Dávid\AppData\Roaming\npm\node_modules\nightwatch\lib\api\
assertions\urlContains.js:23:18)
    at Object.<anonymous> (C:\Users\Dávid\AppData\Roaming\npm\node_modules\night
watch\lib\core\assertion.js:94:23)
    at HttpRequest.<anonymous> (C:\Users\Dávid\AppData\Roaming\npm\node_modules\
nightwatch\lib\index.js:299:20)
    at HttpRequest.emit (events.js:110:17)
    at HttpRequest.<anonymous> (C:\Users\Dávid\AppData\Roaming\npm\node_modules\
nightwatch\lib\index.js:346:15)
    at HttpRequest.emit (events.js:118:17)
    at IncomingMessage.<anonymous> (C:\Users\Dávid\AppData\Roaming\npm\node_modu
les\nightwatch\lib\http\request.js:150:16)
    at IncomingMessage.emit (events.js:129:20)
    at _stream_readable.js:908:16
    at process._tickCallback (node.js:355:11)
Run Code Online (Sandbox Code Playgroud)

IEDriverServer的硒版本为2.45.0。我在64b Windows 8.1上使用x64版本。而且我已经完成了IE11的注册表操作。

测试文件:

module.exports = {
    'google.com': function(browser){
        return browser
            .url('www.google.com')
            .pause(5000)
            .assert.urlContains('google')
            .end();
    }
}
Run Code Online (Sandbox Code Playgroud)

nightwatch.json:

{
    "src_folders" : ["./tests/e2e"],
    "output_folder" : "./tests/reports",
    "custom_assertions_path" : "",
    "globals_path" : "",
    "live_output" : false,
    "parallel_process_delay" : 10,
    "disable_colors": false,

    "selenium" : {
        "start_process" : true,
        "server_path" : "./bin/selenium-server-standalone-2.45.0.jar",
        "log_path" : "",
        "host" : "127.0.0.1",
        "port" : 4444,
        "cli_args" : {
        "webdriver.chrome.driver" : "",
        "webdriver.ie.driver" : "./bin/IEDriverServer.exe",
        "webdriver.firefox.profile" : ""
    }
},

"test_settings" : {
    "default" : {
        "launch_url" : "http://localhost:3001",
        "selenium_host" : "127.0.0.1",
        "selenium_port" : 4444,
        "silent" : true,
        "disable_colors": false,
        "screenshots" : {
            "enabled" : false,
            "path" : ""
        },
        "desiredCapabilities" : {
            "browserName" : "firefox",
            "javascriptEnabled" : true,
            "acceptSslCerts" : true
        }
    },
    "chrome": {
        "desiredCapabilities" : {
            "browserName" : "chrome",
            "javascriptEnabled" : true,
            "acceptSslCerts" : true
        }
    },
    "ie": {
        "desiredCapabilities": {
            "browserName" : "internet explorer",
            "javascriptEnabled" : true,
            "acceptSslCerts" : true
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

运行命令:

nightwatch --env ie
Run Code Online (Sandbox Code Playgroud)

在此行失败:

.assert.urlContains('google')
Run Code Online (Sandbox Code Playgroud)

对于所有帮助,在此先感谢。

Dan*_*ley 6

我看到您有解决方案,但是我自己经历了此事,我想我会把这里留给以后的人们。

Selenium文档说Internet Explorer需要特定的配置

  • IEDriverServer需要在路径中。我的经验是,使用%PATH%令人惊讶地异常,我要么:

    • 设置webdriver.ie.drivercli_argsnightwatch.json中的路径
    • 手动启动Selenium Server java -jar selenium-server-standalone-2.47.1.jar -Dwebdriver.ie.driver=.\IEDriverServer.exe
  • IE中的保护模式(“工具”>“ Internet选项”>“安全性”)对于所有区域都必须相同(如您所见!)。我经常在本地和VM上进行测试,因此我为“本地”和“可信”启用了它,而不是为Internet区域禁用了它。

  • 将缩放比例设置为100%(不过,为什么不呢?)

  • 对于IE10 +,需要禁用增强保护模式(“工具”>“ Internet选项”>“高级”>“安全性”)。可以肯定的是,在Windows的客户端版本上默认情况下已禁用此功能,但在服务器版本上已启用该功能。

  • 对于IE11 +,请执行reghack以促进硒服务器和浏览器实例之间的连接。在中HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE添加DWORD iexplore.exe并将其设置为0。如果您运行的是64位Windows,则该路径将变为HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE

从我的经验中可以得出以下几点:

  • 如果您使用的是64位Windows,请不要被64位IEDriverServer吸引。太慢了 “比自动柜员机前面的老太太慢”。