Reputation: 31
I'm wrihing test for "Forgot password" flow in Playwright JS and for that purpose I'm using Mailosaur. The problem I have is when I run same test few times, my Mailosaur inbox won't refresh and test doesn't pick up the last email in inbox. It always picks the previous email in the inbox and every second test is failing because it clicks on expired link.
Is there any way I can refresh the Mailosaur inbox or delete the emails after the test is done to overcome this issue?
I'm always using same email address.
This is the code for clicking reset password link:
const email = await mailosaur.messages
.get(server_Id, { sentTo: user_email, }) expect(email.subject)
.toEqual('Password reset request by [email protected]')
const resetPasswordLink = email.html?.links?.[1].href ?? ''
await this.page.goto(resetPasswordLink)
Upvotes: 0
Views: 384
Reputation: 3372
according to this page you can delete all emails with
try {
await client.messages.deleteAll(SERVER_ID);
} catch (e) {
throw new Error('Cannot delete emails');
}
or for a single email:
async deleteAllEmailMessagesSentTo(emailAddress) {
try {
const result = await client.messages.search(
SERVER_ID,
{
sentTo: emailAddress
},
{
page: 0,
itemsPerPage: 10
});
// delete emails
result.items.map(async item => {
await this.deleteEmailMessage(item.id);
});
} catch (e) {
// do nothing
}
}
Upvotes: 0