http://quicktesthp.blogspot.com

QTP VBScript new series + Interview Question Bank on QTP for enrichment of Knowledge in QTP

This Site has been brought to you by HP Certified Expert of QTP.

Exciting new articles for October:

1) QTP Tip:Deselect all Radio Buttons

2) HP QTP Crypt Object

3)Adding Hyperlinks in Excel Spreadsheet

Best of Luck Friends ! ! !

Expert QTP
expert.qtp@gmail.com

All Articles are Copyright Protected. These are Free for Reading & Personal Use. Reproduction in Any Form without the Permission is Illegal & Strictly Prohibited.

Copyright © 2009 ExpertQTP

Google Search

Friday, June 6, 2008

Usage of Datatable: Parameterization

Usage of DataTable

Datatable is infact an excel sheet which is embedded into the QTP with datatable as name. It is mainly used to parameterize the scripts. We have to make the constant value as parameter, so that in each iteration(cycle) it takes a value that is supplied in run-time datatable. Through parameterization only we can drive a transaction (action) with different sets of data.

There are two types of sheets inside the QTP datatable:
1. Global DataTable
2. Local DataTable

Global dataTable is created by default with every new script and Local Datatable is created everytime when a new Action is created inside the script. You can even view the contents of your DataTable inside the file “Default.xls” which is created on saving the script.

Now, lets see how we can really utilize the datatable in our scripting.

1. Create a new script and open your browser and navigate to http://www.gmail.com.
2. Start recording and provide a dummy username and password say “User1” and “Pass1”.
3. Stop your recording.

You will see a script like this:

Browser("Browser").Page("Gmail: Email from Google").WebEdit("Email").Set "user"
Browser("Browser").Page("Gmail: Email from Google").WebEdit("Passwd").SetSecure “48af0f9632214bc0964877b44a4e"

4. Now create two columns in Global DataTable named “Username” and “Password”.
5. Provide “user1” and “user2” in the first two rows of above created “Username” column.
6. Similarly provide “pass1” and “pass2” in the first two rows of the above-created “Password” column.

Now in order to access the values created in Datatable, we will use DataTable associated methods properties. The most popular is “Value” which is the default datatable property. Now let us see how do we access values stored in dataTable.

UserID1=DataTable.Value(“UserName”,dtGlobalSheet)
Pass1= DataTable.Value(“Password”,dtGlobalSheet)

Here “UserName” is the name of DataTable column and dtGlobalSheet signifies we are working with the datatable. Here, you can also ommit "Value" which is optional.

Now add these two lines into your script and so your script will look like:

UserID1=DataTable(“UserName”,dtGlobalSheet)
Pass1= DataTable(“Password”,dtGlobalSheet)

Browser("Browser").Page("Gmail: Email from Google").WebEdit("Email").Set "user"
Browser("Browser").Page("Gmail: Email from Google").WebEdit("Passwd").SetSecure “48af0f9632214bc0964877b44a4e"

Now modify the above two lines so that they will look like:

Browser("Browser").Page("Gmail: Email from Google").WebEdit("Email").Set UserID1 Browser("Browser").Page("Gmail: Email from Google").WebEdit("Passwd").Set Pass1

What I have done in the above script? Any guesses.. Instead of hard coded values, I infact parameterized my script so that my usernames and passwords come from run time datatable.

In order to move your pointer to next row, I mean if you want to use your second row, just use:

DataTable.SetNextRow

Now the real powerful feature of qtp is it can run my script for all datatable values. For this, click File->Settings. Navigate to Run tab inside Test Settings dialog box. Select “Run on all rows” option and click OK button. Run your script and voila you are done………

No comments:

 
Copyright © 2009 ExpertQTP