How To Create Driver Script In Qtp
Software Quality Assurance Forums: Driver Script in QTP
Wow, nothing like resurrecting a 3 year old post. I don t know if Jim s even still lurking on these boards but you re welcome to have my driver:
Code:Dim intScriptCount, intScriptLoop, strRunScript
Creates an environment variable to hold the user name. Initialized here to be empty until it is used somewhere.
Creates an environment variable to hold the account name. Initialized here to be empty until it is used somewhere.
Creates an environment variable to hold the deposit amount. Initialized here to be empty until it is used somewhere.
For intMultiLoop 1 to 1 Just used for testing when I feel like making the script run over and over, otherwise it is set for 1 to 1
Now we re ready to actually run some tests
We get the number of scripts in the local DataSheet
intScriptCount DataTable.GetSheet Main. GetRowCount
We loop through each row and check to see if the Run column is blank.
If it is blank, we skip that row.
Otherwise, we run the script identified in the ScriptName column
For intScriptLoop 1 to intScriptCount
DataTable.GetSheet Main. SetCurrentRow intScriptLoop
strRunScript DataTable Run, dtLocalSheet
RunAction DataTable ScriptName, dtLocalSheet, oneIteration
Next intMultiLoop Just used for testing
This last line is here to stop test execution. Without it, QTP will finish this action then try to run other actions.
Since all other actions are called by Main, there is no reason to also run them after Main is finished.
In my DataTable, my first column is called Run and my second column is ScriptName.
In the Run column, I leave the cell blank if I want to skip this particular script, or I put anything I want into it usually just an x to make it run. In the ScriptName column I have the name of every Reusable Action in my test suite - make sure to spell them exactly like you named them.
So the driver gets the count of the datatable rows, loops through them in order, checks the Run column, then executes whatever script is in the ScriptName column unless the Run column is blank.
Oh, the top part where I create those environment veriables is not really part of the driver. I just left them in so you can see some of the stuff I do in the driver before I actually start calling actions.
The last 10 of any software project will take 90 of the budgeted time. The first 90 will take the other 90
QTP Linear Framework We will now create a script in QTP Linear Framework which would open GMail and retrieve the number of Driver Script created using QTP.
- Nov 30, 2009 Sample of Driver script to run multiple QTP scripts Hi, If you just wish to control the execution of QTP Actions, you don t need anything special.
- Generally in Keyword Driven Framework Driver Script is the only QTP Script, remaining all are Vb Script files . vbs.
- What is driver script and driver script in qtp frame work. Advertise your Business Here : Browse Placement Papers How do you create a library file : 2.
- Right now we are in the process of preparing Automation Framework Document; QTP will be used as the automation tool; We are discussing to have a Driver Script as part.
- QTP - Designing Framework - Learn what is QTP QuickTest Professional and associated concepts like Record and Play Back, Object Repository, Master Driver Script.
The sample application under test is Calculator, a default application that is available as part of Windows. Let us now create different components of a framework. Here, we will develop a hybrid framework and use Object Repository as it is fairly a simple application. However, this framework can be scaled to support a complex application as well.
The Folder Structure of the Framework is as follows. The Explanation of the folder structure is explained below:
Master Driver Script - The Script that drives the entire execution. It performs prerequisite and initial settings that are required for the execution.
Library Files - The Associated Functions that forms the Function Library
Data Table - The Test Data that is required for the Execution.
Object Repository - The Objects and its properties that enable QTP to recognize the objects seamlessly.
Execution Logs - The Folder contains the execution log file with user functions and function execution history.
MASTER DRIVER SCRIPT NAME : Calculator
DESCRIPTION : Drivers Script to Execute Automated Test for the Calculator
OBJECT REPOSITORY ASSOCIATED : Calc.tsr
LIBRARY FILES ASSOCIATED : calculator.qfl, Common.qfl
----------------------------------------------------
Get the Root folder of the Test so that we can make use of relative paths.
Dim x : x Instr Environment.Value TestDir, Driver -2
ExecDrive mid Environment.Value TestDir, 1,x
Get the path of Libraries using relative to the current Drive
Dim LibPath : LibPath ExecDrive Libraries
Dynamically Load the Function Libraries
LoadFunctionLibrary LibPath Calculator.qfl, LibPath common_utils.qfl
clscommon is the class object created in common.qfl library file
SystemUtil.Run C: Windows System32 Calc.exe : wait 2
Initialize the Data Table Path
Dim FileName : FileName ExecDrive TestData Calculator.xls
Dim SheetSource : SheetSource Calc_test
Dim SheetDest : SheetDest Global
Import the DataTable into the QTP Script
DataTable.ImportSheet FileName, SheetSource, SheetDest
Dim RepPath : RepPath ExecDrive Object_Repository Calc.tsr
RepositoriesCollection.RemoveAll
RepositoriesCollection.Add RepPath
Dim InttestRows : InttestRows datatable.GetRowCount
Fetching Date-TimeStamp which will be unique for Naming the Execution Log File
clscommon.StrDateFormatted day date _ MonthName Month date, true
_ YEAR date _ hour now _ minute now
clscommon.StrLogFile ExecDrive Execution Logs
clscommon.StrDateFormatted . txt
Create the Execution LogFile which captures the result
clscommon.Fn_FileCreate clscommon.StrLogFile
Iniitialize the Parameters and all the relevant Test Details
Kill all the previous calculator process
For InttestIteration 1 to InttestRows
datatable.SetCurrentRow InttestIteration
Dim StrExecute : StrExecute Ucase Trim datatable.Value Run, Global
clscommon.Number1 Trim datatable.Value Number_1, Global
clscommon.Number2 Trim datatable.Value Number_2, Global
clscommon.Number3 Trim datatable.Value Number_3, Global
clscommon.Number4 Trim datatable.Value Number_4, Global
clscommon.Number5 Trim datatable.Value Number_5, Global
clscommon.Number6 Trim datatable.Value Number_6, Global
clscommon.Test_Case_ID Trim datatable.Value Test_Case_ID, Global : clscommon.LogWrite The Test Case Data is Located at :: tcDataPath
clscommon.tcScenario Trim datatable.Value Scenario, Global : clscommon.LogWrite The Test Case Data is Located at :: tcDataPath
Dim Expected_Val : Expected_Val Trim datatable.Value Expected_Val, Global : clscommon.LogWrite The Test Case Data is Located at :: tcDataPath
Select case clscommon.tcScenario
clscommon.LogWrite Inside the Test Set :: clscommon.tcScenario
Call fnCalculate, Expected_Val
Call fnCalculate -, Expected_Val
Call fnCalculate /, Expected_Val
Call fnCalculate sqt, Expected_Val
Calling the End Test to Add the result Footer in exec log file.
The Calculator Functions are written in a separate function file saved with the extension. qfl or. vbs. These functions are reusuable across actions.
Calculator. Qfl File :: Associated Function Library for Calculator Master Driver
FUNCTION NAME : Fn_InitializeLogFile
DESCRIPTION : Function to Write the Initial Values in the Log File
INPUT PARAMETERS : varExecDrive,StrDB,StrUId,Strpwd,StrNewDB
RETURN VALUE : Pass or Fail message
Public Function Fn_InitializeLogFile
clscommon.LogWrite Calc Automation Started
DESCRIPTION : Function to perform Arithmetic Calculations
INPUT PARAMETERS : operator,Expected_Val
Function fnCalculate operator,Expected_Val
clscommon.LogWrite Executing the Function fnCalculate
If Trim clscommon.Number1 Then Window Calculator. WinButton clscommon.Number1. Click
If Trim clscommon.Number2 Then Window Calculator. WinButton clscommon.Number2. Click
If Trim clscommon.Number3 Then Window Calculator. WinButton clscommon.Number3. Click
Window Calculator. WinButton operator. Click
If Trim clscommon.Number4 Then Window Calculator. WinButton clscommon.Number4. Click
If Trim clscommon.Number5 Then Window Calculator. WinButton clscommon.Number5. Click
If Trim clscommon.Number6 Then Window Calculator. WinButton clscommon.Number6. Click
Window Calculator. WinButton. Click
Dim ActualVal : ActualVal Window Calculator. WinEdit Edit. GetROProperty text
clscommon.LogWrite The Actual Value after the Math Operation is ActualVal
If Trim ActualVal Trim Expected_Val Then
clscommon.WriteResult Pass, clscommon.Test_Case_ID, clscommon.tcScenario, Expected Value matches with Actual Value :: ActualVal
clscommon.WriteResult Fail, clscommon.Test_Case_ID, clscommon.tcScenario, Expected Value - Expected_Val Does NOT matches with Actual Value :: ActualVal
Window Calculator. WinButton C. Click
clscommon.LogWrite Execution Error : The Error Number is :: Err.Number The Error Description is Err.Description
clscommon.LogWrite Exiting the Function fnCalculate
FUNCTION NAME : fn_Kill_Process
DESCRIPTION : Function to Kill the process by name
INPUT PARAMETERS : Application name to be killed
Function fn_Kill_Process process
Dim strComputer, strProcessToKill, objWMIService, colProcessstrComputer .
Set objWMIService GetObject winmgmts: _ impersonationLevel impersonate. _ strComputer root cimv2
Set colProcess objWMIService.ExecQuery _ Select from Win32_Process Where Name strProcessToKill
For Each objProcess in colProcess
DESCRIPTION : Function to finish the test Execution process
clscommon.LogWrite Status Message - Executing the Function fn_End_test
clscommon.ElapsedTime DateDiff n, clscommon.StartTime,clscommon.StopTime
Totaltests clscommon.gintPassCount clscommon.gintFailCount
clscommon.LogWrite The Execution Start Time :: clscommon.StartTime
clscommon.LogWrite The Execution End Time :: clscommon.StopTime
clscommon.LogWrite The Time Elapsed :: clscommon.ElapsedTime Minutes
clscommon.LogWrite The OS :: Environment.Value OS
clscommon.LogWrite The Total No of Test Cases Executed :: Totaltests
clscommon.LogWrite The No. of Test Case Passed :: clscommon.gintPassCount
clscommon.LogWrite The No. of Test Case Failed :: clscommon.gintFailCount
SystemUtil.CloseDescendentProcesses
The other library file which is common_utils.qfl that contains the functions which enables us to write the output to a text file.
Creating a class file to handle global variables.
Dim StartTime, StopTime, ElapsedTime
Dim gintPassCount, gintFailCount, gintWarningCount, gintdoneCount, gintinfoCount
Function Fn_FileCreate strFileName
Dim objFSO: Set objFSO CreateObject Scripting.FileSystemObject
Dim objTextFile : Set objTextFile objFSO.CreateTextFile strFileName
Dim objFSO : Set objFSO CreateObject scripting.FileSystemObject
Dim objTextFile : Set objTextFile objFSO.OpenTextFile clscommon.StrLogFile, ForAppending, True
objTextFile.WriteLine day date / MonthName Month date, true / YEAR date time : sMsg
Function WriteResult strStatus,functionName,functionDescription,Result
objTextFile.WriteLine day date / MonthName Month date, true / YEAR date time : Test Case Exec Details
objTextFile.WriteLine day date / MonthName Month date, true / YEAR date time : Test staus :: strStatus
objTextFile.WriteLine day date / MonthName Month date, true / YEAR date time : Tese ID :: functionName
objTextFile.WriteLine day date / MonthName Month date, true / YEAR date time : Test Description :: functionDescription
objTextFile.WriteLine day date / MonthName Month date, true / YEAR date time : Test Result Details :: Result
objTextFile.WriteLine day date / MonthName Month date, true / YEAR date time :
Object Repository has got all the objects that the user would be acting upon. The below image shows the list of all objects added into the repository with the name calc.tsr
Data Table contains the keywords which drive the tests and also Test data with which QTP will act on the objects.
The Execution log file or output file contains user actions and function logs which will enable the testers to debug upon script failures.
8/Jan/2014 :16 PM: Calc Automation Started
8/Jan/2014 :16 PM: Inside the Test Set :: Add
8/Jan/2014 :16 PM: Executing the Function fnCalculate
8/Jan/2014 :17 PM: The Actual Value after the Math Operation is 949.
8/Jan/2014 :17 PM: Test Case Exec Details
8/Jan/2014 :17 PM: Test staus :: Pass
8/Jan/2014 :17 PM: Tese ID :: TC_001
8/Jan/2014 :17 PM: Test Description :: Add
8/Jan/2014 :17 PM: Test Result Details :: Expected Value matches with Actual Value :: 949.
8/Jan/2014 :17 PM: Exiting the Function fnCalculate
8/Jan/2014 :17 PM: Inside the Test Set :: Subtract
8/Jan/2014 :17 PM: Executing the Function fnCalculate
8/Jan/2014 :17 PM: The Actual Value after the Math Operation is 415.
8/Jan/2014 :17 PM: Tese ID :: TC_002
8/Jan/2014 :17 PM: Test Description :: Subtract
8/Jan/2014 :17 PM: Test Result Details :: Expected Value matches with Actual Value :: 415.
8/Jan/2014 :17 PM: Inside the Test Set :: Multiply
8/Jan/2014 :18 PM: The Actual Value after the Math Operation is 278883.
8/Jan/2014 :18 PM: Test Case Exec Details
8/Jan/2014 :18 PM: Test staus :: Pass
8/Jan/2014 :18 PM: Tese ID :: TC_003
8/Jan/2014 :18 PM: Test Description :: Multiply
8/Jan/2014 :18 PM: Test Result Details :: Expected Value matches with Actual Value :: 278883.
8/Jan/2014 :18 PM: Exiting the Function fnCalculate
8/Jan/2014 :18 PM: Inside the Test Set :: Divide
8/Jan/2014 :18 PM: Executing the Function fnCalculate
8/Jan/2014 :19 PM: The Actual Value after the Math Operation is 3.
8/Jan/2014 :19 PM: Test Case Exec Details
8/Jan/2014 :19 PM: Test staus :: Pass
8/Jan/2014 :19 PM: Tese ID :: TC_004
8/Jan/2014 :19 PM: Test Description :: Divide
8/Jan/2014 :19 PM: Test Result Details :: Expected Value matches with Actual Value :: 3.
8/Jan/2014 :19 PM: Exiting the Function fnCalculate
8/Jan/2014 :19 PM: Inside the Test Set :: Sqrt
8/Jan/2014 :19 PM: Executing the Function fnCalculate
8/Jan/2014 :20 PM: The Actual Value after the Math Operation is 10.
8/Jan/2014 :20 PM: Test Case Exec Details
8/Jan/2014 :20 PM: Test staus :: Pass
8/Jan/2014 :20 PM: Tese ID :: TC_005
8/Jan/2014 :20 PM: Test Description :: Sqrt
8/Jan/2014 :20 PM: Test Result Details :: Expected Value matches with Actual Value :: 10.
8/Jan/2014 :20 PM: Exiting the Function fnCalculate
8/Jan/2014 :20 PM: Status Message - Executing the Function fn_Finish_test
8/Jan/2014 :20 PM: The Execution Start Time :: :14 PM
8/Jan/2014 :20 PM: The Execution End Time :: :20 PM
8/Jan/2014 :20 PM: The Time Elapsed :: 0 Minutes
8/Jan/2014 :20 PM: The OS :: Microsoft Windows Vista Server
8/Jan/2014 :20 PM: The Total No of Test Cases Executed :: 25
8/Jan/2014 :20 PM: The No. of Test Case Passed :: 25
8/Jan/2014 :20 PM: The No. of Test Case Failed ::