我正在使用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的版本为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')
提前感谢所有人的帮助。
答案 0 :(得分:5)
我看到你已经找到了一个解决方案,但是我自己也经历过这个问题,我想我会把它留给未来的人。
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
IE中的保护模式(工具&gt; Internet选项&gt;安全性)需要对所有区域都相同(如您所见!)。我经常在本地和虚拟机上进行测试,所以我为Local和Trusted启用了它,而不是为Internet区域禁用它。
将缩放设置为100%(虽然,你知道,为什么不是?)
对于IE10 +,需要禁用增强保护模式(工具&gt; Internet选项&gt;高级&gt;安全性)。非常确定在Windows的客户端版本上默认禁用此功能,但在服务器版本上启用。
对于IE11 +,请进行重新编程,以便于selenium服务器和浏览器实例之间的连接。在HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE
中为iexplore.exe
添加一个DWORD,并将其设置为0
。如果您运行的是64位窗口,则该路径将变为HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE
。
根据我的经验另外一个:
答案 1 :(得分:2)
我已通过为所有区域禁用IE保护模式以及将安全性降低到所有区域的最低级别来解决此问题。
答案 2 :(得分:0)
我尝试了你的测试,它在我的笔记本电脑上使用Nightwatch v0.6.13正常工作。你使用哪个版本的Nighwatch? (npm list nightwatch -g)