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

Scripts for Data Driven Testing using Notepad & Datatables

Data Driven Testing using notepad

Set f=CreateObject("Scripting.FileSystemObject")
Set f1=f.CreateTextFile("c:\text.txt")
f1.writeline "aaa bbb"
f1.writeline "ccc ddd"

The above script creates a notepad in C: drive with following contents:

aaa bbb
ccc ddd

Set f2=f.OpenTextFile("c:\text.txt")
While f2.AtEndOfStream <>true
f3=f2.readline
x=Split(f3, "")
msgbox x(0)
msgbox x(1)
WEnd

The above script is used for data driven using notepad directly. Here we are not importing data to excel sheet. Directly values are retreived from notepad. We are using while loop and reading each line till the end. Split function splits the line where space(" ")occurs. Line is divided to 2 parts.one before space and other after space. For example we have 1st line in notepad as aaa bbb

here aaa is 1st part and bbb is 2nd part

x(0)=aaa
x(1)=bbb

all values are read this way using while loop. One point to note here is if any line is empty in notepad datadriven testing is stopped before that line. It will not proceed further.so we have to give values without any empty lines in notepad. To make things more clear,

Suppose u have

aaa bbb

ccc ddd

Datadriven is stopped at aaa and bbb only because next line is empty. Datadriven is stopped after 1st line.

Datadriven using dataTable

This Script gives result by retrieving values from datatable.

A B
5 5
6 6
7 7
8 8
9 9

In datatable enter test data as shown above.
Fill values below "A" and "B"

script required for DDT(data driven testing)is

val1=datatable("A",1)
val2=datatable("B",1)
res=cint(val1) +cint(val2)
msgbox res

Result will be 10,12,14,16,18.

datatable("column name",sheetname/id)

cint is a function which converts string to integer.

check what will happen if u are not using cint in third step.
just replace this res=val1+val2 in place of res=cint(val1) +cint(val2)

1 comment:

KISHORE.R said...

This information helped a lot to me. Keep up the good work and keep posting

 
Copyright © 2009 ExpertQTP