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

Testcafe: repeat click until another element appears

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

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

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

await t
  .click(Button)
  .click(Button)
  .click(Button)
  .click(ModalDialogButton);

我需要一种重复点击 Button 直到出现 ModalDialogButton 的方法。然后,必须单击 ModalDialogButton

如何使用 testcafe 执行此操作?

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

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

await t.click(ModalDialogButton);

能否说明一下重复点击的需求?也许你可以等待 ModalDialogButton 存在。例如:

await ModalDialogButton();

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