I work as a Software Engineer at Endtest.
It's easy to forget to include email testing in your test automation workflow.
I'm going to show you how to test emails.
Most applications send automatic emails to users.
For example, you get an email when you sign up on a website and you usually need to click on the confirmation link from that email.
You might also get transactional emails when you perform certain actions on a service.
Like any responsible developer, you probably have some automated tests that verify if your web application is working as expected.
You should also verify if the emails sent by your web application look good and work as expected.
Think of this nightmare scenario:
Something breaks in your app and the email confirmation no longer works for users who want to sign up.
This is a preventable type of disaster.
This makes it easy to test them with Selenium or any other testing tool.
And not just visually.
We can easily click on links and other elements from the email.
It would be difficult to rely on a single email address.
Even if we would have steps to delete that email address from our application, it would still be inconvenient.
And we cannot use our work email or our Gmail account. Since they tend to have 2FA, reCAPTCHAs and other tricky obstacles.
We can use a disposable email service, as long it's reliable and secure.
We built a free email testing service called Endtest Mailbox.
Anyone can use it and you don't have to sign up.
The way it works is similar to a disposable email service.
Simply send your email(s) to a firstname.lastname@example.org email address.
The username can be anything you choose and you don't have to register it anywhere.
For instance, you can choose something like email@example.com.
You can access the Inbox for that email address on this page.
Just add the email parameter in the URL, like this:
Let's write some Python + Selenium code that will perform a sign up on a website.
driver.get("https://swit.io/register") firstName = driver.find_element_by_id("firstName") lastName = driver.find_element_by_id("lastName") email = driver.find_element_by_id("id") password = driver.find_element_by_id("password") confirmPassword = driver.find_element_by_id("confirmPassword") submitButton = driver.find_element_by_class_name("button--important") firstName.send_keys("Jim") lastName.send_keys("Carrey") email.send_keys("firstname.lastname@example.org") password.send_keys("Password123") confirmPassword.send_keys("Password123") submitButton.click()
And that code would lead us to this screen:
Now, we can check that email by going to this URL:
And we'll be able to open our email:
And you can use any testing tool, browser or mobile device to access it.
Here is how you would access it with Python + Selenium:
driver.get("https://email@example.com") email = driver.find_element_by_class_name("email_item") email.click()