Advanced Topics 1. Regular Expressions :During execution some times QTP may not identify the objects due to the regular changes in its properties values. To over come this situation one need to replace the corresponding Constant value in the object repository with a suitable regular expressions. Example : To send number of orders thru fax Open the flight application Put the tool under recording mode Open an existing order by clicking on open order icon Activate the menu item file Select the option Fax Order Give dummy fax number (say 999-999-9999) Click on Send button Fax will be sent as if its sent. Stop recording Now if you want to send number of orders thru FAX Open the data table Change the 1st column name as ‘order_no’ Give the order numbers you want to send fax ( say 8,3,1) Now change the edit box script where you enter order id in such way that QTP should enter order ids from data table. ' this statment where recorded while trying to open order number 9 Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit").Set "9" ' update above statement only in the main test script as below ' setting the datatable values into edit field of open order ' order_no is the column name of data table ' 1= global sheet in datatable Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit").Set datatable("order_no",1)
Open the object repository Select the Fax order No. in object hierarchy Select the Text property Click on Constant option value button Constant value option window will appear ( To search all the files, we use *.* ) in the same way Change the value name with .* extension ( say Fax Order No.*) Select the checkbox Regular Expression Click on OK Click on No button (optional) Click on OK Run the test Analyze the results
2. Input & Output Parameters :Input parameter is a concept provided by QTP which is used for Passing some value into the action and getting some value from the action while calling that action. One has to declare the desired number of input and output parameters at the action that is about to be called in order to pass and get the value. Function :- is used for Passing and Getting value from a function. • We need to Return the value to the function name itself. • Function has a limitation that we can catch or get only one value at time Example : Function file Function add(a,b) : function name is add Total = a + b : adding to values to Total add = Total : Retuning the result to the function name it self End function Main Test file var = add(10,20) : passing value to function Action :- is used to pass Two values and return One value Example :
Open the cal application Add the cal application’s object properties to Object Repository Activate menu item Step Select the option Action properties Select Parameters tab Declare the input parameters values by clicking (+) add button Give the name (a) , Type ( number) and some default number Similarly Give the name (b) , Type ( number) and some default number Declare the output parameters by clicking (+) add button Give the name (a) and Type ( number) Click on OK Write the script as below ' setting the input parameter to val1 VbWindow("Form1").VbEdit("val1").Set parameter("a") ' setting the input parameter to val2 VbWindow("Form1").VbEdit("val2").Set parameter("b") VbWindow("Form1").VbButton("ADD").Click ' getting the value of Result and passing to var1 var1=vbwindow("Form1").VbEdit("res").GetROProperty("text") ' passing that var1 to Output parameter c parameter("c")=var1 Make this test as re-usable Activate menu item Step Select the option Action properties Select the check box Reusable action Click on OK
Save it say (myTest) ( no extension is required) Open the new test Call that saved re-usable action Activate menu item Insert Select the option Call to Existing action Browse that saved test (myTest) Click on OK An external action will be added to current test select the action1 from actions list now test pane will have the following code RunAction "Action1 [myTest]", oneIteration Replace the above code as below ' oneIteration = one time it will execute ' 100 = passing this value into val1 thru input parameter (a) ' 200 = passing this value into val2 thru input parameter (b) ' r1= getting the output value by outputparameter ( c) RunAction "Action1 [myTest]", oneIteration,100,200,r1 msgbox r1 run the test Analyze the results Note : RunAction "Action1 [myTest]", oneIteration, , ,r1 : used to enter the default values into val1 and val2 3. Virtual Object Configuration :Virtual object configuration is a process of making the QTP tool to Treat an user defined object or a specific area as a specific object. • Whenever QTP is not recognizing the object, then we Force QTP to recognize that object as a specific object • Making the QTP to understand a button on the screen. ** Once we created virtual object , it will be available to All Tests except we delete it. Example :
Open the virtual object application ( a window with colorbutton shape) Activate menu item , select Virtual Objects option Select the option New virtual Object Virtual Object wizard will appear, click on Next Select the standard class that nearly match to your object ( say button ) Click Next Mark the object on the AUT screen, Height and width will be captured Click Next Select the option for parent of the virtual object Select Next Specify the name (button) and collection name ( Button_collections) Click OK Put the tool under recoding mode Click on the area you selected as button and any area on the screen Stop recording
Analyze the results Virtual Object Manager : Which is a feature provided by QTP used for creating and maintaining the virtual objects. -: The End :Pls. leave your feed back (both +ve and –ve ) at
[email protected]