Checking Email within Tests

Access and interact with email triggered during your tests

Search our documentation:

Toggle Documentation Menu

Checking Email within Tests

It's common for websites and applications to send emails when certain actions are triggered. In some cases, you may want access to those emails during your test(s) to confirm their delivery, check their contents, or extract data for use within your test. While Ghost Inspector can often access 3rd party webmail clients, it's often challenging and not recommended. Instead, Ghost Inspector includes a built-in email service that can be used to seemlessly access triggered emails during your browser tests.

Email Service

To use our built-in email service, simply send your email(s) to a "<username>@email.ghostinspector.com" email address (where "<username>" can be anything you choose). For instance, you can choose something like "example@email.ghostinspector.com". However, it's more likely that you'll want a unique or time-based username that is generated for each specific test run (see below). Once delivered your email will be immediately accessible without login via our email service.

Important Notes

  • Emails sent to this service are technically public and can be accessed by anyone with knowledge of the <username> being used. While using a unique <username> with a dynamic portion (which we suggest below) provides some level of privacy, we insist that you avoid inclusion of sensitive data in your emails when using this service.
  • Emails are purged 1 hour after they are received.
  • This service is specifically designed to receive emails which you plan to access and use during a test. It is not designed to receive mass mailing, which may impact performace. Please refrain from sending large volumes of email to this service.

When an email is sent to a "<username>@email.ghostinspector.com" email address, two different URLs can be used for accessing it.

https://email.ghostinspector.com/<username>
This URL will provide a simple "Inbox" view of all emails send to this address within the last hour.

Email service inbox

https://email.ghostinspector.com/<username>/latest
This URL will display the latest email sent to this address within the last hour (provided that one exists).

Sample email message

To use this service in your tests, simply assign a "<username>@email.ghostinspector.com" email address, add a 30 second "Pause" step after the email is triggered to allow for delivery, then navigate to the email service's public URL within your test and interact with the email.

Email steps - Static email address

Dynamic Email Addresses

In many cases, it's going to be useful (or necessary) to use a unique email address — for instance, when testing your application's sign up process. We suggest using our built-in {{TIMESTAMP}} variable for this. You can create an {{emailUser}} variable containing a time-based username, then use that variable in the email address that you send to and check in your test.

Email steps - Dynamic email address

Checking Email while Maintaining Sessions

In some cases, you may need to extract a value from an email while keeping you browser test on an open page. For instance, you may submit a form in your application which prompts you for a code that is emailed. You'll need the browser to keep your application open while the email is accessed and code is fetched. In this case, we recommend opening up our email service in a popup window. This can be done with a simple JavaScript snippet, rather than a "Go to URL" step (which will navigate away from your application):

window.open("https://email.ghostinspector.com/{{emailUser}}/latest");

Simply place that snippet into an Execute JavaScript step to open the email service in a popup window. We have some details on interacting with popup windows, but in general, the system will figure out which window the target element exists in (as long as the selector is unique across all windows). Below is an example that triggers an email, extracts a value from the email in a popup window, then assigns that value back into the main window.

Email steps - Dynamic email address in a popup window