Email Validation Using VB Script In QTP/UFT

While automating test cases and developing QTP/UFT script, I came across a requirement where email validation needs to be performed in Gmail. Once email is triggered during test case execution or completion of test case execution, every time email validation required to be done automatically.

There could be scenario where we need to perform email validation or we need to perform email validation of the contents in the mail. For example, every time when a test case execution completes, suppose a notification email gets triggered to the email id provided. Once email triggered to provided email id then you need to verify whether email has been received or not in inbox.

If email validation is performed manually on each execution of script, it will take lots of time and patient to check each email every time after test case execution completes or during test case execution. Hence, it’s a good practice that instead of verifying email manually, we can automate email validation and complete test case execution faster without any manual intervention.

Please follow the steps mentioned below to automate mail validation in Gmail:

Open Browser:

BrowserPath="C:\Program Files (x86)\Internet Explorer\iexplore.exe"
SystemUtil.Run BrowserPath

Navigate and Login Gmail:

 Browser("MAIL").Navigate("www.gmail.com")
 Browser("MAIL").Page("GMAIL").WebEdit("txtGMEmailid").Click
 Browser("MAIL").Page("GMAIL").WebEdit("txtGMEmailid").set "Type your email id"
 Browser("MAIL").Page("GMAIL").WebButton("btnGMNextbtn").Click
 Browser("MAIL").Page("GMAIL").Sync
 Browser("MAIL").Page("GMAIL").WebEdit("txtGMPassword").Click
Browser("MAIL").Page("GMAIL").WebEdit("txtGMPassword").set "Type your email password"
 Browser("MAIL").Page("GMAIL").WebButton("btnGMNextbtn").Click 
 
If Browser("MAIL").Page("GMAIL").InsightObject("gMailLogo").Exist then
 Browser("MAIL").Page("GMAIL").InsightObject("gMailLogo").Click
End If

Validate Mail Subject and Contents:

First spy the subject name that you want to verify. Make sure you are spying the mail subject when it is in unread mode. If you spy the subject in read mode then the next time when subject is in unread mode, object will not be identified while executing.

If Browser("MAIL").Page("GMAIL").WebElement("TestMail").Exist Then
 MsgBox "Mail Received Successfully"
 Browser("MAIL").Page("GMAIL").WebElement("TestMail").Click
'Here you have clicked on the mail subject and mail has been opened.
'Now you can spy the other objects and add the code that you want to do verification.
'Example
If Browser("MAIL").Page("GMAIL").WebElement("ThankYou").Exist Then 
strOrderInformation=Browser("MAIL").Page("GMAIL").WebElement("eleFulfilmentText").GetROProperty("innertext")
 MsgBox "Mail Verified Successfully" 
 Else
 MsgBox "Mail Verification Failed"
 End If
 Else
 MsgBox "Mail Is Not Received"
End If

Before executing above script make sure you have added all the required objects in object repository. You can change the name of objects as your wish, I have kept the name for my convenience.

One Response to “Email Validation Using VB Script In QTP/UFT”

  1. Glasslae says:

    , text and illustrations to which

Leave a Reply

Your email address will not be published. Required fields are marked *

AlphaOmega Captcha Classica  –  Enter Security Code