Ghost Inspector
Test SMS and email with Ghost Inspector - the all-in-one website test and monitoring service and SMSByrd, the number one SMS and email testing service.
What is Ghost Inspector?
Ghost Inspector lets you create automated website tests and set up monitoring suites. It makes automated testing for websites and web apps easier, especially with its web test recorder, which allows you to easily record tests from right within your web browser.
As you’re here, there is a good chance you know about Ghost Inspector already, but if you don’t we highly recommend their official getting started guide and video.
What is SMSByrd?
SMSByrd lets you test SMS and email messages as part of your end-to-end automated testing. This is particular important for websites and web apps that send an email (password resets, account setup, marketing emails, etc.) or SMS message (multi-factor authentication, verification, etc.)
If you don’t already have one, you’ll need to create a free trial account. Once you’re in, familiarize yourself with sending email into SMSByrd. Once you have this working, you’re ready to start testing!
1. Get Started
Creating an account
Create a free trial account for SMSByrd via the website.
Once you have this, navigate to the API tab to find the following values:
- Project ID - Servers act like projects, which group your tests together. You need this ID whenever you interact with a server via the API.
- Server Domain - Every server has its own domain name. You’ll need this to send email to your server.
- API Key - You can create an API key per server (recommended), or an account-level API key to use across your whole account. Learn more about API keys.
Test email addresses with SMSByrd
SMSByrd gives you an unlimited number of test email addresses - with no setup or coding required!
This is because every server uses a catch-all/wildcard pattern. Here’s what that means:
- When you create an account, you are given a server.
- Every server has its own Server Domain name (e.g.
abc123.smsbyrd.net
) - Any email address that ends with
@YOUR_SERVER_DOMAIN
will work with SMSByrd without any special setup. For example: - You can create more servers when you need them. Each one will have its own domain name.
Can’t use test email addresses? You can also use SMTP to test email. By connecting your product or website to SMSByrd via SMTP, SMSByrd will catch all email your application sends, regardless of the email address.
Understanding the API
Because Ghost Inspector runs all your tests in the browser, we’re going to use SMSByrd.js (our client-side API library). This guide will take you through all the key use cases, but it’s worth remembering that the library is powered by the SMSByrd email & SMS testing API. You can easily check out the API itself by looking at our API reference documentation or via our Postman or Insomnia collections:
//buttons
2. Create a new Ghost Inspector test suite
Navigate to Ghost Inspector, and create a new test suite. This is done by clicking New > New suite in the top-right of the page.
Give your suite a name and create Create Suite.
//photo
3. Add steps that trigger an email
You now need some test steps that will cause an email to be sent from your website or product. As discussed above, you have an unlimited number of usage test email addresses with SMSByrd.
In this example, we will navigate to the SMSByrd Playground to mimic a real world product that has a password reset feature.
Ghost Inspector has an awesome browser extension to allow you to quickly record these steps yourself in the browser, but in this guide we’re going to do this manually, because that’s how we roll… 💪
- Under Create new test, on the right of the screen, we type “Request Password Reset”.
- Next, input the starting URL (in our example, that’s
https://example.SMSByrd.com/password-reset
). - Click Create.IMAGE
- Next, add a step to fill in the email address on the password reset form. In the screenshot below you can see we use an Assign step to set the input field (
#email
) to our test email address ofghost-inspector@abc123.SMSByrd.net
. Note thatabc123.SMSByrd.net
is our Server Domain (from step 1 above), andghost-inspector
is any string we want (you don’t need to create email addresses with SMSByrd). - Finally, add a step to submit the password reset request - a simple button click is all we need.IMAGE
Running this test allows us to successfully request a password reset. But to complete the process, we next to find that email and follow the link inside it.
4. Find the email
Using SMSByrd.js in a web browser A hashtag icon SMSByrd has libraries to write tests in various languages. As Ghost Inspector runs in the browser, we need to use SMSByrd.js which allows us to do SMS and email testing from within a web browser.
To do this, you must first verify your website or web app’s domain name. To do this, go to the Domains section of the SMSByrd Dashboard, and follow the on-screen instructions to add a new verified domain. Learn more about.
Execute JavaScript to import the SMSByrd.js library A hashtag icon To pull SMSByrd.js into our Ghost Inspector test, add an Execute JavaScript step, with the following code:
//code snippet
Extract the email into a variableNext, we need to find our email and extract the result into a variable that we can use else where in our Ghost Inspector suite.
To do this, add an Extract from JavaScript step, with the following code (note that we discussed the values to use for apiKey and serverId above):
//code snippet
In the Variable name field, type “message”.
Let’s break down what the code above actually does:
- First, it is an async method, so Ghost Inspector requires that we first return a Promise.
- Inside that, we set variables for our
apiKey
andserverId
, the values for which we discussed above. - Finally, we have an async method that searches for the email we sent (using
SMSByrd.messages.get
) and resolves the result.
In this example we are searching for our message using the sentTo option. You can search using any of the criteria described in the API reference.
5. Create an assertion step
Now that we have our email in a variable, we can start creating assertions. This can be done by adding a JavaScript returns true step in Ghost Inspector. For example, this will test the email’s subject line:
//code snippet
You’re now ready to write whatever tests you need. The rest of this guide will take you through some of the most common things you might want to test.
Testing plain text content
Most emails, and all SMS messages, should have a plain text body. SMSByrd exposes this content via the text.body property on an email or SMS message:
//code snippet
Extracting verification codes from plain textYou may have an email or SMS message that contains an account verification code, or some other one-time passcode. You can extract content like this using a simple regex.
Here is how to extract a 6-digit numeric code:
//code snippet
Testing HTML content
Most emails also have an HTML body, as well as the plain text content. You can access HTML content in a very similar way to plain text:
//code snippet
Working with hyperlinks
When an email is sent with an HTML body, SMSByrd automatically extracts any hyperlinks found within anchor and area elements and makes these available via the html.links array.
Each link has a text property, representing the display text of the hyperlink within the body, and an href property containing the target URL:
//code snippet
Important: To ensure you always have valid emails. SMSByrd only extracts links that have been correctly marked up with a or area tags.
Links in plain text (including SMS messages)SMSByrd auto-detects links in plain text content too, which is especially useful for SMS testing:
//code snippet
Working with attachments
If your email includes attachments, you can access these via the attachments property:
//code snippet
Each attachment contains metadata on the file name and content type:
The length property returns the size of the attached file (in bytes):
//code snippet
Working with images and web beaconsThe html.images property of a message contains an array of images found within the HTML content of an email. The length of this array corresponds to the number of images found within an email:
//code snippet
Remotely-hosted imagesEmails will often contain many images that are hosted elsewhere, such as on your website or product. It is recommended to check that these images are accessible by your recipients.
All images should have an alternative text description, which can be checked using the alt attribute.
//code snippet
Triggering web beaconsA web beacon is a small image that can be used to track whether an email has been opened by a recipient.
Because a web beacon is simply another form of remotely-hosted image, you can export the src attribute via an Extract from JavaScript step, then navigate to that URL using Ghost Inspector:
//code snippet
Spam checking
You can perform a SpamAssassin check against an email. The structure returned matches the spam test object:
//code snippet