SoapUI with Disposable Email

Registration and Login API automation using SoapUI with Disposable Email


Overview

How to automate the process of Registration and Login APIs using disposable Emails through SoapUI.

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 them before use it. 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 easy 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 inbox is 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 are received in the mail7 mailbox.

For example, We are surfing over the internet and found something interesting and navigated 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

Nowadays, 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 a 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 can register and log in using API through SoapUI

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

Steps:

  1. Let us open the SoapUI Application.
  2. Create a REST project named "Registration And Login Using Disposable Email".
  3. Right Click on the project and select 'New REST Service from URI'. Enter Endpoint and ResourcePath without space in REST request URI text box.
  4. Similarly, add 'New REST Service from URI' for each API mentioned below.

Global Properties: -

url         ->  <string> application host url
hpaUrl          ->  <string> hpa host url
apikey      ->  <string> application key
apisecret       ->  <string>  application secret
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 
password        ->  <string> password value for creating account

1. Set the user and email

Add a Groovy Step (Right-click on test case > Hover over Add Step > Select Groovy Script > Add a name for the step) as the first step of the test case. Enter the below mentioned code in the script:

    def generator = { String alphabet, int n ->
      new Random().with {
       (1..n).collect { alphabet[ nextInt( alphabet.length() ) ] }.join()
      }
    }
    def userVal = generator( (('a'..'z')+('0'..'9')).join(), 10)
    def emailVal = user + "@mail7.io"

    //Set Global Property user 
    com.eviware.soapui.model.propertyexpansion.PropertyExpansionUtils.globalProperties.setPropertyValue('user', userVal)
    com.eviware.soapui.model.propertyexpansion.PropertyExpansionUtils.globalProperties.setPropertyValue('email', emailVal)

2. Post Request Registration API

    Select Method as POST.
    Enter Endpoint:  ${#Global#url}
    Update ResourcePath: [/identity/v2/manage/account?
    apikey=${#Global#apiKey}&
    apisecret=${#Global#apiSecret}]
    Select Media Type: application/json
    Add below json as request body:
{
        "Email": [
            {
                "Type": "primary",
                "Value": "${#Global#email}" 
            }
        ],
        "password": " ${#Global#password}"
    }

Add following assertions:

i) Valid HTTP Status codes assertion: 200 ii) Contains assertion: ${#Global#emailValue} iii) Contains assertion: Uid iv) JSONPath Match Configuration:

  • JSONPathExpression: NoOfLogins
  • Expected Result: 0

3. Get Request Inbox of Mail7

Select Method as GET.
Enter Endpoint:  https://api.mail7.io
Update ResourcePath: [/inbox?
apikey=${#Global#mail7ApiKey}&
apisecret=${#Global#mail7ApiSecret}&
to=${#Global#emailValue}]

Add following assertions:

i) Valid HTTP Status codes assertion: 200 ii) JSONPath Match Configuration:

  • JSONPathExpression: status
  • Expected Result: success

iii) Contains assertion: data iv) JSONPath Match Configuration:

  • JSONPathExpression: data[0].to_username
  • Expected Result: ${#Global#emailValue}

v) Script Assertion:

    // Get JSON response
     import groovy.json.JsonSlurper
     def reponseMessage = messageExchange.response.responseContent
     def jsonData = new JsonSlurper().parseText(reponseMessage)
     // Fetch value of vToken
     assert jsonData.data[0].mail_source.html.toString() != null
     def tokenString =  jsonData.data[0].mail_source.html.split('vtoken=')
     def token = tokenString[1].split(' ')
     // Set global property 'vToken'
     com.eviware.soapui.model.propertyexpansion.PropertyExpansionUtils.globalProperties.setPropertyValue('vToken', token[0])
     

4. Put Request to verify User

Select Method as PUT.

Enter Endpoint: ${#Global#hpaUrl}

Update ResourcePath: [/hpa/v1/auth/email/verify?

apikey=${#Global#apiKey}]

Select Media Type: application/json

Add below json as request body:

{
    "verificationToken": "${#Global#vToken}" 
}

Add following assertions: i) Valid HTTP Status codes assertion: 200 ii) JSONPath Match Configuration:

  • JSONPathExpression: IsPosted
  • Expected Result: true

5. Post Login to Authenticate User

Select Method as POST.
Enter Endpoint:  ${#Global#url}
Update ResourcePath: [/identity/v2/auth/login?
apikey=${#Global#apiKey}]
Select Media Type: application/json
Add below json as request body:
  {
       "email": "${#Global#email}",
      "password": "${#Global#password}"
   }

Add following assertions: i) Valid HTTP Status codes assertion: 200 ii) Contains assertion: Profile iii) Contains assertion: Uid iv) Contains assertion: ${#Global#email}

Execution of test case:

Step 1: Create a TestSuite named "Registration and Login". Step 2: Create a TestCase named "RegistrationLogin" Step 3: Add Test Steps in the order: Register account > Get Inbox > Verify email > Login. Step 4: Double click on test case RegistrationLogin. RegistrationLogin editor window will open. Step5: Click on 'Run this test case' icon. It will execute all the test steps in the mentioned order.

Conclusion:

Using mail7.io as disposable email service testers can automate registration and login use case that requires a new email for verification purpose.