Postman with Disposable Email

Registration and Login API using Postman with Disposable Email


Overview

How to automate the process of Registration and Login API's using disposable Emails through PostMan.

What is a Disposable Email.

Disposable email addressing set up a different, unique email address for every sender/recipient combination. Usually in scenarios we need to use emails and verify them but we need to create and verify emails prior to use them. Whereas disposable email server allows you the freedom to not required to create and verify the emails. We have one such service very friendly and ease to use called "mail7"(https://mail7.io).

Let me take you more understanding about mail7.

What is mail7(https://mail7.io)

mail7 is a disposable email server, which offers public and private inboxes. Public inboxes are accessible to everyone and the emails will be purged after some time based on their timestamp. Since Public inboxes are open to everyone. It's not a good choice to send personal information to Public inbox. Its good thing that Mail7 offers a Private inbox as well. Here we can create and manage Private emails with mail7.io domain. You can create a team and add members to it. Who can access all emails which is received in the mail7 mailbox?

For example, We are surfing over the internet and found something interesting and navigate to the website. Where it is asking Login / Signup to continue further. We have no idea about the website and they might send spamming your inbox. In that case we can use mail7 emails to avoid spamming.

UseCase

Now a days, Many Organizations are widely using automation tools to perform their QA Activities. Let us take an example, To perform Registration on any web application / API, We fill required fields along with the email and user will receive mail in their inbox, Performing registration is not a big deal using any automation tool like Selenium, Postman, SoapUI, etc. Where as verifying using through automation tool is making your work stop because every registration requires a new email and it should be verified for further actions. So, In many organizations they are leaving this kind of scenario to manual testers. Here Disposable Emails comes handy. So we will cover in this article, How to overcome this obstacle in the process of automation. Listing few use-cases below where we need to interact with the mail server to get the mail and verify it.

  1. Forgot Password Email
  2. Resend Verification Email
  3. Delete User verification
  4. Subscribe / Unsubscribe etc...

E2E User Scenario

Let us take a use-case where user register and Login using API through Postman

  1. Call Registration API.
  2. Call Verification API to verify Email(User will Receive an email with Link).
  3. Call Login API to login.

Steps:

Let us open the Postman Application and Create Collection Named API Automation, add Requests to Collection. Environment Variable: -

url				   ->  <string> application host url
apikey			 ->  <string> application key
mail7key		 ->  <string> disposable email service key
mail7secret	 ->  <string> disposable email service  secret
token			  ->  <string> extracted from mail7 to verify user
user				->  <string> from which user get register (random)
email			  ->  <string> user + @mail7.io

How to set a random email in postman:

const uuid = Math.random().toString(36).substring(2, 15) +
        Math.random().toString(36).substring(2, 15);
const email = "user_" + uuid + "@mail7.io";
const user = "user_" + uuid
pm.environment.set("email", email);
pm.environment.set("user", user);

1. Post Request Registration API

Select method as POST and enter URL

{{url}}/v1/register/apikey={{apikey}}

Click on the body and add below JSON

{
"email":{{email}},
"password":"password"
}

Click on Tests tab and add below code

tests["Status code is 200"] = responseCode.code  === 200
tests["IsPosted should be True"] = responseBody.IsPosted === true;

2. Get Request Inbox of Mail7

Select method as GET and enter URL

https://api.mail7.io/inbox?apikey={{mail7key}}&apisecret={{mail7apisecret}}&to={{user}}

Click on Tests tab and add below code

tests["Status code is 200"] = responseCode.code  === 200
var jsonData = JSON.parse(responseBody);
var tokVal = jsonData.Data[0].mail_source.html.split('vtoken=').pop();
postman.setEnvironmentVariable("token", tokVal);

3. Put Request to verify User

Select PUT method and enter URL

{{url}}/v1/email/verify?apikey={{apikey}}

and add request body as

{
"verificationToken": {{token}}
}

Click on Tests Tab and add below code

tests["Status code is 200"] = responseCode.code  === 200
tests["IsPosted should be True"] = responseBody.IsPosted === true;

4. Post Login to Authenticate User

Select Method as POST and enter URL

{{url}}/v1/login?apikey={{apikey}}

and add request body as

{
"email":{{email}},
"password":"password"
}

Click on Tests Tab and add below code

tests["Status code is 200"] = responseCode.code  === 200
tests["Access Token Should not Blank"] = responseBody.access_token !== "";

Click on Runner it will pop up Collection Runner, Then select the collection "API Automation". Add run order of API's Register -> Inbox -> Verify -> Login into collection. Select the Environment to set variables and select the number of iteration and click on Run API Automation button. Then We will get the test Results.

Conclusion

Automating End to End Email flow Scenarios makes Tester job difficult without disposable email service. Now we have the availability of disposable email services like Mail7 (https://mail7.io/) making tester's life easy to perform a complete scenario without using manual effort.