失败时重新启动夹具

Restart fixture when it fails

我编写的测试在 95% 的时间内通过,其余 5% 的情况下未通过。我仍然不知道为什么它会失败(我的猜测是组件没有正确呈现)。

我实现了页面重新加载调用以重新加载页面并重试,但它不是很可靠。

万一 fixture 失败,最好的重启方法是什么?

这是一个示例测试,它故意未能模拟我的选择器,该选择器大部分时间都有效,但有时会失败。

import { Selector } from 'testcafe';

const URL = 'https://www.youtube.com/watch?v=RWQtB6Xv01Q';

fixture `Portal Experience playback`
  .page `${URL}`;

test('Testing YouTube', async t => {
  await t.click(Selector('.wrong-selector')); // to emulate my unstable test
});

结果

✖ Testing YouTube

   1) The specified selector does not match any element in the DOM tree.

是否可以将测试放在 for 循环中,并在测试通过时跳出循环?

quarantine mode serves this purpose. In this mode, TestCafe will restart a failed test again until it passes or fails 3 times and will consider it failed only if it fails 3 times. Get more details about the quarantine mode in this article: Quarantine Mode.