简体   繁体   中英

Cypress asynchronous execution returns 4 same assertion

I have a question. I am using Cypress for my automation and I started using async and await for my tests. I am using POM design pattern.

My question: If I execute the following test:

test.spec.ts class (test class)

 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(); }); });

My POM class.

 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'); } }

When I execute the test - Cypress makes 4 (same) assertions. 在此处输入图像描述

If I remove 'async' - 'await' from the test class - Cypress makes 1 assertion.

 import { login_po } from "../pom/1.Chiquito/login_po"; const pom = new login_po() describe("Put some name here.", () => { it('TestCase1', () => { pom.navigateTo(); }); });

在此处输入图像描述

Why this is happening?

Cypress commands are not promises , and their interaction with async/await will not happen as you expect. Additionally, while POM is feasible and reasonable to do within Cypress, it is recommended that you use App Actions instead of a POM.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM