javascript_JavaScript waitForTime 红太狼 2023-02-21 14:28 4阅读 0赞 javascript I write a lot of tests for new features within Firefox DevTools. We have hundreds of "mochitests" which open the browser and perform synthetic actions like clicking, typing, and other user actions. I've previously written about [`waitForever`][waitForever] which essentially halts following actions without locking the browser. Another utility I enjoy is `waitForTime`, an async JavaScript function that I can `await` to give breathing time between two tasks. 我为Firefox DevTools中的新功能编写了许多测试。 我们有数百个“ mochitests”,它们可以打开浏览器并执行诸如单击,键入和其他用户操作之类的综合操作。 之前,我曾写过关于[`waitForever`][waitForever] ,它实际上是在不锁定浏览器的情况下停止了后续操作。 我喜欢的另一个实用程序是`waitForTime` ,这是一个异步JavaScript函数,可以`await`两个任务之间的喘息时间。 Whenever I want to wait a given amount of time between tasks, I employ this function: 每当我想在任务之间等待给定的时间时,我都会使用以下功能: function waitForTime(ms) { return new Promise(r => setTimeout(r, ms)); } /* Usage */ await waitForTime(200); // ...do other thing... await waitForTime(200); // ...do next thing ... It's important to point out that most `waitForTime` calls don't appear in the final test, since arbitrary timeouts lead to intermittent test failures, but they are helpful in knowing where I need to add polling for some other condition! 重要的是要指出,大多数的`waitForTime`调用不会出现在最终测试中,因为任意超时都会导致间歇性的测试失败,但是它们对于了解在其他情况下需要在何处添加轮询很有帮助! > 翻译自: [https://davidwalsh.name/waitfortime][https_davidwalsh.name_waitfortime] javascript [waitForever]: https://davidwalsh.name/javascript-wait [https_davidwalsh.name_waitfortime]: https://davidwalsh.name/waitfortime
相关 javascript_JavaScript waitForTime javascript I write a lot of tests for new features within Firefox DevTools. We have hun 红太狼/ 2023年02月21日 14:28/ 0 赞/ 5 阅读
还没有评论,来说两句吧...