nightwatch.js 互联网浏览器
nightwatch.js internet explorer
我正在使用 nightwatch 来测试我的 javascript 应用程序。我需要能够 运行 在本地机器上进行跨浏览器测试。 Chrome 和 Firefox 都可以,但是在 IE 上 运行ning 测试时,出现错误:
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 的版本为 2.45.0,与使用的 selenium 相同。我在 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')
在此先感谢所有帮助。
我尝试了您的测试,它在我装有 Nightwatch v0.6.13 的笔记本电脑上运行良好。您使用哪个版本的 Nighwatch? (npm list nightwatch -g)
我已经通过为所有区域禁用 IE 保护模式并将所有区域的安全级别降低到尽可能低的级别解决了这个问题。
我看到你有一个解决方案,但我自己已经解决了这个问题,我想我会把它留给未来的人。
Selenium docs 说 Internet Explorer 需要特定配置
IEDriverServer 需要在路径中。我的经验是使用 %PATH% 出奇地不稳定,我要么:
- 将
webdriver.ie.driver
设置为nightwatch.jsoncli_args
中的路径
- 使用
java -jar selenium-server-standalone-2.47.1.jar -Dwebdriver.ie.driver=.\IEDriverServer.exe
手动启动 Selenium 服务器
IE 中的保护模式(工具 > Internet 选项 > 安全)需要对所有区域都相同(如您所见!)。我经常在本地和 VM 上进行测试,所以我为 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 的诱惑。它很慢。 "Slower than the old lady in front of you at the ATM"慢。
我正在使用 nightwatch 来测试我的 javascript 应用程序。我需要能够 运行 在本地机器上进行跨浏览器测试。 Chrome 和 Firefox 都可以,但是在 IE 上 运行ning 测试时,出现错误:
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 的版本为 2.45.0,与使用的 selenium 相同。我在 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')
在此先感谢所有帮助。
我尝试了您的测试,它在我装有 Nightwatch v0.6.13 的笔记本电脑上运行良好。您使用哪个版本的 Nighwatch? (npm list nightwatch -g)
我已经通过为所有区域禁用 IE 保护模式并将所有区域的安全级别降低到尽可能低的级别解决了这个问题。
我看到你有一个解决方案,但我自己已经解决了这个问题,我想我会把它留给未来的人。
Selenium docs 说 Internet Explorer 需要特定配置
IEDriverServer 需要在路径中。我的经验是使用 %PATH% 出奇地不稳定,我要么:
- 将
webdriver.ie.driver
设置为nightwatch.jsoncli_args
中的路径 - 使用
java -jar selenium-server-standalone-2.47.1.jar -Dwebdriver.ie.driver=.\IEDriverServer.exe
手动启动 Selenium 服务器
- 将
IE 中的保护模式(工具 > Internet 选项 > 安全)需要对所有区域都相同(如您所见!)。我经常在本地和 VM 上进行测试,所以我为 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 的诱惑。它很慢。 "Slower than the old lady in front of you at the ATM"慢。