Saturday 13 July 2019

Automating email validations through Selenium and disposable email service

There are some aplications which sends Welcome emails/User registration emails to activate accounts etc. Also there are some systems which sends marketing emails. For testing them, manually verifying these emails is always tedious and time consuming. What if we have a way to automate them just through Selenium. Sounds Interesting? Lets see how it works.

We all know that Selenium can only interact with HTML elements. So, to verify the mails, we need to open our email in browser. Luckily we have a free disposable email service which opens up our mail in a browser called Endtest Mailbox. All we need to do is, use any mailid with the extension '@endtest.io'.

The username can be anything you choose.
For instance, you can choose something like ram12234@endtest.io.

You can access the Inbox for that email address in browser just by adding the email parameter in the URL, like this:
https://endtest.io/mailbox?email=ram12234@endtest.io

Please note that these emails will be deleted after 2 hours.

To demonstarte this I am using thissite . When you enter an email id and click on check, a test email is sent to the given email id immediately. Lets consider this as our application and we need to verify if it sends an email correctly to the given email address!

driver.get("http://ismyemailworking.com");
driver.manage().window().maximize();
driver.findElement(By.id("verify_email")).sendKeys("ram12234@endtest.io");
driver.findElement(By.id("content_cob_check")).click();

The above code will send a test mail to your inbox. Now we can open the inbox in browser through selenium with the link https://endtest.io/mailbox?email=ram12234@endtest.io.



driver.get("https://endtest.io/mailbox?email=klaus123@endtest.io");
driver.findElement(By.id("email_item")).click();

After this, we can add all the assertions such as Subject,  email body etc.

There are also few alternatives for Endtest mailbox such as mailnatorguerrillamailNada

Note:
If your emails are confidential, this solution is not appropriate. Because these free mailboxes are public and can be accessed by anybody.

In our next post, we will discuss about 'how we to verify the mails received in your Gmail Account or outlook'. 

3 comments:

  1. Great work Nainappa!This is a new thing that I learnt today and it's very interesting to know. I am waiting for your outlook email validation along with SSO restrictions.

    ReplyDelete
  2. Hi,

    Can we automate following steps

    1. create new get getnada mail id.
    2. collect new mail id
    3. a verification code send to previously created getnada mail id
    4. extract that verification code from mail box

    ReplyDelete
  3. You made some decent points there. I looked on the internet for the issue and found most individuals will go along with with your website. Temporary Email

    ReplyDelete