Showing posts with label Data Table. Show all posts
Showing posts with label Data Table. Show all posts

Data Driven Testing using Notepad in QTP

Set
f=createobject("scripting.filesystemobject")
Set f1=f.createtextfile("d://file1.txt")
f1.writeline"aaa bbb"
f1.writeline"ccc ddd"
f1.writeline"eee fff"
f1.writeline"ggg hhh"
f1.writeline"iii jjj"

The above script creates a notepad in "d" drive with name file1

aaa bbb
ccc ddd
eee fff
ggg hhh
iii jjj

values are stored in file1.txt.

Set f2=f.opentextfile("d://file1.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 u 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.

Validating and Passing Data Back to the Server

The simple validation example uses a plain button control. If a Submit control was used, the example would never see the data to check it — everything would go immediately to the server. Avoiding the Submit control lets you check the data, but it doesn't submit the data to the server. That requires an additional line of code:

<SCRIPT LANGUAGE="VBScript"> 
<!--
Sub Button1_OnClick
 Dim TheForm
 Set TheForm = Document.ValidForm
 If IsNumeric(TheForm.Text1.Value) Then
    If TheForm.Text1.Value < 1 Or TheForm.Text1.Value > 10 Then
      MsgBox "Please enter a number between 1 and 10."
    Else
      MsgBox "Thank you."
      TheForm.Submit   ' Data correct; send to server.
    End If
 Else
    MsgBox "Please enter a numeric value."
 End If
End Sub
-->
</SCRIPT>

To send the data to the server, the code invokes the Submit method on the form object when the data is correct. From there, the server handles the data just as it otherwise would — except that the data is correct before it gets there.

 

Using Data Table Formulas

This page provides some useful formulas that can be used in the Data Table. Any combination of the formulas below is acceptable. The formulas refer to the data in cell A1 but may be applied to any cell.

For more information on Data Table formulas, refer to Microsoft Excel documentation. All Microsoft Excel formulas can be used in the Data Table.

First word in a sentence:

=LEFT(A1,SEARCH("",A1,1))

First three words in a sentence:

=LEFT(A1,SEARCH("@",SUBSTITUTE(A1,"","@",3),1))

Part of the sentence starting with the fourth word:

=MID(A1,SEARCH("@",SUBSTITUTE(A1,"","@",3),1),LEN(A1))

The part of the sentence starting with "word":

=MID(A1,SEARCH("word",A1,1),LEN(A1))

Check if two strings are equal:

=EXACT(A1,"text2")

Duplicate the string three times:

=REPT(A1,3)

Concatenation of two strings:

="Hello " & "There"

Today's date:

=TODAY()

Generate a random uppercase letter:

=CHAR((RAND() *26) +65)