QA Wolf logo

QA Wolf

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, waitForMessages } = getInbox();
// get a new email address
// example: my-team+a25sa5q@qawolf.email
const { email, sendMessage, waitForMessage, waitForMessages } = getInbox({
new: true,
});
// get a custom email address
// example: my-team+admin@qawolf.email
const { email, sendMessage, waitForMessage, waitForMessages } = 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 });
// Wait for a timeout in milliseconds (default 60 seconds) and then
// return all messages sent to the email during that period, sorted
// by when they were received, newest to oldest.
const messages = await waitForMessages({ timeout: 20000 });
// 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, waitForMessages }

  • 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.
  • waitForMessages (Function): Wait for a timeout in milliseconds (default 60 seconds) and then return all messages sent to the email during that period, sorted by when they were received, newest to oldest.

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();
expect(subject).toMatch("hello");
// wait for a message up to 2 minutes
const { subject, text } = await waitForMessage({ timeout: 120000 });
expect(subject).toMatch("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>

  • [cc] (string): One or more CC'd email addresses. If multiple, they are separated by commas. Example: "other-person@some.site"
  • from (string): Sender of the email. Example: "tug@qawolf.com"
  • html (string): HTML body of the email. Example: "<a href="https://myurl.com">Click Me</a>"
  • [reply_to] (string): One or more reply-to email addresses. If multiple, they are separated by commas. Example: "no-reply@some.site"
  • 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. If multiple, they are separated by commas. Example: "my-team@qawolf.email"
  • urls (string[]): URLs parsed from the email. Example: ["https://myurl.com"]

waitForMessages([options])

Get a list of all messages sent to the inbox after this is called and until timeout milliseconds have passed.

If a message is not received before the timeout, the returned array will be empty.

// wait for 1 minute and then see what messages were received
const messages = await waitForMessages();
const messageWeCareAbout = messages.find((message) =>
message.subject.includes("code")
);
expect(messageWeCareAbout).toBeTruthy();
// wait 2 minutes
const messages = await waitForMessages({ timeout: 120000 });

Use the after option to wait for an email that is received after a specified Date. If you don't provide the after option, it defaults to the moment that waitForMessages is called, which may be after an email has already been received.

// 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 messages = await waitForMessages({ after });
const messageWeCareAbout = messages.find((message) =>
message.subject.includes("code")
);
expect(messageWeCareAbout).toBeTruthy();

waitForMessages Arguments

[options] (Object)

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

Returns: Promise<Message[]>

  • [cc] (string): One or more CC'd email addresses. If multiple, they are separated by commas. Example: "other-person@some.site"
  • from (string): Sender of the email. Example: "tug@qawolf.com"
  • html (string): HTML body of the email. Example: "<a href="https://myurl.com">Click Me</a>"
  • [reply_to] (string): One or more reply-to email addresses. If multiple, they are separated by commas. Example: "no-reply@some.site"
  • 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. If multiple, they are separated by commas. Example: "my-team@qawolf.email"
  • urls (string[]): URLs parsed from the email. Example: ["https://myurl.com"]