如何编写cypress测试来捕捉ant成功弹出的消息?

问题描述 投票:0回答:1

目前,点击“加入”按钮后,它会立即显示成功弹出的消息,而我的

cy.get("div.ant-message-custom-content.ant-message-success").should("be.visible");
线无法捕捉到它。这是我的完整测试:

    context("Student join a class", () => {
      context("Using account having joined no classes", () => {
        beforeEach(() => {
          cy.visit("http://localhost:3000/auth/login");
    
          cy.fixture("student/student-no-classes.json").then((data) => {
            cy.login(data.username, data.password);
          });
    
          cy.url().should("include", "/home");
        });
        it("Join class using valid invite code from home page", function () {
          cy.fixture("student/successful-join-with-code-response1.json").then((response) => {
            this.joinResponse = response;
          });
    
          cy.intercept("POST", "/v1/classes/join-with-code/", (req) => {
            req.reply({
              statusCode: 200,
              body: this.joinResponse,
            });
          }).as("join-class");
    
          cy.get("button").contains("Get Started").click();
          cy.get("div").contains("Join a class").click();
          cy.fixture("student/invite-code-valid").then((data) => {
            cy.get("input#code").type(data.inviteCode);
          });
          cy.get("button").contains("Join").click();
    
          cy.get("div.ant-message-custom-content.ant-message-success").should("be.visible");
          cy.fixture("student/invite-code-valid").then((data) => {
            cy.url().should.be(`http://localhost:3000/classes/feeds/${data.slug}`);
          });
        });
      });
    });

ant cypress
1个回答
0
投票

将该行更改为

cy.contains("div", "Joined class successfully").should("be.visible");
解决了我的问题。使用选择器类可能会导致它找不到弹出窗口。

© www.soinside.com 2019 - 2024. All rights reserved.