cypress-mailhog icon indicating copy to clipboard operation
cypress-mailhog copied to clipboard

a question: polling Mailhog on different environments

Open NevenaCukucan opened this issue 3 years ago • 2 comments

What is the recommended way for creating a custom command that polls Mailhog until the email is received - the command flexible enough to take different Mailhog URLs? Instead of using cy.request in the code below, I'd like to use cy.mhGetAllMails(), so this command can pick the correct mailhog url depending on which environment the test is being executed at. Is this possible?

Cypress.Commands.add('pollMailhog', () => {
    function requestEmail() {
        return cy.request({
                method: 'GET',
                url: "/api/v2/messages",

            })
            .then(({ body }) => {
                if (body.items.length > 1) {
                    return body;
                }
                cy.wait(500);
                return requestEmail();
            });
    }
    return requestEmail();
});

NevenaCukucan avatar May 10 '21 20:05 NevenaCukucan

Hi @NevenaCukucan, thanks for your question. You could achieve your goal by utilizing cypress-wait-until. Here is an example of how it could look like.

I'm planning on integrating that feature as default behaviour in an upcoming update.

SMenigat avatar Jun 02 '21 12:06 SMenigat

Hi @NevenaCukucan, thanks for your question. You could achieve your goal by utilizing cypress-wait-until. Here is an example of how it could look like.

I'm planning on integrating that feature as default behaviour in an upcoming update.

Awesome timing! Just recently adopted this plugin and am running into the same flakiness issues.

jpreese avatar Jul 02 '21 17:07 jpreese