我对摩卡咖啡很陌生,到目前为止,我似乎很喜欢它。但是我确实遇到了一个小问题,似乎它试图太快地找到pageTitle,如果幸运的话,它实际上设法找到了标题,但有时却找不到,我正在寻找一种类似“等到元素”的方法出现,如果没有在10秒钟后出现错误,则抛出错误“
browser.get(url);
it('should have a title', (done) => {
browser.driver
.then(() => browser.getPageTitle())
.then((text) => {
assert.equal(text, "TEST", 'Not able to find the title');
})
.then(() => done());
});
现在,如果我很幸运,它设法抓住了它,但大多数情况下会引发错误,这是一个空的响应,我相信由于速度太快而无法获得标题。我该如何使某个功能类似“等待标题出现,如果没有在10秒后出现错误”
尝试一下:
`setTimeout(()=> {browser.get(URL);
it('should have a title', (done) => {
browser.driver
.then(() => browser.getPageTitle())
.then((text) => {
assert.equal(text, "TEST", 'Not able to find the title');
})
.then(() => done());
});
},1000);`
听起来像您需要带有browser.wait
的expectedCondition。试试这个
browser.wait(protractor.ExpectedConditions.urlContains('required_url'),
10*1000,
"Url did not contain 'required_url' within 10 seconds"
);