相关疑难解决方法(0)

Cypress.io 如何处理异步代码

我正在将我们的旧水豚测试迁移到 cypress.io,因为我们的应用程序正在采用 SPA 方式。

在我们的例子中,我们有 2000 多个测试涵盖了很多功能。因此,测试功能的常见模式是让用户创建和发布商品。

一开始我写了一个案例,其中柏树通过页面并点击所有内容。它起作用了,但我看到要约创建 + 发布花了将近 1.5 分钟才能完成。有时我们需要多个报价。所以我们有一个需要 5 分钟的测试,我们还有 1999 年要重写。

我们想出了 REST API 来创建报价和用户,基本上是测试环境准备的快捷方式。

我到了使用async/await. 所以这就是事情。如果我想在 cypress 中使用普通的异步 JS 代码,我会得到Error: Cypress detected that you returned a promise from a command while also invoking one or more cy commands in that promise.

这是它的样子:

    const faker = require('faker')
    import User from '../../support/User';

    describe('Toggle button for description offer', () => {
      const user = new User({
        first_name: faker.name.firstName(),
        last_name: faker.name.firstName(),
        email: `QA_${faker.internet.email()}`,
        password: 'xxx' …
Run Code Online (Sandbox Code Playgroud)

javascript testing async-await cypress

18
推荐指数
4
解决办法
3万
查看次数

标签 统计

async-await ×1

cypress ×1

javascript ×1

testing ×1