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

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


How to debug a test in QTP: Complete Tutorial

Debugging is the process of locating and fixing or bypassing bugs in computer program code.Before starting debugging in QTP,We need to install Microsoft debugger for debugging. This can be done during QTP Installation.

Below are the options available in Debug Menu and will discuss the same in detail:



Pause:

To detect and isolate defects in a test or function library, you can control the run session using the Pause command. This will pause the test run and you can check for state of objects, and values in variable at the moment of pause to get the issue. You can temporarily suspend a run session by choosing Debug > Pause or clicking the Pause button. The Test execution will resume if we Press F5 or Run.

Step Into :

While navigation into a function definition from the function called in script. We can use Debug>Step Into or Press F11 or click on Step into button. Using Step Into, we can debug in the function called in script and run each step line by line in the function.

Step Over:

Step Over does debugging line by line in the script, but does not debug into a function called within script, but executes the function as a step and moves to next step in the Test. We can use Step Over using F10 Key or Debug>Step Over or icon for Step Over in the QTP IDE.

Step Out:

Suppose we have step into a function as explained in Step To, and wants to come out of the function or Action, we use Step Out Option. We can use Step Over using shift + F11 Key or Debug>Step Out or icon for Step Out in the QTP IDE.

Run To Step:

You can instruct QTP to run from the beginning of the test or action or from the current location in the test and to stop at a particular step. This is similar to adding a temporary breakpoint to a step.
To select Run to Step, Insert your cursor in the step in which you want QuickTest to stop the run and choose Debug > Run to Step or press Ctrl+F10

Debug from Step

You can instruct QuickTest to begin your debug session from a particular step instead of beginning the run at the start of the test or action. Before you start debugging from a specific step, make sure that the application is open to the location.
To debug a test from step, Insert your cursor in the step where you want QuickTest to start the run and choose Debug > Debug from Step.

Using BreakPoints in QTP:

We can use breakpoints to suspend a run session and inspect the state of your application or mark a point from which to begin stepping through a test or function library.
Breakpoints are applicable only to the current QuickTest session and are not saved with the tests.
Test execution pauses at the step where we provide breakpoint. A breakpoint can be inserted using Debug > Insert/Remove Breakpoint or clicking Insert/Remove Breakpoint button or pressing F9 key on the step.
To enable\disable a breakpoint,i.e enable a checkpoint if disabled below or vice versa, Press Ctrl + F9 or select Debug > Enable/Disable Breakpoint
We can enable disable all breakpoint by selecting Debug > Enable/Disable All Breakpoints or click the Enable/Disable All Breakpoints button.


Debug Viewer in QTP:










We can  use debug Viewer in QTP to view, set, or modify the current value of objects or variables in your test or function library,  To view Debug Viewer, Choose View > Debug Viewer or click the Debug Viewer button.

Below are the tabs in Debug Viewer:


Watch Tab

This is used to view the value of any variable or an expression in the test. To add an expression, Click the expression and choose Debug > Add to Watch.

Variables Tab

QTP automatically displays the current value of all variables in the current action or function in the Variables tab—up to the point where the test or function library is stopped or paused. We can change value of a variable manually also in variables tab. This will be reflected in test.

Command tab

This is to execute a line of script to set or modify the current value of a variable or VBScript object in your test or function library.


How to load and Associate Function libraries in QTP Test at runtime

Below are the various ways by which we can add/associate libraries with QTP tests so that functions in the libraries can be used within test.

ExecuteFile Statement 

      Executes the VBScript statements in the specified file. Functions, subroutines defined in the file are available from the global scope of the action's script.We cannot debug functions or statement contained in the file.

ExecuteFile "C:\BusinessLib.vbs”

Through QTP Interface 

      A library can be associated with a test so that the functions and subroutines, classes defined in the function library can be used .This can be achieved as follows:
      Navigate to File > Settings > Resources > Associate Function Library’ option in QTP. Add the required Libraries to the resources by clicking on + icon.

      Once function library is associated with the test.We can debug function in the function libraries and view function definition of the functions from the scripts.We can also define the priority of function library using up and down icon.

     
Associating Libraries with QTP tests

     

Using Load Function Library method

In  QTP 11, and onwards, We can dynamically load function library with the test using load function library. Libraries are released from test once completed. We can debug into function on calling library using LoadFunctionLibrary. The scope of the library is local to the action in which it is called.

Syntax: LoadFunctionLibrary “D:\TestLib.vbs”


We can add multiple files seperated by


Using Automation Object Model 

We can associate multiple libraries to QTP test using the below code. Also all the tests actions can use the functions from associated libraries.

strFilesNameCommaSeperated = "d:\test1.vbs,d:\test.vbs"
strTestName ="D:\Sample\Test1"
Call LoadLibrariesThroughAOM(strFilesNameCommaSeperated,strTestName)
Public Function LoadLibrariesThroughAOM(strFilesNameCommaSeperated,strTestName)
Set oqtapp = CreateObject("QuickTest.Application")
oqtapp.Launch
oqtapp.Visible = True
 strLibName = split(strFilesNameCommaSeperated,",")
'Open a test and associate a function library to the test
oqtapp.Open strTestName, False, False
Set oLib = oqtapp.Test.Settings.Resources.Libraries
 For i = 0 to ubound(strLibName)
                 LibName = strLibName(i)
                 ' If library is not already added, add the required library.
 
                If oLib.Find(LibName) = -1 Then
                         oLib.Add LibName, 1
                End If
 Next
oqtapp.Test.Save
                End Function