Search code examples
asp.net-corecypressblazor-client-side

Why does my cypress e2e test never complete?


I have this cypress e2e tests.

/// <reference types="Cypress" />

describe('Toss Full Test', function () {
let polyfill;
const uuid = Cypress._.random(0, 1e6)

before(() => {
    const polyfillUrl = 'https://unpkg.com/whatwg-fetch@3.0.0/dist/fetch.umd.js';
    cy.request(polyfillUrl).then(response => {
        polyfill = response.body;
    });
});
Cypress.on('window:before:load', win => {
    delete win.fetch;
    win.eval(polyfill);
});
const SubscribeEmail = "tosstests" + uuid + "@yopmail.com";
const SubscribePassword = "tossTests123456!!";
const SubscribeLogin = "tosstests" + uuid;

it('Full process', function (win) {
    cy.server();
    cy.visit("/");



    cy.route('POST', '/api/account/register').as('register');
    //this could be lagging as ravendb is starting
    cy.get("#LinkLogin", { timeout: 20000 }).click();
    //register
    cy.get("#LinkRegister").click();
    cy.get("#NewEmail").type(SubscribeEmail);
    cy.get("#NewName").type(SubscribeLogin);
    cy.get("#NewPassword").type(SubscribePassword);
    cy.get("#NewConfirmPassword").type(SubscribePassword);

    cy.window()
        .then(win => {
            // disables runCaptcha
            win.runCaptcha = new win.Function(['action'], 'return Promise.resolve(action)');
        })
        .then(
            () => {
                cy.get("#BtnRegister").click();
                cy.wait('@register');
                cy.get('@register').then(function (xhr) {
                    expect(xhr.status).to.eq(200);
                });

            }
        );
    })
})

The full code can be found here https://github.com/RemiBou/Toss.Blazor/tree/master/Toss.Tests.E2E.Cypress.

When I run my project with the following code

docker-compose up -V ravendb web
./node_modules/.bin/cypress open

The code runs well, the assertion "expect(xhr.status).to.eq(200);" returns true but the test execution never stops. Why is that ?


Solution

  • After a lot of trial and error I just needed to remove the "win" parameter from the method in the "if" call which was a test for getting a window reference. In fact this parameter is a callback you need to call at the end of the tests, I can't find any documentation about it.