cypress-mailhog
cypress-mailhog copied to clipboard
a question: polling Mailhog on different environments
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();
});
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.
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.