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.

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.