Set obj=createobject("Scripting.filesystemobject")
Set of=obj.getfile("c:\1.xls")
s=of.type
msgbox s
Important Topics & Useful Scripts on QTP. Ask your QTP related questions at this id - asrajaputra@gmail.com
Saturday, December 6, 2008
To Display the Files in a Particular Folder
folderpath="E:\macromedia-8"
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(folderpath)
Set fc = f.Files
For Each f1 in fc
s = s & f1.name &chr(10)
Next
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(folderpath)
Set fc = f.Files
For Each f1 in fc
s = s & f1.name &chr(10)
Next
Displaying numbers into Ascending Order By Using Arrays
''''''''''''''''Displaying numbers into Ascending Order By Using Arrays'''''''''''''''''''''''''''''''''''''''''
a=array(10,20,1,30,2,40,23,50,4)
For j=lbound(a) to ubound(a)
For i=lbound(a) to ubound(a)-1
If a(i)>a(i+1) Then
temp=a(i+1)
a(i+1)=a(i)
a(i)=temp
End If
Next
For i=lbound(a) to ubound(a)
x=x&chr(10)&a(i)
'y=a(i)&chr(10)
Next
msgbox(x)
a=array(10,20,1,30,2,40,23,50,4)
For j=lbound(a) to ubound(a)
For i=lbound(a) to ubound(a)-1
If a(i)>a(i+1) Then
temp=a(i+1)
a(i+1)=a(i)
a(i)=temp
End If
Next
For i=lbound(a) to ubound(a)
x=x&chr(10)&a(i)
'y=a(i)&chr(10)
Next
msgbox(x)
Swaping two numbers without using 3rd variable
a=inputbox ("Enter the first value:")
b=inputbox( "Enter the second value:")
msgbox "a= "&a&" b= "&b
a=int(a)+int(b)
b=int(a)-int(b)
a=int(a)-int(b)
msgbox "After swap a= "&a&" b= "&b
b=inputbox( "Enter the second value:")
msgbox "a= "&a&" b= "&b
a=int(a)+int(b)
b=int(a)-int(b)
a=int(a)-int(b)
msgbox "After swap a= "&a&" b= "&b
Write a Mathematical Table in Notepad through the VB Script
'To open notepad and write a mathematical table in that throug QTP and save in C Drive and close
Set obj=createobject("Scripting.filesystemobject")
Set of=obj.createtextfile("c:\mat.txt")
'set of=obj.opentextfile("c:\mat.txt")
For i=1 to 10
x=5*i
of.writeline"5 * "&i&" = "&x
Next
Set obj=createobject("Scripting.filesystemobject")
Set of=obj.createtextfile("c:\mat.txt")
'set of=obj.opentextfile("c:\mat.txt")
For i=1 to 10
x=5*i
of.writeline"5 * "&i&" = "&x
Next
Comparing Two Files
''''''''''''''''''''''''Compare both the text files and isolate the differences found in the file1 which are not present in file2''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' in a seperate ouput file.''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
dim found
set objfso = createobject("scripting.filesystemobject")
set objinputfile2 = objfso.opentextfile ("c:\text2.txt")
set objoutputfile = objfso.createtextfile("c:\output.txt")
do until objinputfile2.atendofstream
found = false
strnextline2 = objinputfile2.readline
set objinputfile1 = objfso.opentextfile ("c:\text1.txt")
do until objinputfile1.atendofstream
strnextline1 = objinputfile1.readline
if (strnextline2 = strnextline1) then
found = true
end if
loop
objinputfile1.close
if (found = false) then
objoutputfile.writeline strnextline2
end if
loop
objinputfile2.close
objoutputfile.close
set objinputfile1 = nothing
set objinputfile2 = nothing
set objoutputfile = nothing
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' in a seperate ouput file.''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
dim found
set objfso = createobject("scripting.filesystemobject")
set objinputfile2 = objfso.opentextfile ("c:\text2.txt")
set objoutputfile = objfso.createtextfile("c:\output.txt")
do until objinputfile2.atendofstream
found = false
strnextline2 = objinputfile2.readline
set objinputfile1 = objfso.opentextfile ("c:\text1.txt")
do until objinputfile1.atendofstream
strnextline1 = objinputfile1.readline
if (strnextline2 = strnextline1) then
found = true
end if
loop
objinputfile1.close
if (found = false) then
objoutputfile.writeline strnextline2
end if
loop
objinputfile2.close
objoutputfile.close
set objinputfile1 = nothing
set objinputfile2 = nothing
set objoutputfile = nothing
Writing Log Files
Public function generate_result()
starttime=time()
msgbox(nam)
MyArray=split(nam, ":", -1)
For i=0 to ubound(MyArray)
filename=filename+MyArray(i)
Next
Set fso=Createobject("Scripting.FileSystemObject")
Set textfile=fso.createtextfile("c:/result.txt")
textfile.Writeline("Automated Smoke Test Results")
textfile.WriteLine("````````````````````````````")
textfile.WriteBlanklines(3)
textfile.WriteLine("Run on Host : " & Environment.Value("LocalHostName"))
textfile.WriteBlanklines(1)
textfile.WriteLine("Run on Operating System : " & Environment.Value("OS"))
textfile.WriteBlanklines(1)
textfile.WriteLine("Run on : "&now)
textfile.WriteBlanklines(1)
endtime=time()
textfile.WriteLine("Test Start Time : " &starttime)
textfile.WriteLine("Test End Time : " & endtime)
textfile.WriteLine("Test Execution Time : " & datediff("s", startime, endtime)& " Seconds")
End Function
generate_result()
starttime=time()
msgbox(nam)
MyArray=split(nam, ":", -1)
For i=0 to ubound(MyArray)
filename=filename+MyArray(i)
Next
Set fso=Createobject("Scripting.FileSystemObject")
Set textfile=fso.createtextfile("c:/result.txt")
textfile.Writeline("Automated Smoke Test Results")
textfile.WriteLine("````````````````````````````")
textfile.WriteBlanklines(3)
textfile.WriteLine("Run on Host : " & Environment.Value("LocalHostName"))
textfile.WriteBlanklines(1)
textfile.WriteLine("Run on Operating System : " & Environment.Value("OS"))
textfile.WriteBlanklines(1)
textfile.WriteLine("Run on : "&now)
textfile.WriteBlanklines(1)
endtime=time()
textfile.WriteLine("Test Start Time : " &starttime)
textfile.WriteLine("Test End Time : " & endtime)
textfile.WriteLine("Test Execution Time : " & datediff("s", startime, endtime)& " Seconds")
End Function
generate_result()
VB Script Procedures
'There are two types of procedures
'1. Function Procedure
'2. Sub Procedure
'Function Procedure-A Function procedure is a series of VBScript statements enclosed by the Function
'and End Function statements. Function Procedure can able to return the value.
'Example:
Function demo_add(a,b)
demo_add=a+b
End Function
oVal=demo_add( 2,3)
msgbox oVal 'Returns 5
'In this example demo_add function returns a value to oVal.
'In Function procedures we can use function name to assign a value.
'Sub Procedure-A Sub procedure is a series of VBScript statements enclosed by the Sub
'and End Sub statements. Sub Procedure cannot return any value.
'Example:
Sub demo_sub(a,b, c)
c=a+b
End sub
demo_sub 2,3,x
msgbox x 'Returns 5
'This example will do the same as what function procedure is doing above.
'But in sub Procedure we need to use one more parameter to get values from the sub procedure.
'1. Function Procedure
'2. Sub Procedure
'Function Procedure-A Function procedure is a series of VBScript statements enclosed by the Function
'and End Function statements. Function Procedure can able to return the value.
'Example:
Function demo_add(a,b)
demo_add=a+b
End Function
oVal=demo_add( 2,3)
msgbox oVal 'Returns 5
'In this example demo_add function returns a value to oVal.
'In Function procedures we can use function name to assign a value.
'Sub Procedure-A Sub procedure is a series of VBScript statements enclosed by the Sub
'and End Sub statements. Sub Procedure cannot return any value.
'Example:
Sub demo_sub(a,b, c)
c=a+b
End sub
demo_sub 2,3,x
msgbox x 'Returns 5
'This example will do the same as what function procedure is doing above.
'But in sub Procedure we need to use one more parameter to get values from the sub procedure.
Use of Split Function
''''To display the words in a sentence by spliting with dellimeter''''
str1="arunsingh is a good boy"
var=split(str1," ")
lenarray=ubound(var)
For i=0 to lenarray
str2=var(i)
msgbox str2
Next
str1="arunsingh is a good boy"
var=split(str1," ")
lenarray=ubound(var)
For i=0 to lenarray
str2=var(i)
msgbox str2
Next
Use of RandomNumber Method
set da1=datatable.AddSheet("demo")
set da2=datatable.AddSheet("result")
set pm1=da1.addparameter("name","123")
set pm2= da1.addparameter("age","18")
For i=1 to 10
da1.setcurrentrow(i)
pm1.value="emp"&i
pm2.value=RandomNumber (30,60)
Next
x=da1.getrowcount
set pmr=da2.addparameter("resname","")
set pmg=da2.addparameter("age","")
k=1
For j=1 to x
ag=pm2.valuebyrow(j)
If ag>50 Then
pmr.valuebyrow(k)=pm1.valuebyrow(j)
pmg.valuebyrow(k)=ag
k=k+1
End If
Next
set da2=datatable.AddSheet("result")
set pm1=da1.addparameter("name","123")
set pm2= da1.addparameter("age","18")
For i=1 to 10
da1.setcurrentrow(i)
pm1.value="emp"&i
pm2.value=RandomNumber (30,60)
Next
x=da1.getrowcount
set pmr=da2.addparameter("resname","")
set pmg=da2.addparameter("age","")
k=1
For j=1 to x
ag=pm2.valuebyrow(j)
If ag>50 Then
pmr.valuebyrow(k)=pm1.valuebyrow(j)
pmg.valuebyrow(k)=ag
k=k+1
End If
Next
Use of Excel Object Model
''We can do excel operations using excel object model. To find excel object model in your system follow these steps..
'*********** ********* ********* ********* *
'creating an excel application object
Set Excel=CreateObject( "Excel.Application")
'Adding a sheet in that application
Set ExcelSheet = CreateObject( "Excel.Sheet" )
' Make Excel visible through the Application object.
ExcelSheet.Application.Visible = True
'Adding value into sheet
For i=1 to 10
ExcelSheet.ActiveSheet.Cells( i,1).Value = "This is column A, row"&i
Next
' Save the sheet.
ExcelSheet.SaveAs "C:\TEST.xls"
' Close Excel with the Quit method on the Application object.
ExcelSheet.Applicat ion.Quit
' Release the object variable.
Set ExcelSheet = Nothing
'*********** ********* ********* ********* *
''Copy this script in .vbs file and double click on it or paste this script in QTP and execute it.
''After that go C:\ drive you will find an excel application in the name of TEST.xls..
''Try to understand this by referring excel object model.. Revert me for any concerns..
'*********** ********* ********* ********* *
'creating an excel application object
Set Excel=CreateObject( "Excel.Application")
'Adding a sheet in that application
Set ExcelSheet = CreateObject( "Excel.Sheet" )
' Make Excel visible through the Application object.
ExcelSheet.Application.Visible = True
'Adding value into sheet
For i=1 to 10
ExcelSheet.ActiveSheet.Cells( i,1).Value = "This is column A, row"&i
Next
' Save the sheet.
ExcelSheet.SaveAs "C:\TEST.xls"
' Close Excel with the Quit method on the Application object.
ExcelSheet.Applicat ion.Quit
' Release the object variable.
Set ExcelSheet = Nothing
'*********** ********* ********* ********* *
''Copy this script in .vbs file and double click on it or paste this script in QTP and execute it.
''After that go C:\ drive you will find an excel application in the name of TEST.xls..
''Try to understand this by referring excel object model.. Revert me for any concerns..
How to set the value for a property
Setting.Add "Tester Name", "Mark Train"
MsgBox Setting("Tester Name")
MsgBox Setting("Tester Name")
Use of SetTOProperty
'For example..in first build there is a OK button..and u
'reorded on OK button..
'but in modified build it changed to Yes..and this
'modificatio is only for single build...in this situation u
'need to change that button name OK to Yes
'window("XXXX").winbutton("OK").SetTOProperty "Text","Yes"
'reorded on OK button..
'but in modified build it changed to Yes..and this
'modificatio is only for single build...in this situation u
'need to change that button name OK to Yes
'window("XXXX").winbutton("OK").SetTOProperty "Text","Yes"
To search for something in Google
url="ww.google.com"
systemutil.Run"IEXPLORE",url 'It is to Open a Browser with any website address
Set gBrowser=Browser("name:=Google.*")
Set gPage=gBrowser.Page("title:=Google.*")
gPage.webedit("name:=q","type:=text","html tag:=INPUT").set "QTP"
gpage.webbutton("name:=Google Search","index:=0","type:=submit","html tag:=INPUT").click
systemutil.Run"IEXPLORE",url 'It is to Open a Browser with any website address
Set gBrowser=Browser("name:=Google.*")
Set gPage=gBrowser.Page("title:=Google.*")
gPage.webedit("name:=q","type:=text","html tag:=INPUT").set "QTP"
gpage.webbutton("name:=Google Search","index:=0","type:=submit","html tag:=INPUT").click
To Check weather the text contains a particular word or not
To check/Uncheck all the checkboxes present on a web page
Systemutil.Run"IExplore","www.yahoomail.com"
wait(10)
Dim obj_DescChk
Set obj_DescChk=Description.Create
obj_DescChk("html tag").value="INPUT"
obj_DescChk("type").value="checkbox"
'obj_DescChk.remove "html tag" '''''''''''''''''''Would delete the html tag property from the collections
'If obj_DescChk("html tag").value=empty then ''''''''To Know the property is exists or not in the collection
'obj_DescChk("html tag").value="INPUT" '''''''''''''''''If not then add it to the collection
'end if
Dim AllChkBoxes, SingleChkBox
Set AllChkBoxes=Browser("title:=Yahoo! Mail: The best web-based email!").Page("title:=Yahoo! Mail: The best web-based email!").ChildObjects(obj_DescChk)
msgbox AllChkBoxes.count
For i=0 to AllChkBoxes.count-1
AllChkBoxes(i).set "ON"
Next
wait(10)
Dim obj_DescChk
Set obj_DescChk=Description.Create
obj_DescChk("html tag").value="INPUT"
obj_DescChk("type").value="checkbox"
'obj_DescChk.remove "html tag" '''''''''''''''''''Would delete the html tag property from the collections
'If obj_DescChk("html tag").value=empty then ''''''''To Know the property is exists or not in the collection
'obj_DescChk("html tag").value="INPUT" '''''''''''''''''If not then add it to the collection
'end if
Dim AllChkBoxes, SingleChkBox
Set AllChkBoxes=Browser("title:=Yahoo! Mail: The best web-based email!").Page("title:=Yahoo! Mail: The best web-based email!").ChildObjects(obj_DescChk)
msgbox AllChkBoxes.count
For i=0 to AllChkBoxes.count-1
AllChkBoxes(i).set "ON"
Next
To retrive data from datatable which is in 3rd row and 4th column
'in Action1 sheet change the names of A,B,C,D columns with A,B,C,D respectively.
'And type the values in D column
datatable.SetCurrentRow(3)
answer=datatable(4,2)'.Value(4,2) '4th column in 2nd Sheet
msgbox answer
'Run the program
'-------------------------------------
'To retrive value from 3rd row 4th column from external excel sheet
datatable.Importsheet "c:/1.xls",1,1
datatable.SetCurrentRow(3)
val=datatable.Value(4,1)'4th column 1st sheet
msgbox "The Value is "&val
'And type the values in D column
datatable.SetCurrentRow(3)
answer=datatable(4,2)'.Value(4,2) '4th column in 2nd Sheet
msgbox answer
'Run the program
'-------------------------------------
'To retrive value from 3rd row 4th column from external excel sheet
datatable.Importsheet "c:/1.xls",1,1
datatable.SetCurrentRow(3)
val=datatable.Value(4,1)'4th column 1st sheet
msgbox "The Value is "&val
How to paste a image in Word Document
Set objWord = CreateObject( "Word.Application")
objWord.Visible = True
Set objDoc = objWord.Documents. Add()
Set objSelection = objWord.Selection
Set objShape = objDoc.Shapes
objShape.AddPicture ("c:\image010.jpg")
objWord.Visible = True
Set objDoc = objWord.Documents. Add()
Set objSelection = objWord.Selection
Set objShape = objDoc.Shapes
objShape.AddPicture ("c:\image010.jpg")
To Know the No of Items in the Web Page
url="http://my.naukri.com/manager/createacc2.php?othersrcp=5421&wExp=N"
'url="www.gmail.com"
'url="www.yahoomail.com"
If Browser("index:=0").Exist(1) then' If Browser is already opened
a = Browser("index:=0").GetROProperty("hwnd")
Browser("hwnd:=" & a).Navigate(url)
Browser("hwnd:=" & a).Sync
wait(2)
Else' If Browser is not opened
SystemUtil.Run"IEXPLORE.exe"
a = Browser("index:=0").GetROProperty("hwnd")
Browser("hwnd:=" & a).Navigate(url)
Browser("hwnd:=" & a).Sync
wait(2)
End If
Set Editobj=Description.Create'For WebEdits
Editobj("html tag").value="INPUT"
Editobj("kind").value="singleline"
Set Butobj = Description.Create'For Buttons
Butobj("html tag").value = "INPUT"
Butobj("type").value="submit"
Set Listobj=Description.Create'For Web Lists
Listobj("html tag").value="SELECT"
Set Linkobj=Description.Create'For Link
Linkobj("html tag").value="A"
Set Checkboxobj=Description.Create'For Checkboxes
Checkboxobj("html tag").value="INPUT"
Checkboxobj("type").value="checkbox"
Set Radioobj=Description.Create'For Radio Buttons
Radioobj("html tag").value="INPUT"
Radioobj("html id").value="ctctype_i"
Set Edits = browser("hwnd:=" &a).Page("title:=.*").ChildObjects(Editobj)
Set Buttons = browser("hwnd:=" &a).Page("title:=.*").ChildObjects(Butobj)
Set Lists = browser("hwnd:=" &a).Page("title:=.*").ChildObjects(Listobj)
Set Links = browser("hwnd:=" &a).Page("title:=.*").ChildObjects(Linkobj)
Set Checks = browser("hwnd:=" &a).Page("title:=.*").ChildObjects(Checkboxobj)
Set Radios = browser("hwnd:=" &a).Page("title:=.*").ChildObjects(Radioobj)
msgbox "Total EditBoxes are : "&Edits.count
msgbox "Total Button are : "&Buttons.count
msgbox "Total Lists are : "&Lists.count
msgbox "Total Links are : "&Links.count
msgbox "Total checkBoxes are : "&Checks.count
msgbox "Total RadioButtons are : "&Radios.count
'url="www.gmail.com"
'url="www.yahoomail.com"
If Browser("index:=0").Exist(1) then' If Browser is already opened
a = Browser("index:=0").GetROProperty("hwnd")
Browser("hwnd:=" & a).Navigate(url)
Browser("hwnd:=" & a).Sync
wait(2)
Else' If Browser is not opened
SystemUtil.Run"IEXPLORE.exe"
a = Browser("index:=0").GetROProperty("hwnd")
Browser("hwnd:=" & a).Navigate(url)
Browser("hwnd:=" & a).Sync
wait(2)
End If
Set Editobj=Description.Create'For WebEdits
Editobj("html tag").value="INPUT"
Editobj("kind").value="singleline"
Set Butobj = Description.Create'For Buttons
Butobj("html tag").value = "INPUT"
Butobj("type").value="submit"
Set Listobj=Description.Create'For Web Lists
Listobj("html tag").value="SELECT"
Set Linkobj=Description.Create'For Link
Linkobj("html tag").value="A"
Set Checkboxobj=Description.Create'For Checkboxes
Checkboxobj("html tag").value="INPUT"
Checkboxobj("type").value="checkbox"
Set Radioobj=Description.Create'For Radio Buttons
Radioobj("html tag").value="INPUT"
Radioobj("html id").value="ctctype_i"
Set Edits = browser("hwnd:=" &a).Page("title:=.*").ChildObjects(Editobj)
Set Buttons = browser("hwnd:=" &a).Page("title:=.*").ChildObjects(Butobj)
Set Lists = browser("hwnd:=" &a).Page("title:=.*").ChildObjects(Listobj)
Set Links = browser("hwnd:=" &a).Page("title:=.*").ChildObjects(Linkobj)
Set Checks = browser("hwnd:=" &a).Page("title:=.*").ChildObjects(Checkboxobj)
Set Radios = browser("hwnd:=" &a).Page("title:=.*").ChildObjects(Radioobj)
msgbox "Total EditBoxes are : "&Edits.count
msgbox "Total Button are : "&Buttons.count
msgbox "Total Lists are : "&Lists.count
msgbox "Total Links are : "&Links.count
msgbox "Total checkBoxes are : "&Checks.count
msgbox "Total RadioButtons are : "&Radios.count
To Insert a Value in a Exce l Sheet
''''''''''''''''''''To Insert a Value in a Exce l Sheet'''''''''''''''''''''''''
Set xl=createobject("Excel.Application")
Set x=xl.workbooks.open("c:/arun.xls")
Set y=xl.activeworkbook.worksheets("sheet1")
xl.cells(1,1)="arun"
Set xl=createobject("Excel.Application")
Set x=xl.workbooks.open("c:/arun.xls")
Set y=xl.activeworkbook.worksheets("sheet1")
xl.cells(1,1)="arun"
Wednesday, December 3, 2008
To get the only numbers from the flat file and store in a datatable
'bombay 100 hyderabad jkjk '
'djkhkk ksljk 88 asdk '
'dkjsajl kskj kjhsjk 88 '
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''To get the only numbers from the flat file and store in a datatable''''''''''''''''''''''''''''''''''''
set fso=createobject("scripting.filesystemobject")
set oText=fso.opentextfile("c:/demo.txt",1)
datatable.getsheet(1).addparameter"Numbers",""
row=1
While not oText.atendofline
text=oText.readline
n=split(text," ")
for i=lbound(n) to ubound(n)
If isnumeric(n(i)) then
datatable.setcurrentrow(row)
datatable(1,1)=n(i) '''''''''''''''datatable(ColumnNo,SheetNo)
row=row+1
end if
Next
wend
'djkhkk ksljk 88 asdk '
'dkjsajl kskj kjhsjk 88 '
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''To get the only numbers from the flat file and store in a datatable''''''''''''''''''''''''''''''''''''
set fso=createobject("scripting.filesystemobject")
set oText=fso.opentextfile("c:/demo.txt",1)
datatable.getsheet(1).addparameter"Numbers",""
row=1
While not oText.atendofline
text=oText.readline
n=split(text," ")
for i=lbound(n) to ubound(n)
If isnumeric(n(i)) then
datatable.setcurrentrow(row)
datatable(1,1)=n(i) '''''''''''''''datatable(ColumnNo,SheetNo)
row=row+1
end if
Next
wend
To Display the Files in a Particular Folder
'''''''''''''''''''To Display the Files in a Particular Folder'''''''''''''''''''''''''''''''''''
folderpath="E:\macromedia-8"
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(folderpath)
Set fc = f.Files
For Each f1 in fc
s = s & f1.name &chr(10)
Next
folderpath="E:\macromedia-8"
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(folderpath)
Set fc = f.Files
For Each f1 in fc
s = s & f1.name &chr(10)
Next
To count the no of links and button in a web page
'''''''''''''''''''''''''Open A Google Page and Count the No Of Links and Buttons in that page'''''''''''''''''''''''''''''''''''
' '
' '
' '
' '
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
If Browser("index:=0").Exist(1) then' If Browser is already opened
a = Browser("index:=0").GetROProperty("hwnd")
Browser("hwnd:=" & a).Navigate("http://www.google.com")
Browser("hwnd:=" & a).Sync
wait(2)
Else' If Browser is not opened
SystemUtil.Run"IEXPLORE.exe"
a = Browser("index:=0").GetROProperty("hwnd")
Browser("hwnd:=" & a).Navigate("http://www.google.com")
Browser("hwnd:=" & a).Sync
wait(2)
End If
Set Butobj = Description.Create()'For Button
Butobj("html tag").value = "INPUT"'For Button
Butobj("type").value="submit"'For Button
Set Linkobj=Description.Create()'For Link
Linkobj("html tag").value="A"'For Link
Set Buttons = browser("hwnd:=" &a).Page("title:=.*").ChildObjects(Butobj)
Set Links = browser("hwnd:=" &a).Page("title:=.*").ChildObjects(Linkobj)
msgbox "Total Button are : "&Buttons.count
msgbox "Total Links are : "&Links.count
' '
' '
' '
' '
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
If Browser("index:=0").Exist(1) then' If Browser is already opened
a = Browser("index:=0").GetROProperty("hwnd")
Browser("hwnd:=" & a).Navigate("http://www.google.com")
Browser("hwnd:=" & a).Sync
wait(2)
Else' If Browser is not opened
SystemUtil.Run"IEXPLORE.exe"
a = Browser("index:=0").GetROProperty("hwnd")
Browser("hwnd:=" & a).Navigate("http://www.google.com")
Browser("hwnd:=" & a).Sync
wait(2)
End If
Set Butobj = Description.Create()'For Button
Butobj("html tag").value = "INPUT"'For Button
Butobj("type").value="submit"'For Button
Set Linkobj=Description.Create()'For Link
Linkobj("html tag").value="A"'For Link
Set Buttons = browser("hwnd:=" &a).Page("title:=.*").ChildObjects(Butobj)
Set Links = browser("hwnd:=" &a).Page("title:=.*").ChildObjects(Linkobj)
msgbox "Total Button are : "&Buttons.count
msgbox "Total Links are : "&Links.count
To copy contents of one file to another file
'To copy contents of one file to another file
Set fso=createobject("scripting.filesystemobject")
Set fname=fso.opentextfile("C:/mtable.txt",1)
Set fname1=fso.createtextfile("C:/duptable1.txt")
Do while not fname.atendofstream
n=fname.readline
fname1.writeline n
Loop
Set fso=createobject("scripting.filesystemobject")
Set fname=fso.opentextfile("C:/mtable.txt",1)
Set fname1=fso.createtextfile("C:/duptable1.txt")
Do while not fname.atendofstream
n=fname.readline
fname1.writeline n
Loop
To Color the column in a excel sheet
'""""To Color the column in a excel sheet.""""""""""""""''''
Set xlApp=Createobject("Excel.Application")
set xlWorkBook=xlApp.workbooks.add
set xlWorkSheet=xlWorkbook.worksheets.add
xlWorkSheet.Range("A1:B10").interior.colorindex = 34 'Change the color of the cells
xlWorkSheet.Range("A1:A10").value="text" 'Will set values of all 10 rows to "text"
xlWorkSheet.Cells(1,1).value="Text" 'Will set the value of first row and first col
rowsCount=xlWorkSheet.Evaluate("COUNTA(A:A)") 'Will count the # of rows which have non blank value in the column A
colsCount=xlWorkSheet.Evaluate("COUNTA(1:1)") 'Will count the # of non blank columns in 1st row
xlWorkbook.SaveAs "C:\Test.xls"
xlWorkBook.Close
Set xlWorkSheet=Nothing
Set xlWorkBook=Nothing
set xlApp=Nothing
Set xlApp=Createobject("Excel.Application")
set xlWorkBook=xlApp.workbooks.add
set xlWorkSheet=xlWorkbook.worksheets.add
xlWorkSheet.Range("A1:B10").interior.colorindex = 34 'Change the color of the cells
xlWorkSheet.Range("A1:A10").value="text" 'Will set values of all 10 rows to "text"
xlWorkSheet.Cells(1,1).value="Text" 'Will set the value of first row and first col
rowsCount=xlWorkSheet.Evaluate("COUNTA(A:A)") 'Will count the # of rows which have non blank value in the column A
colsCount=xlWorkSheet.Evaluate("COUNTA(1:1)") 'Will count the # of non blank columns in 1st row
xlWorkbook.SaveAs "C:\Test.xls"
xlWorkBook.Close
Set xlWorkSheet=Nothing
Set xlWorkBook=Nothing
set xlApp=Nothing
To know the no of list items in the web page
''''''''''''''''''''To know the no of list items in the web page'''''''''''''''''''''''''''''''''
url="http://corp.naukri.com/mynaukri/mn_newsmartsearch.php?xz=2_0_5&id="
Systemutil.Run "Iexplore.exe",url
set oDesc= Browser("name:=Mynaukri : naukri.com - India's No.1 Job Site")
itemcount=oDesc.WebList("name:=qe").GetROProperty("items count")
msgbox "Number of Items in Experience List= "& itemcount
itemcount=oDesc.WebList("name:=qm").GetROProperty("items count")
msgbox "Number of Items in Minimum Salary List= "&itemcount
url="http://corp.naukri.com/mynaukri/mn_newsmartsearch.php?xz=2_0_5&id="
Systemutil.Run "Iexplore.exe",url
set oDesc= Browser("name:=Mynaukri : naukri.com - India's No.1 Job Site")
itemcount=oDesc.WebList("name:=qe").GetROProperty("items count")
msgbox "Number of Items in Experience List= "& itemcount
itemcount=oDesc.WebList("name:=qm").GetROProperty("items count")
msgbox "Number of Items in Minimum Salary List= "&itemcount
Replace all text with a new text in a text file
Set oDesc=createobject("scripting.filesystemobject")
Set oFile=oDesc.opentextfile("c:/demo.txt",2,true)'''''1-Reading 2-Writing 3-Appending
oFile.write "Hello World"
Set oFile=oDesc.opentextfile("c:/demo.txt",2,true)'''''1-Reading 2-Writing 3-Appending
oFile.write "Hello World"
Open Dialog box from Tool Menu of the MS Word Application
'This program will open a word pad and enter some text (impossibel) and checks the spelling and grammar in that text
'This program will open a word and opens a spelling and grammar dialog box for tools menu
Const wdDialogToolsSpellingAndGrammar = 828
Const wdDoNotSaveChanges = 0
Uncorrected = "impossibel"
Set Word = CreateObject("Word.Application")
Set Doc = Word.Documents.Add
Word.Selection.Text = Uncorrected
Word.Dialogs(wdDialogToolsSpellingAndGrammar).Show
If Len(Word.Selection.Text) <> 1 Then
Corrected = Word.Selection.Text
Else
Corrected = Uncorrected
End If
Doc.Close wdDoNotSaveChanges
Word.Quit
'This program will open a word and opens a spelling and grammar dialog box for tools menu
Const wdDialogToolsSpellingAndGrammar = 828
Const wdDoNotSaveChanges = 0
Uncorrected = "impossibel"
Set Word = CreateObject("Word.Application")
Set Doc = Word.Documents.Add
Word.Selection.Text = Uncorrected
Word.Dialogs(wdDialogToolsSpellingAndGrammar).Show
If Len(Word.Selection.Text) <> 1 Then
Corrected = Word.Selection.Text
Else
Corrected = Uncorrected
End If
Doc.Close wdDoNotSaveChanges
Word.Quit
Multiple Screen shots at runtime
''''''''''''''''''''''''''''''''To create multiple screeen shots at runtime''''''''''''''''''''''''''''''''''''''
Systemutil.run"C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe"
Set Dlg= Dialog("text:=Login")
Set wnd=Window("text:=Flight Reservation")
Set oDlg=wnd.Dialog("text:=Open Order")
Dlg.WinEdit("attached text:=Agent Name:").set "rajaputra"
Dlg.WinEdit("attached text:=Password:").setsecure"mercury"
Dlg.WinButton("text:=OK").click
wait(7)
For i=1 to
wnd.Activate
wnd.WinButton("window id:=5").click
oDlg.WinCheckBox("text:=&Order No.").set "ON"
oDlg.WinEdit("window id:=1016").set "55"
oDlg.WinButton("text:=OK").click
if(oDlg.Dialog("text:=Flight Reservations").Exist) then
oDlg.Dialog("text:=Flight Reservations").CaptureBitmap"c:\snapshot"&i&".bmp"
oDlg.Dialog("text:=Flight Reservations").WinButton("text:=OK").click
oDlg.WinButton("text:=Cancel").click
end if
Next
wnd.Close
Systemutil.run"C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe"
Set Dlg= Dialog("text:=Login")
Set wnd=Window("text:=Flight Reservation")
Set oDlg=wnd.Dialog("text:=Open Order")
Dlg.WinEdit("attached text:=Agent Name:").set "rajaputra"
Dlg.WinEdit("attached text:=Password:").setsecure"mercury"
Dlg.WinButton("text:=OK").click
wait(7)
For i=1 to
wnd.Activate
wnd.WinButton("window id:=5").click
oDlg.WinCheckBox("text:=&Order No.").set "ON"
oDlg.WinEdit("window id:=1016").set "55"
oDlg.WinButton("text:=OK").click
if(oDlg.Dialog("text:=Flight Reservations").Exist) then
oDlg.Dialog("text:=Flight Reservations").CaptureBitmap"c:\snapshot"&i&".bmp"
oDlg.Dialog("text:=Flight Reservations").WinButton("text:=OK").click
oDlg.WinButton("text:=Cancel").click
end if
Next
wnd.Close
DP from Logging in - Open a Order and Closing the Flight Reservation Application
''''''''''''''' Discriptive Program for starting from Logging in - Opening a order and closing the Flight Reservation Application'''''''''''''
''''''''''''''Importing the Excel sheet into datatable and Exporting the Datatable into Excel file''''''''''''''''''''''''''''''''''''''''
systemutil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe"
Dialog("text:=Login").Activate
Dialog("text:=Login").WinEdit("attached text:=Agent Name:").set "rajaputra"
Dialog("text:=Login").WinEdit("attached text:=Password:").set "mercury"
Dialog("text:=Login").WinButton("text:=OK").click
wait(5)
Window("text:=Flight Reservation").Activate
datatable.Importsheet "c:/orders.xls",1,1' 1st sheet will be imported into the 1st sheet in runtime datatable
rowcount=datatable.GetRowCount
'msgbox rowcount
For i=1 to rowcount
Window("text:=Flight Reservation").WinButton("window id:=5").click
Dialog("text:=Open Order").Activate
Dialog("text:=Open Order").WinCheckBox("text:=&Order No.").set "ON"
datatable.SetCurrentRow(i)
n=datatable(1,1) '1st column 1st sheet
Dialog("text:=Open Order").WinEdit("window id:=1016").set n
Dialog("text:=Open Order").WinButton("text:=OK").click
If(window("text:=Flight Reservation").Dialog("text:=Open Order").Dialog("text:=Flight Reservations").exist)then
window("text:=Flight Reservation").Dialog("text:=Open Order").Dialog("text:=Flight Reservations").WinButton("text:=OK").click
window("text:=Flight Reservation").Dialog("text:=Open Order").WinButton("text:=Cancel").click
datatable(2,1)="Not Exist"'2nd column 1st sheet
Else
datatable(2,1)="Exist" '2nd column 1st sheet
end if
Next
DataTable.Exportsheet"C:\flight.xls",1'1st sheet of the runtime datatable will be exported at last sheet in flight.xls
Window("text:=Flight Reservation").Close
''''''''''''''Importing the Excel sheet into datatable and Exporting the Datatable into Excel file''''''''''''''''''''''''''''''''''''''''
systemutil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe"
Dialog("text:=Login").Activate
Dialog("text:=Login").WinEdit("attached text:=Agent Name:").set "rajaputra"
Dialog("text:=Login").WinEdit("attached text:=Password:").set "mercury"
Dialog("text:=Login").WinButton("text:=OK").click
wait(5)
Window("text:=Flight Reservation").Activate
datatable.Importsheet "c:/orders.xls",1,1' 1st sheet will be imported into the 1st sheet in runtime datatable
rowcount=datatable.GetRowCount
'msgbox rowcount
For i=1 to rowcount
Window("text:=Flight Reservation").WinButton("window id:=5").click
Dialog("text:=Open Order").Activate
Dialog("text:=Open Order").WinCheckBox("text:=&Order No.").set "ON"
datatable.SetCurrentRow(i)
n=datatable(1,1) '1st column 1st sheet
Dialog("text:=Open Order").WinEdit("window id:=1016").set n
Dialog("text:=Open Order").WinButton("text:=OK").click
If(window("text:=Flight Reservation").Dialog("text:=Open Order").Dialog("text:=Flight Reservations").exist)then
window("text:=Flight Reservation").Dialog("text:=Open Order").Dialog("text:=Flight Reservations").WinButton("text:=OK").click
window("text:=Flight Reservation").Dialog("text:=Open Order").WinButton("text:=Cancel").click
datatable(2,1)="Not Exist"'2nd column 1st sheet
Else
datatable(2,1)="Exist" '2nd column 1st sheet
end if
Next
DataTable.Exportsheet"C:\flight.xls",1'1st sheet of the runtime datatable will be exported at last sheet in flight.xls
Window("text:=Flight Reservation").Close
Importing Data from Flat File using Split function
'''''''''''''''''Importing Data From Flat File using split''''''''''''''''''''''''''''
''Source.txt file is having following data
''Arunsingh,40000,KiranKumar,35000,Chandra,50000
''Test Engineer,Developer,Project Leader
Set fso=createobject("scripting.filesystemobject")
Set z=fso.opentextfile("c:\source.txt",1)
l=1
While not z.atendofline
i=1
k=1
count=1
parname=inputbox("Enter Name of The Parameter "&l) '''''Enter the requiered parameter names
datatable.GetSheet(1).addparameter parname,""
n=z.readline
a=split(n,",")
For j=lbound(a) to ubound(a)
If isnumeric(a(j)) Then
If count=1 Then
datatable.GetSheet(1).addparameter "Salary",""
count=count+1
end if
datatable.SetCurrentRow(k)
m=l +1
datatable(m,1)=a(j)
k=k+1
else
datatable.SetCurrentRow(i)
datatable(l,1)=a(j)
i=i+1
end if
Next
l=m
l=l+1
Wend
''Source.txt file is having following data
''Arunsingh,40000,KiranKumar,35000,Chandra,50000
''Test Engineer,Developer,Project Leader
Set fso=createobject("scripting.filesystemobject")
Set z=fso.opentextfile("c:\source.txt",1)
l=1
While not z.atendofline
i=1
k=1
count=1
parname=inputbox("Enter Name of The Parameter "&l) '''''Enter the requiered parameter names
datatable.GetSheet(1).addparameter parname,""
n=z.readline
a=split(n,",")
For j=lbound(a) to ubound(a)
If isnumeric(a(j)) Then
If count=1 Then
datatable.GetSheet(1).addparameter "Salary",""
count=count+1
end if
datatable.SetCurrentRow(k)
m=l +1
datatable(m,1)=a(j)
k=k+1
else
datatable.SetCurrentRow(i)
datatable(l,1)=a(j)
i=i+1
end if
Next
l=m
l=l+1
Wend
Fixed VS Dynamic Arrays
'Using Fixed arrays
Dim x(2)
x(0)="how"
x(1)="are"
x(2)="you"
for i=lbound(x) to ubound (x)
msgbox x(i)
Next
'Here we cann't store more than 3 elements. Because this is a fixed length array..
'Using Dynamic Arrays
Dim x()
Redim preserve x(2)
x(0)="how"
x(1)="are"
x(2)="you"
Redim preserve x(3)
x(3)=123
'Here 'x' is a dynamic array and by redeclaring x it can able to store more values into it.
Dim x(2)
x(0)="how"
x(1)="are"
x(2)="you"
for i=lbound(x) to ubound (x)
msgbox x(i)
Next
'Here we cann't store more than 3 elements. Because this is a fixed length array..
'Using Dynamic Arrays
Dim x()
Redim preserve x(2)
x(0)="how"
x(1)="are"
x(2)="you"
Redim preserve x(3)
x(3)=123
'Here 'x' is a dynamic array and by redeclaring x it can able to store more values into it.
Displaying Numbers into Ascending Order
''''''''''''''''Displaying numbers into Ascending Order By Using Arrays'''''''''''''''''''''''''''''''''''''''''
a=array(10,20,1,30,2,40,23,50,4)
For j=lbound(a) to ubound(a)
For i=lbound(a) to ubound(a)-1
If a(i)>a(i+1) Then
temp=a(i+1)
a(i+1)=a(i)
a(i)=temp
End If
Next
Next
For i=lbound(a) to ubound(a)
x=x&chr(10)&a(i)
Next
msgbox(x)
a=array(10,20,1,30,2,40,23,50,4)
For j=lbound(a) to ubound(a)
For i=lbound(a) to ubound(a)-1
If a(i)>a(i+1) Then
temp=a(i+1)
a(i+1)=a(i)
a(i)=temp
End If
Next
Next
For i=lbound(a) to ubound(a)
x=x&chr(10)&a(i)
Next
msgbox(x)
Capture the Screen shot during runtime
''''''''''''''''''''''Capture the Screen Shot when Error Is Occured'''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''Using Objects'''''''''''''''''''''''''''''''''''''''''''''''''
Systemutil.run"C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe"
Set Dlg= Dialog("text:=Login")
Set wnd=Window("text:=Flight Reservation")
Set oDlg=wnd.Dialog("text:=Open Order")
Dlg.WinEdit("attached text:=Agent Name:").set "rajaputra"
Dlg.WinEdit("attached text:=Password:").setsecure"mercury"
Dlg.WinButton("text:=OK").click
wait(7)
wnd.Activate
wnd.WinButton("window id:=5").click
oDlg.WinCheckBox("text:=&Order No.").set "ON"
oDlg.WinEdit("window id:=1016").set "55"
oDlg.WinButton("text:=OK").click
if(oDlg.Dialog("text:=Flight Reservations").Exist) then
oDlg.Dialog("text:=Flight Reservations").CaptureBitmap"c:\snapshot1.bmp"
oDlg.Dialog("text:=Flight Reservations").WinButton("text:=OK").click
oDlg.WinButton("text:=Cancel").click
end if
wnd.Close
'''''''''''''''''''''''''''''''''''''Using Objects'''''''''''''''''''''''''''''''''''''''''''''''''
Systemutil.run"C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe"
Set Dlg= Dialog("text:=Login")
Set wnd=Window("text:=Flight Reservation")
Set oDlg=wnd.Dialog("text:=Open Order")
Dlg.WinEdit("attached text:=Agent Name:").set "rajaputra"
Dlg.WinEdit("attached text:=Password:").setsecure"mercury"
Dlg.WinButton("text:=OK").click
wait(7)
wnd.Activate
wnd.WinButton("window id:=5").click
oDlg.WinCheckBox("text:=&Order No.").set "ON"
oDlg.WinEdit("window id:=1016").set "55"
oDlg.WinButton("text:=OK").click
if(oDlg.Dialog("text:=Flight Reservations").Exist) then
oDlg.Dialog("text:=Flight Reservations").CaptureBitmap"c:\snapshot1.bmp"
oDlg.Dialog("text:=Flight Reservations").WinButton("text:=OK").click
oDlg.WinButton("text:=Cancel").click
end if
wnd.Close
Subscribe to:
Posts (Atom)
About Me
- RAJAPUTRA
- Hi all,I am Arun Singh Rajaputra. I am working as a Project Lead in a reputed organization in Hyderabad, AP, India. I have little bit knowledge on Quick Test Professional and like to share my knowledge to all through this blog.
Subscribe to get updates on this blog
NOTE
Some of the posts posted in this blog are collected and most of them have been prepared by me. If any one have objections regarding any copied posts. Please mail me so that I can take a necessary action on that post.