【问题标题】:Cypress asynchronous execution returns 4 same assertionCypress 异步执行返回 4 个相同的断言
【发布时间】:2022-01-24 13:18:23
【问题描述】:

我有一个问题。 我正在使用 Cypress 进行自动化,我开始使用 async 并等待我的测试。 我正在使用 POM 设计模式。

我的问题: 如果我执行以下测试:

test.spec.ts 类(测试类)

import { login_po } from "../pom/1.Chiquito/login_po";
const pom = new login_po()

describe("Put some name here.", async() => {
    it('TestCase1', async () => {
        await pom.navigateTo();
    });
});

我的 POM 课程。

export class login_po {

    navigateTo() {
        cy
            .visit(`https://chiquito-qa.omnifitrgsites.co.uk/`)
            .url()
            .should('be.equal', 'https://chiquito-qa.omnifitrgsites.co.uk/').then(() => this.verifyAfterLogin());
    }

    verifyAfterLogin() {
        cy.get('.header__logo-img');
    }
}

当我执行测试时 - 赛普拉斯做出 4 个(相同的)断言。

如果我从测试类中删除 'async' - 'await' - Cypress 会做出 1 个断言。

import { login_po } from "../pom/1.Chiquito/login_po";
const pom = new login_po()

describe("Put some name here.", () => {
    it('TestCase1', () => {
        pom.navigateTo();
    });
});

为什么会这样?

【问题讨论】:

    标签: async-await cypress type-assertion


    【解决方案1】:

    Cypress commands are not promises,它们与 async/await 的交互不会像你期望的那样发生。此外,虽然 POM 在 Cypress 中是可行且合理的,但 it is recommended that you use App Actions 而不是 POM。

    【讨论】:

      猜你喜欢
      • 2021-07-16
      • 1970-01-01
      • 2016-07-25
      • 1970-01-01
      • 2012-02-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多