Modularize the script
I am unable to modularize the script. Can you please help me out to write the script in formal way. The Script is related to validate the Login Screen.
Following is excel file named "TestSheet.xls".
Following is the Script-
Sub Test1
Dim prowin
Dim loginMainWin
Dim loginFrame
Dim edit
Dim uName,pwd
Dim strCaption
' Creates the driver
Set Driver = DDT.ExcelDriver("D:\TCProject\GUITestingAutomation\Stores\TestSheet.xls", "Sheet1")
TestedApps.prowin.Run
Set prowin = Aliases.prowin
Set loginMainWin = prowin.wndProMainWin
Set loginFrame = loginMainWin.ProClientWin.proFrame
Set uname = loginFrame.Edit
Set pwd = loginFrame.Edit2
' Iterates through records
rec = 0
While Not Driver.EOF()
rec = rec + 1
Call uname.Keys("^a")
Call uname.Keys("[BS]")
if rec <> 2 and rec <> 5 then
Call uname.Keys(Driver.Value(0))
end if
Call uname.Keys("[Tab]")
Call pwd.Keys("^a")
Call pwd.Keys("[BS]")
if rec <> 3 and rec <> 5 then
Call pwd.Keys(Driver.Value(1))
end if
loginFrame.btnLogin.ClickButton
if rec = 2 then 'When UserName is Blank
'Call aqObject.CheckProperty(Aliases.prowin.dlgMessage.Static, "WndCaption", cmpEqual, Driver.Value(2), True)
strCaption = Aliases.prowin.dlgInformation.Static.WndCaption
If strCaption <> Driver.Value(2) Then
Log.Error("Property value " & strCaption & " does not match data value " & Driver.Value(2))
End If
prowin.dlgInformation.btnOK.ClickButton
End if
if rec = 3 then 'When Passowrd is Blank
strCaption = Aliases.prowin.dlgInformation.Static2.WndCaption
If strCaption <> Driver.Value(2) Then
Log.Error("Property value " & strCaption & " does not match data value " & Driver.Value(2))
End If
prowin.dlgInformation.btnOK.ClickButton
End if
if rec = 4 then 'Invalid username or password
strCaption = Aliases.prowin.dlgMessage.Static.WndCaption
If strCaption <> Driver.Value(2) Then
Log.Error("Property value " & strCaption & " does not match data value " & Driver.Value(2))
End If
prowin.dlgMessage.btnOK.ClickButton
End if
if rec = 5 then 'When Both Username and Password are blank
strCaption = Aliases.prowin.dlgInformation.Static.WndCaption
If strCaption <> Driver.Value(2) Then
Log.Error("Property value " & strCaption & " does not match data value " & Driver.Value(2))
End If
prowin.dlgInformation.btnOK.ClickButton
End if
if rec <> 2 and rec <> 3 and rec <> 4 and rec <> 5 then
prowin.wndProMainWin2.Close
end if
Call Driver.Next()
Wend
loginMainWin.Close
prowin.wndProMainWin3.Close
' Closes the driver
'Call DDT.CloseDriver(Driver.Name)
End Sub
Here I am using simple if and based on the record exist on excel file, checking the data and Logging error. Please help me to make this script general using some techniques(like DDT loops or some other) if any.