Thursday, July 10, 2008

Use of Windows Shell Script (WSH)

set WshShell = CreateObject("WScript.Shell")

WshShell.AppActivate Parameter("ipURL")

Browser("title:=Test.*").Page("title:=Test.*").Frame("title:=WebFrame.*").WebElement("WebElement").Click

WshShell.SendKeys "{DOWN}"

WshShell.SendKeys "{DOWN}"

WshShell.SendKeys "{DOWN}"

WshShell.SendKeys "{DOWN}"

Log into Web Application

Public Function login(Url,UserName,Password)
Browser("title:=about:blank").Page("url:=[a-z].*").Sync

Browser("title:=about:blank").Navigate urlBrowser("title:=Login").Page("title:=Login").Sync
If not Browser("title:=Login").Page("title:=Login").Exist(TIMEOUT) Then

report_result "FAIL","Login","Login Page is not Displayed" login = -1

Exit Function

End If
Browser("title:=Login").Page("title:=Login").WebEdit("outerhtml :=.*username.*","name:=username").Set username

Browser("title:=Login").Page("title:=Login").WebEdit("outerhtml := .*password.*", "name:=password").Set password
If Browser("title:=Login").Page("title:=Login").Image("alt:=.*Login.*").Exist(OBJ_TIMEOUT) Then

Browser("title:=Login").Page("title:=Login").Image("alt:=.*Login.*").Click

Else

Browser("title:=Login").Page("title:=Login").WebButton("name:=.*Login.*").Click

End If
Browser("title:=Test.*").Page("title:=Test.*").Sync
If Browser("title:=Test.*").Page("title:=Test.*").Exist(TIMEOUT) Then

report_result "PASS","Login","Login Is Successful with the user : "+ username login = 0

Else

report_result "FAIL","Login","Login Is UnSuccessful with the user : "+ username + " User details may not be right. look at the Global data Table" login = -1

Exit Function

End If

End Function

Delete the Cookies in Web Page

Public Function Open_Browser()
SystemUtil.Run "iexplore.exe","about:blank"
Webutil.deletecookies
End Function

Find the Cookies in Web Page

Dim Sample Sample = Browser("name:=Google").Page("title:=Google").Object.cookie
msgbox Sample

'Dim Sample 'Sample = Browser( "Name:=&[A-Za-z]").Page( "title:=&[A-Za-z]").Object.cookie
msgbox Sample

Find the Radio Button in Web page

Set RadBtn_Desc = Description.Create()
RadBtn_Desc("micclass") = "RadioButton"
Set RadBtn_Coll = Browser(B).Page(P).ChildObjects(RadBtn_Desc)
MsgBox RadBtn_Coll.Count

String Compare Function

Value1 = Browser("").Page(""). Webedit("").Get RO Property("Value")
Value2 = Browser("").Page(""). Webedit("").Get RO Property("Value")
Variable have value and now we want to compare the value.
String Compare function:
Dim Value1,Value2, MyCompare
Mycompare = strcomp(Value1,Value2,1)
string1 is less than string2 = 1string1 is equal to string2 = 0 string1 is greater than string2

Add Date to Current Date

Dim Mydate
Mydate = Dateadd("D",4,Date)
Msgbox Mydate

Define the Object Value

Dim RadBtnDesc
Set RadBtnDesc = Description.Create()
RadBtnDesc("Class Name") = "WebEdit"
Set RadBtnColl = Browser("Yahoo! Mail: The best").Page("Yahoo! Mail: The best").ChildObjects(RadBtnDesc)
MsgBox RadBtnColl.Count

Write the Data Into Notepad

Dim a, b
Const ForReading = 1, ForWriting = 2, ForAppending = 8
set a = createobject ("Scripting.FileSystemObject")
Set b = a.Getfile("c:\Vinodh.txt")
Set b = a.opentextfile("c:\Vinodh.txt",ForWriting, True)
b.write "Vinodh from Bangalore"
Set b = a.opentextfile("c:\Vinodh.txt",ForReading, True)
filespec = ("c:\Vinodh.txt")
ShowFileAccessInfo(filespec)
print ShowFileAccessInfo
Function ShowFileAccessInfo(filespec)
Dim fso, f, s
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(filespec)
s = f.Path & "
" s = s & "Created: " & f.DateCreated & "
" s = s & "Last Accessed: " & f.DateLastAccessed & "
" s = s & "Last Modified: " & f.DateLastModified ShowFileAccessInfo = s
End Function

Write the Excel

Function WriteToFile
Const ForReading = 1, ForWriting = 2
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("c:\testfile.txt", ForWriting, True)
f.Write "Hello world!"
Set f = fso.OpenTextFile("c:\testfile.txt", ForReading)
WriteToFile = f.ReadLine
End Function

Open the Notepad

Dim a
set a = wscript.createobject ("wscript.shell")
a.run "notepad.exe"

Copy the excel File

DataTable.ExportSheet(filePath)
DataTable.Import ( FilePath)

Data base Connection

Dim objConn,objRecSet
Set objConn= CreateObject("ADODB.connection")
Set objRecSet = CreateObject("ADODB.recordset")
objConn.open " Server: , Database: , User Name , Password " ' connection string about ur Datanbase objRecSet.open "Select * from Table Name "
objConn.close
objRecSet.close