javascript - 用 promises 替换 TestCafe async/await

标签 javascript promise automated-tests e2e-testing testcafe

出于某些原因,我试图用 Promises 替换 TestCafe Async/Await。下面是我使用 promises 代替 await 的代码块。

但是出现如下错误:未等待对异步函数的调用。在操作、断言或它们的链之前使用“await”关键字 以确保它们以正确的顺序运行。 enter image description here

最佳答案

如果你不想使用async/await,你可以从测试函数返回一个Promise:

fixture `Example`
    .page `example.com`;

test(`example`, t => {
   let promise = Promise.resolve(t);

   return promise
       .then(result => {
           return result.typeText('...');
       })
       .then(result => {
           return result.click('...');
       });
});

关于javascript - 用 promises 替换 TestCafe async/await,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55952402/

相关文章:

Javascript:在所有浏览器中检测$函数

php - JQuery:通过 AJAX 调用提交包含多个字段的表单

javascript - 重新绑定(bind)JavaScript Promise中resolve返回的值

javascript - 在 node.js 中返回一个延迟的嵌套 promise

javascript - "while"循环的 promise 版本?

c++ - Google 测试 - 使用 "SetUpTestSuite"似乎不起作用

c# - 使用 vstest.console.exe 工具运行 Selenium 测试时显示测试的 URL

javascript - 如何在 react 中从url获取数据

javascript - 如何修复嵌套样式组件中的缩进 eslint 错误?

spring - 使用 spring xml 作为后台进程/线程启动 jetty