为此:
// Mocha timeout
this.timeout(50000);
!!!
arrow function
摩卡咖啡不鼓励这样做。了解更多信息
here
.
解决方案
(根据您的设置选择):
-
WebdriverIO test-runner
并设置
mochaOpts: { timeout: <desiredTimeout>}
,或者您甚至可以从测试运行中覆盖它:
wdio wdio.config.js --mochaOpts.timeout=<desiredTimeout>
-
设置您的
timeout
describe
声明,甚至更好,在
before
挂钩:
before(function() { this.timeout(<desiredTimeout>); (...)});
-
如果您使用Mocha运行测试用例,请将超时传递到CLI命令中(如果您使用它来运行测试):
mocha yourTestFile.js --timeout <desiredTimeout>
,或更改其在您的
mocha.opts
注:
browser.waitUntil( function() {
return browser.isExisting('[name=lastName]');
});
!!!
这将始终等待
element
name="lastName"
默认情况下
1000 ms
在超时之前。该值可以通过以下方式更改:
waitforTimeout
解决方案
-
明确给出您的
waitUntil...
/
waitfor...
browser.waitUntil( function() { return browser.isExisting('[name=lastName]');}, <desiredTimeout>, <errorMessage>);
;
-
使用运行脚本
WebdriverIO测试运行程序
并设置
waitforTimeout: <desiredTimeout>
wdio wdio.config.js --waitforTimeout=<desiredTimeout>
最后,我试着运行了几个具有淫秽超时值的测试用例(
50000 ms
)对于你提到的每一个问题,它都像预期的那样起作用。
waitforTimeout示例
:
日志
(
1 failing (57s)
):
[chrome #0-0] ConnectWeb Devices Content Test Suite
[chrome #0-0] 1) "before all" hook
[chrome #0-0]
[chrome #0-0]
[chrome #0-0] 1 failing (57s)
[chrome #0-0]
[chrome #0-0] 1) ConnectWeb Devices Content Test Suite "before all" hook:
[chrome #0-0] Oups! An error occured.
Timed out waiting for element ('span[connectqa-device="events"]') to exist
注:
我以前从未在WebdriverIO中使用过Selenium超时(
implicit
pageLoad
,
script
)但是我以前从来没有这样的必要性
对于我的测试场景来说非常有效。
本声明
inserting any amount of async behaviour is making it time out at the 10 sec threshold
sync: true
但在幕后,一切仍然是异步的。