簡體   English   中英

劇作家相當於量角器的瀏覽器。不滿足條件時等待循環

[英]Playwright equivalent to Protractor's browser.wait to loop while condition is not met

我試圖找到一種在不滿足特定條件時在 Playwright 中循環的方法。 在量角器中,我可以使用browser.wait 在我從 Protractor 遷移到 Playwright 的以下示例中,代碼在 refreshButton 不可見時單擊 refreshButton,一旦它可見,它就單擊 testButton:

        await browser.wait(async function () {
            return testButton.isPresent().then(async function (present) {
                // Refresh the grid until testButton is present
                if (present) {
                    await testButton.click();
                    return true;
                } else {
                    await refreshButton.click();
                    return false;
                }
        });

我已經看到 Playwright 提供了一組調用來等待特定條件,例如 waitForSelector,但我在嘗試讓它們循環工作時遇到了麻煩,因為在承諾之前不會解決簡單的問題。

從 Playwright v1.29 開始,您可以重試代碼塊,直到所有斷言都通過:

await expect(async () => {
    await expect(testButtonLocatorHere).toBeVisible();
}).toPass();

await testButtonLocatorHere.click();

我想這可能就是你要找的:)

您也可以將輪詢視為一種可能的解決方案。 我以前用過它來解決與您的問題類似的問題。

暫無
暫無

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

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