QA Wolf logo

QA Wolf

/

Star

2.7k

Receive an Email

In this tutorial, we'll receive an email in a test. You might want this for testing:

  • Sign in with a login code
  • Password reset
  • Email notifications after an event happens

Test Receiving an Email

QA Wolf provides a getInbox method that returns:

  • email: your team's email address
  • waitForMessage: function that waits for an email message to the test address

Let's use getInbox and waitForMessage in our test.

Below we 1) get an email address, 2) fill out the form, and 3) wait for a message and assert it's content.

const { context } = await launch();
const page = await context.newPage();
await page.goto("https://ismyemailworking.com");
// use our test email to fill out the form
const { email, waitForMessage } = getInbox();
await page.fill("#verify_email", email);
await page.click("#content_cob_check");
// wait for a message and check it starts with "Congratulations"
const message = await waitForMessage();
console.log(message);
assert(message.text.startsWith("Congratulations"));