Blog to understand automation concepts in QTP, Selenium Webdriver and Manual Testing concepts

How to execute multiple external tests action using LoadandrunAction from QTP test

In QTP, we can execute external tests actions from a QTP test using LoadandRunAction Method. This method was introduced Post QTP 10, and is very useful to execute multiple tests from a test.Using This method we can execute reusable actions.


Syntax for LoadandrunAction is:



LoadAndRunAction "C:\Documents\qtp\test", "Action1", oneIteration


This will load Action1 from test in the script in which it is called.

Benefits of LoadandRunAction  are as follows:


  • Loads Action from external test dynamically at run time.

  • Can be useful to execute multiple tests in batch from the driver script which will call multiple tests action using LoadandrunAction

  • To run a test from QC, Test Path starts with [QualityCenter] Subject followed by folder structure in QC e.g "[QualityCenter] Subject\TestAutomation/Module1/Test1"



How to share values between various actions in a test in QTP


Below are the various ways by which values can be transferred between various actions in a test.

Sharing Values via the Global Data Table

Value generated in one action can be shared  with other actions in your test by storing the value in the global Data Table. Each Action in the test can access the global data table and hence can access data from the global data table. For details on how to access various in a data table, see Working With data Tables in QTP


Sharing Values Using Environment Variables

Environment variables are also shared between actions and can be used to share information between various action in the test. Also values can be parameterized using environment variable. To create an environment variable, loading environment variable, and details on environment variable, Please see post on Environment Variables in QTP

Sharing Values Using the Dictionary Object

Values between various actions in a test can be done creating a global dictionary object, and using properties of dictionary object.Below are the steps to share values between actions using globaldictionary object:

To use the Dictionary object, you must first add a reserved object to the registry (in HKEY_CURRENT_USER\Software\Mercury Interactive\QuickTest Professional\MicTest\ReservedObjects\) with ProgID = "Scripting.Dictionary". For example: HKEY_CURRENT_USER\Software\Mercury Interactive\QuickTest Professional\MicTest\ReservedObjects\GlobalDictionary


Once object has been added, we can add and remove values to the Dictionary in one action and retrieve the values in another action from the same test using scripting dictionary methods.For details on Scripting Dictionary, Please see Working with dictionary Object


 

Code to send mail with multiple attachments using Outlook.Application Object in QTP

The below function will send mail to recipient  and add multiple attachments in the mail through Outlook Object.



call func_SendMailUsingOutlook("aa@abc.com", "test", "body", "c:\bdlog.txt>c:\testlog.txt")


Function func_SendMailUsingOutlook(strRecipient, strSubject, strBody, AddMultipleAttachment)


   '''Create an instance of Outlook application    Set objol=CreateObject("Outlook.Application")

    Set objMail=objol.CreateItem(0)

    objMail.to=strRecipient

    objMail.Subject=strSubject

    objMail.Body=strBody

  ''Add multiple attachments to mail

strAttachments = split(AddMultipleAttachment,">")

intCount = ubound(strAttachments)

For i = 0 to (intCount)

    If (strAttachments(i) <> "") Then

        objMail.Attachments.Add(strAttachments(i))

    End If

Next

    objMail.Send

    objol.Quit

    Set objMail = Nothing

    Set objol = Nothing

End Function