1
votes

I am new to Cypress and i am checking HTML page. I need to test the login authentication and to log XHR body. So, I wrote a test like :

describe('Login test', function () {

    it("Test description", () => {
        cy.server();
        cy.visit("login");

        cy.route({
            method: "POST",
            url: '/login'
        }).as("login");

        cy.get('#username')
            .type(Cypress.env('Account'));

        cy.get('#password')
            .type(Cypress.env('Password'));

        cy.get('#login')
            .click();

        cy.wait("@login").then(xhr => {
            cy.log(JSON.stringity(xhr.response.body));
        });

    });
});

The test fail with a log of :

CypressError: Timed out retrying: cy.wait() timed out waiting 5000ms for the 1st request to the route: 'route_login'. No request ever occurred.

can any one help please ?

1

1 Answers

0
votes

Try this :

describe('Login test', function () {

it("Test description", () => {
    cy.server();


    cy.route({
        method: "POST",
        url: '/login'
    }).as("login");

    cy.wait("@login", {timeout: 15000});

    cy.visit("login");

    cy.get('#username')
        .type(Cypress.env('Account'));

    cy.get('#password')
        .type(Cypress.env('Password'));

    cy.get('#login')
        .click();

    cy.get("@login").then(xhr => {
        cy.log(JSON.stringity(xhr.response.body));
    });

});

});