我已经看过这个solution,但没有帮助。
我正在尝试使用Mocha运行webdriver.io测试,这里我使用的是来自webdriver.io的browser.waitUntil()方法,更多详细信息请参见:https://webdriver.io/docs/api/browser/waitUntil.html 我已经尝试了另一种方法来解决该问题,包括在方法调用中添加“ done”,并且还在10000ms中在conf.js中提供了最大超时,但是该页面似乎仍然挂在结果页面上。 >
此处增加超时时间:
mochaOpts: {
ui: 'bdd',
timeout: 100000
},
将摩卡咖啡的默认等待时间更改为100000ms 添加完成作为承诺解决方案
it('should see product and version selected', () => {
browser.url('//some url');
browser.maximizeWindow();
browser.waitUntil(() => {
return $(ProductPage.productSelector()).isDisplayed()
}, 100000, 'expected page is loaded');
let productSelector = ProductPage.otherProductSelector();
let isEnabled = productSelector.isEnabled();
if(isEnabled == true){
const spanEle = $('//span[contains(text(),"text")]');
isDisplayed = spanEle.isDisplayed();
console.log(isDisplayed);
assert.equal(isDisplayed, true, "Passed");
}
})
错误:
Timeout of 100000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
答案 0 :(得分:0)
it('should see product and version selected', (done) => {
browser.url('//some url');
browser.maximizeWindow();
browser.waitUntil(() => {
return $(ProductPage.productSelector()).isDisplayed()
}, 100000, 'expected page is loaded');
let productSelector = ProductPage.otherProductSelector();
let isEnabled = productSelector.isEnabled();
if(isEnabled == true){
const spanEle = $('//span[contains(text(),"text")]');
isDisplayed = spanEle.isDisplayed();
console.log(isDisplayed);
assert.equal(isDisplayed, true, "Passed");
}
done();
})
我唯一能想到的是done
并没有传递给测试回叫
it('should see product and version selected', (done) => {})
,然后在最后调用。测试中没有任何东西可以返回承诺。
答案 1 :(得分:0)
在这里,我从测试中删除了browser.waitUntil(()=> {..}语句,并添加了WebdriverIO提供的不同等待时间。似乎有一些与诺言有关的问题,此方法无法解决通过兑现承诺或其他任何方式,我都知道,请在此答案中添加评论。 以下是更多详细信息:https://github.com/webdriverio/webdriverio/issues/2361
所以我所做的更改如下:
it('should see product and version selected', () => {
browser.url('url');
browser.maximizeWindow();
let productSelector = $('#product-dropdown-toggle')
let isEnabled = productSelector.isEnabled();
if(isEnabled == true){
const spanEle = $('//span[contains(text(),"text")]');
isDisplayed = spanEle.isDisplayed();
console.log(isDisplayed);
assert.equal(isDisplayed, true, "Passed");
}
})
waitForElemenDisplayed(element,timeout){
element.waitForDisplayed(timeout);
}