Testcafe:重复单击,直到出现另一个元素

时间:2019-05-04 21:44:40

标签: javascript async-await functional-testing e2e-testing testcafe

我正在用testcafe测试用户界面。

要求用户单击按钮,直到出现模式对话框,然后应在对话框中单击按钮。

在测试中,点击次数可能会有所不同,有时是2次,有时是3次。因此,此代码并不总是有效

shading interp

我需要一种方法来反复单击await t .click(Button) .click(Button) .click(Button) .click(ModalDialogButton); ,直到出现Button。然后,必须单击ModalDialogButton

如何用testcafe做到这一点?

1 个答案:

答案 0 :(得分:3)

您可以尝试使用while循环执行此操作,如下所示:

while (!(await ModalDialogButton.exists))
    await t.click(Button)

await t.click(ModalDialogButton);

能否请您说明是否需要多次点击?也许您可以只等待ModalDialogButton存在。例如:

await ModalDialogButton();

此行自动等待,直到ModalDialogButton选择器以默认超时出现在页面上。您可以增加selector timeout