Using MailSlurp to Accept New User Emails in Playwright Automation

If you've ever worked with test automation, you know how frustrating it can be to switch users, especially when adding a new user. In the past, you would have to log out of the current user, go to an email client like Gmail, refresh the page, navigate to the email, and click the link. It's a headache to say the least.

But with Playwright Automation, there's an easier way to handle this!

One of the key features is the ability to have multiple contexts running at the same time. This means you can have two pages open in two separate contexts, and they don't even know the other context exists.

So let's say you're an admin user who is logged in and filling out the steps to create a new user. Once you click save, the app sends out a new user invite via email. This is where MailSlurp comes in. MailSlurp is an API for SMS messages and emails that makes it easy to work with emails in your test cases without having to go into an email client.

To use MailSlurp, you'll need to connect to your MailSlurp account and create a new inbox with an inbox ID. Then, you can use the API to wait for the latest email with that ID and pull the subject and any links from the email. It's a good idea to include an expect statement to confirm that the email has the expected subject, but it's not necessary.

Once you have the links, they'll be returned as an array. In this case, we assume that the link we want is the first link in the array (link[0]). Next, we turn that link into a constant and open a new browser context with a new page (page1). Finally, we navigate to the URL using page1.goto(url).

Example Code

And that's it! With just a few lines of code, you can easily accept new user emails and open the link in a new context using MailSlurp and Playwright Automation.

Download our Automation ROI Formula

More from Loop

Get updates on Loop's best content

Stay in touch as we publish more great Quality Assurance content!