【问题标题】:nightwatch.js internet explorernightwatch.js 互联网浏览器
【发布时间】:2015-06-06 09:38:21
【问题描述】:

我正在使用 nightwatch 测试我的 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)

IEDriverServer 和 selenium 一样是 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();
    }
}

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

运行命令:

nightwatch --env ie

在这一行失败:

.assert.urlContains('google')

提前感谢所有帮助。

【问题讨论】:

    标签: javascript selenium e2e-testing nightwatch.js


    【解决方案1】:

    我知道你有一个解决方案,但我自己也经历过这个,我想我会把这个留给未来的人。

    Selenium docs说 Internet Explorer 需要特定配置

    • IEDriverServer 需要在路径中。我的经验是,使用 %PATH% 非常不稳定,我要么:

      • webdriver.ie.driver 设置为 nightwatch.json 的 cli_args 中的路径
      • 使用java -jar selenium-server-standalone-2.47.1.jar -Dwebdriver.ie.driver=.\IEDriverServer.exe 手动启动 Selenium 服务器
    • IE 中的保护模式(工具 > Internet 选项 > 安全)需要对所有区域都相同(如您所见!)。我经常在本地和虚拟机上进行测试,因此我为 Local 和 Trusted 启用了它,而不是为 Internet 区域禁用它。

    • 将缩放设置为 100%(虽然,你知道,为什么不这样呢?)

    • 对于 IE10+,需要禁用增强保护模式(工具 > Internet 选项 > 高级 > 安全)。很确定这在 Windows 的客户端版本上默认禁用,但在服务器版本上启用。

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

    我的经验补充一点:

    • 如果您使用的是 64 位 Windows,请不要被 64 位 IEDriverServer 所诱惑。它很慢。 “比你面前 ATM 的老太太慢”慢。

    【讨论】:

    • 嘿,我正在尝试在 IE 驱动程序中运行 selenium 测试,但遇到了问题,尤其是在 nativeEvents 设置为 true 时单击元素。在 IE 中测试时您的配置是什么样的?
    【解决方案2】:

    我已通过禁用所有区域的 IE 保护模式以及将所有区域的安全性降低到最低级别来解决此问题。

    【讨论】:

      【解决方案3】:

      我尝试了您的测试,它在装有 Nightwatch v0.6.13 的笔记本电脑上运行良好。您使用哪个版本的守夜人? (npm list nightwatch -g)

      【讨论】:

      • 守夜人 v0.6.13。您是否复制粘贴了所有内容,包括nighwatch.json?你用过哪个版本的 selenium?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-20
      • 2011-06-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多