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

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

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

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

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

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

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"

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

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

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 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

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.

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)

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

About Me

My photo
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

Enter your email address:

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.