我正在使用chimp.js,它通过一些纤维魔法增强了 webdriver.io,以便可以以同步方式定义代码。这是代码:
var c = require('./config');
module.exports = function () {
this.When(/^I try to login with wrong credentials$/, function () {
browser.setValue(userNameField, wrongUser);
browser.setValue(passwordField, wrongPassword);
browser.click('button[value="Login"]');
});
this.When(/^I try to login with the correct credentials$/, function () {
browser.setValue(userNameField, c.userName);
browser.setValue(passwordField, c.password);
console.log('before pressig the button');
browser.click('button[value="Login"]');
console.log('logged in');
});
};
第一个When
执行得很好。第二个When
也有效,我只是看不到
登录
在控制台上。两者都在同一个网站上运行,并且都单击同一个按钮。在第二种情况下,登录成功后,浏览器被重定向到一个 Angular SPA。在这里一切都正确加载,但就是这样。回调永远不会发生。
运行测试--debug --log=command
我看到这是最后一行(在超时之前)
[1;30m[01:30:18]: [0m [0;35mCOMMAND [0mPOST "/wd/hub/session/7c334efe-2417-4184-b43c-082ba4441291/element/11/click"
将日志级别切换为详细,然后等待约 5 分钟,我收到以下错误:
[chimp][selenium.stderr] 01:36:59.561 DEBUG - Executed: [0560aaa14e4cf874afd72336c19e299b, clickElement {id=0.6384125368203968-3}]
[chimp][selenium.stderr] 01:37:02.449 WARN - Exception thrown
org.openqa.selenium.TimeoutException: timeout: Timed out receiving message from renderer: 10.000
(Session info: chrome=47.0.2526.73)
(Driver info: chromedriver=2.19.346063 (38b35413bd4a486d436a9749e090454bc9ff6708),platform=Mac OS X 10.11.0 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 310.12 seconds
Build info: version: '2.47.1', revision: '411b314', time: '2015-07-30 03:03:16'
System info: host: '<HOST_NAME>', ip: '<IP_ADDRESS>', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.11', java.version: '1.8.0_20'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, chrome={userDataDir=/var/folders/nc/3cdxbvwj44j_gk1qj24mbr5w0000gn/T/.org.chromium.Chromium.1n3kHd}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=47.0.2526.73, platform=MAC, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 0560aaa14e4cf874afd72336c19e299b
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:595)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:273)
at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:84)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.openqa.selenium.support.events.EventFiringWebDriver$EventFiringWebElement$1.invoke(EventFiringWebDriver.java:332)
at com.sun.proxy.$Proxy3.click(Unknown Source)
at org.openqa.selenium.support.events.EventFiringWebDriver$EventFiringWebElement.click(EventFiringWebDriver.java:345)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.openqa.selenium.remote.server.KnownElements$1.invoke(KnownElements.java:64)
at com.sun.proxy.$Proxy2.click(Unknown Source)
at org.openqa.selenium.remote.server.handler.ClickElement.call(ClickElement.java:30)
at org.openqa.selenium.remote.server.handler.ClickElement.call(ClickElement.java:1)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at org.openqa.selenium.remote.server.DefaultSession$1.run(DefaultSession.java:176)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
[chimp][selenium.stderr] 01:37:02.458 WARN - Exception: timeout: Timed out receiving message from renderer: 10.000
(Session info: chrome=47.0.2526.73)
(Driver info: chromedriver=2.19.346063 (38b35413bd4a486d436a9749e090454bc9ff6708),platform=Mac OS X 10.11.0 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 310.12 seconds
Build info: version: '2.47.1', revision: '411b314', time: '2015-07-30 03:03:16'
System info: host: '<HOST_NAME>', ip: '<IP_ADDRESS>', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.11', java.version: '1.8.0_20'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, chrome={userDataDir=/var/folders/nc/3cdxbvwj44j_gk1qj24mbr5w0000gn/T/.org.chromium.Chromium.1n3kHd}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=47.0.2526.73, platform=MAC, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 0560aaa14e4cf874afd72336c19e299b
[chimp][selenium.stderr] 01:37:02.471 DEBUG - Finished: POST /session/e103e58b-7ac9-4c8d-8f65-1f60295231d9/element/11/click
平均需要 3-7 秒来加载 SPA 的第一页,初始化数据,...(chrome 停止显示页面正在加载)。超时设置为 10 秒,所以我想增加它,通过
module.exports = function () {
this.BeforeScenario(function () {
browser.timeout('script', 60 * 1000);
browser.timeout('page load', 60 * 1000);
});
};
但这也无济于事。知道我能做什么/尝试吗?
再次澄清一下——登录页面是一个简单的静态服务器端呈现的 HTML。用户登录后,他们会被重定向到基于 Angular 1.4 的 SPA。使用错误的凭据按下登录按钮可能会起作用,因为我没有被重定向到 SPA,而是返回到登录页面。
所有测试都在 chrome 中运行,在 Mac OS X El Capitan 上
更新:
现在它工作了一次。之后我注意到,当我重新加载网站时,脚本会继续运行,以防它卡住。
此处有问题的页面以这种方式工作:
/
访问页面并初始化角度- ui-router 路由到
#/defaultroute
- 控制器被初始化并下载一些初始数据
- 新控制器在内部初始化
ng-repeat
并下载更多数据
所以,是的,它需要大量的数据下载并等待整个页面显示出来。也许这会给 chimp.js 或 webdriver.io 带来麻烦?
当然,从browser.click(...);
to切换browser.key(['Enter']);
也不起作用。卡住和重新加载浏览器的相同问题可以解决它。似乎 silenium 可能没有让页面实际完成加载。这就是为什么重新加载页面可以修复它。知道如何解决吗?
顺便说一句,我还打开了一个关于此的问题:https ://github.com/xolvio/chimp/issues/165
更新 2:
在 Firefox 和 PhantomJS 中它可以工作,Safari 根本不运行。
也许此时我只想知道错误在哪里,如果它是一个已知的错误,......