QA Wolf logo

QA Wolf

/

Star

2.7k

getInbox([options])

Get an email address and send or receive an email message in your test. See this guide to learn more about receiving an email.

If you'd like QA Wolf to forward received emails so you can see them, please contact us.

// get your team's email address
// example: my-team@qawolf.email
const { email, sendMessage, waitForMessage } = getInbox();
// get a new email address
// example: my-team+a25sa5q@qawolf.email
const { email, sendMessage, waitForMessage } = getInbox({ new: true });
// get a custom email address
// example: my-team+admin@qawolf.email
const { email, sendMessage, waitForMessage } = getInbox({ id: "admin" });
// use the email to fill out a form
await page.fill('[name="email"]', email);
await page.click('[aria-label="Sign up with email"]');
// wait for a message up to 1 minute
const message = await waitForMessage();
// wait for a message up to 3 minutes
const message = await waitForMessage({ timeout: 3 * 60000 });
// send a message from your team's email address
const message = await sendMessage({
html: "<b>HTML</b>",
subject: "Subject",
text: "Text",
to: "test@email.com",
});

Arguments

[options] (Object)

  • [id] (string): Get an email address with the specified id. Default: null
  • [new] (boolean): Get a new email address. Default: false

Returns: { email, waitForMessage }

  • email (string): An email address to send your email to.
  • sendMessage (Function): Send a message from the email address.
  • waitForMessage (Function): Wait for a message sent to the email address.

sendMessage([options])

Send a message from the email address returned from getInbox. If the message is not sent successfully, an error is thrown.

To prevent spam, your team must be approved to call this function. Please contact us to get approved.

// send a message
const message = await sendMessage({
html: "<b>HTML</b>",
subject: "Subject",
text: "Text",
to: "test@email.com",
});
// send a message with no subject or HTML body
const message = await sendMessage({
text: "Minimalist email",
to: "test@email.com",
});

sendMessage Arguments

[options] (Object)

  • [html] (string): HTML body of the email. Default: null
  • subject (string): Subject of the email.
  • [text] (string): Text body of the email. Default: null
  • to (string): Recipient of the email.

Note: You must provide at least one of html and text to specify the email content.

Returns: Promise<Message>

  • from (string): Sender of the email. Example: "my-team@qawolf.email"
  • html (string): HTML body of the email. Example: "<div>I'm the email body</div>"
  • subject (string): Subject line of the email. Example: "🐺 Hi there!"
  • text (string): Email body in plain text. Example: "I'm the email body"
  • to (string): Recipient of the email. Example: "test@email.com"

waitForMessage([options])

Get the next message sent to the email address returned from getInbox.

If a message is not received before the timeout, an error is thrown.

// wait for a message up to 1 minute
const { subject } = await waitForMessage();
assert(subject.includes("hello"));
// wait for a message up to 2 minutes
const { subject, text } = await waitForMessage({ timeout: 120000 });
assert(subject.includes("hello"));

Use the after option to wait for an email that is received after a specified Date.

For example, at QA Wolf we use the same test to test sign up and log in. When we log in the second time, we need to make sure to get the latest login code. Otherwise, waitForMessage would return the email with the first login code immediately.

// keep track of when we log in the second time
const after = new Date();
// log in
await page.fill('[name="email"]', email);
await page.click('[aria-label="Log in with email"]');
// get login code from email sent after specified date
const { subject } = await waitForMessage({ after });

waitForMessage Arguments

[options] (Object)

  • [after] (Date): Find a message sent after this date. Default: When getInbox was called
  • [timeout] (number): Time in milliseconds to wait for a message. Default: 60000

Returns: Promise<Message>

  • from (string): Sender of the email. Example: "Tug the QA Wolf <tug@qawolf.com>"
  • html (string): HTML body of the email. Example: "<a href="https://myurl.com">Click Me</a>"
  • subject (string): Subject line of the email. Example: "🐺 Hi there!"
  • text (string): Email body in plain text. Example: "I'm the email body"
  • to (string): Recipient of the email. Example: "my-team@qawolf.email"
  • urls (string[]): URLs parsed from the email. Example: ["https://myurl.com"]