Thursday, October 9, 2008

Yahoo Login Automation

Let's share my experience with yahoo Login automation

Steps to create Script for yahoo login :
1) Main script --> calls function(s) in file loginscript.vbs.
2) loginscript.vbs --> contains two public functions login() and validateLogin().
3) Data for login name and password is being fetched from Global data sheet.

1. Contents of Main script :

username = datatable.Value("Username", dtGlobalSheet)
password = datatable.Value("Password", dtGlobalSheet)
call login(username, password)
call validateLogin()

2. Content of loginscript.vbs :

public function login(uName, uPwd)

SystemUtil.Run"iexplore","http://www.yahoomail.com"

set objUserName = description.create
objUserName("name").value = "login"

set objUserPwd = description.create
objUserPwd("name").value = "passwd"

set objSignIn = description.create
objSignIn("name").value = "Sign In"

Set g=Browser("name:=Yahoo.*").Page("title:=Yahoo.*")
g.WebEdit(objUserName).Set uName
g.WebEdit(objUserPwd).SetSecure uPwd
g.WebButton(objSignIn).Click

End Function

public function validateLogin()
If Browser("name:=Yahoo! Mail.*").Exist Then
reporter.ReportEvent micPass, "Found Yahoo! Mail'", "Logged in successfully, Test Case Passed"
else
reporter.ReportEvent micFail, " Not Found yahoo! Mail" , "Unsucessfull Login, Test Case Failed"
End if
End Function

3. Contents of Global Data sheet :

Username Password
Username-> Enter your yahoo username in data sheet
Password-> Enter your yahoo password in data sheet

Monday, October 6, 2008

Sample Test Project

Steps
1)Open the excel sheet ..Enter the following values in excel sheet

No.1 No.2 Production Substraction Division Addition
5 3



2 1



3 7



2 8




2)Open calculator application using QTP.
3)Then we have to read this no1 and no2 values from the excel sheet.
4)Using this values we need to click the appropriate buttons in calculator application.
5)Then do the calculation for addition, substraction, production and division
6)Result will be save in same excel sheet.

Use the below code for this project..

Save below code as your test script..

'****************************************
On error resume next
Dim i,y

exlPath="D:\Test Project\Test_Input\sample.xls"

DataTable.ImportSheet exlPath,"Sheet1","Global"
rowCount=datatable.GetSheet("Global").GetRowCount
msgbox "The Row count is "&rowCount
SystemUtil.Run "D:\Test Project\AUT_Build\calc.exe", "","",""

For i =1 to rowCount

num1=trim(datatable.GetSheet("Global").GetParameter("No.1").ValuebyRow(i))
msgbox num1
num2=trim(datatable.GetSheet("Global").GetParameter("No.2").ValuebyRow(i))
msgbox num2

Call addition(num1,num2,rAdd)
Call substraction(num1,num2,rSub)
Call production(num1,num2,rMul)
Call division(num1,num2,rDiv)

rw=i+1

Set oFso = createObject("Excel.Application")
Set oFil= oFso.Workbooks.open(exlPath)
Set oWs=oFil.worksheets("Sheet1")
oWs.cells(rw,3).Value =rMul
oWs.cells(rw,4).Value =rSub
oWs.cells(rw,5).Value =rDiv
oWs.cells(rw,6).Value =rAdd
oFil.save
oFil.close

Next
'****************************************
save this code as function library

'*****************************************
Function addition(num1,num2,rAdd)
Window("text:=Calculator").Activate
Window("text:=Calculator").WinButton("text:="&num1).Click
Window("text:=Calculator").WinButton("text:=\+").Click
Window("text:=Calculator").WinButton("text:="&num2).Click
Window("text:=Calculator").WinButton("text:=\=").Click
rAdd=Window("text:=Calculator").WinEdit("nativeclass:=Edit").GetRoProperty("text")
msgbox "Result"&rAdd
End Function

Function substraction(num1,num2,rSub)
Window("text:=Calculator").Activate
Window("text:=Calculator").WinButton("text:="&num1).Click
Window("text:=Calculator").WinButton("text:=\-").Click
Window("text:=Calculator").WinButton("text:="&num2).Click
Window("text:=Calculator").WinButton("text:=\=").Click
rSub=Window("text:=Calculator").WinEdit("nativeclass:=Edit").GetRoProperty("text")
msgbox "Result"&rSub
End Function

Function production(num1,num2,rMul)
Window("text:=Calculator").Activate
Window("text:=Calculator").WinButton("text:="&num1).Click
Window("text:=Calculator").WinButton("text:=\*").Click
Window("text:=Calculator").WinButton("text:="&num2).Click
Window("text:=Calculator").WinButton("text:=\=").Click
rMul=Window("text:=Calculator").WinEdit("nativeclass:=Edit").GetRoProperty("text")
msgbox "Result"&rMul
End Function

Function division(num1,num2,rDiv)
Window("text:=Calculator").Activate
Window("text:=Calculator").WinButton("text:="&num1).Click
Window("text:=Calculator").WinButton("text:=\/").Click
Window("text:=Calculator").WinButton("text:="&num2).Click
Window("text:=Calculator").WinButton("text:=\=").Click
rDiv=Window("text:=Calculator").WinEdit("nativeclass:=Edit").GetRoProperty("text")
msgbox "Result : "&rDiv
End Function
'*********************************