簡體   English   中英

量角器 - 頁面加載時等待 X 秒,如果仍未加載 - 再次單擊按鈕

[英]Protractor - wait X seconds while page loading, if still not loaded - click button again

我的問題是我有非角度登錄頁面,但有時當點擊登錄按鈕時它會停止加載(登錄頁面仍然可見)。

我想要的是點擊登錄按鈕后我給它ex。 5 秒完成加載,如果不是 - 我想再次單擊登錄按鈕。

最好的方法是什么? 我當前的代碼部分如下所示:

browser.waitForAngularEnabled(false);
await browser.driver.wait(EC.visibilityOf(this.getLoginForm()), 10000);
await this.usernameInput.sendKeys(username);
await this.passwordInput.sendKeys(password);
await this.clickLogInButton();
//here I want condition with timeout for page loading with repeat clickLogInButton if necessary
browser.waitForAngularEnabled(true);

我認為最好的方法是try/catch即使我很少建議使用它

// since you may wait for home page twice, you want to make it a function to avoid duplicate code
let waitForHomePage = async function () {
  await browser.wait(
    EC.visibilityOf(welcomeMessage), <-- give it a home page specific element
    10000
  )
}

await browser.waitForAngularEnabled(false); // <-- don't forget await here
await browser.driver.wait(EC.visibilityOf(this.getLoginForm()), 10000);
await this.usernameInput.sendKeys(username);
await this.passwordInput.sendKeys(password);
await this.clickLogInButton();

try {
  await waitForHomePage();
} catch (e) {
  await this.clickLogInButton();
  await waitForHomePage();
}

await browser.waitForAngularEnabled(true); // <-- don't forget await here

我最多等待 10 秒,如果 10 秒后主頁仍未出現,它將再次單擊並等待

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM