[英]Can't get title of the URL when loading too fast
我對摩卡咖啡很陌生,到目前為止我似乎很喜歡它。 但是我確實遇到了一個小問題,它似乎試圖太快地定位 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"
);
進口柴和柴作為承諾
const chai = require('chai').use(require('chai-as-promised'));
const expect = chai.expect;
現在嘗試使用 expect
it('Check page title', () => { expect(browser.getTitle()).toEqual('Protractor practice website - WebTables'); })
現在期望是柴斷言庫而不是默認的茉莉花。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.