See the basic post if you didn't.
Now you wonder, is there a way to implement inside our code.
Here we go;
Browser("myapp").Page("myPage").WebEdit("mytext1").Set "someText1" If Err.Number <> 0 Then Reporter.ReportEvent micFail, "some step", "some description" Err.Clear End If 'after handling the error, continue to next step Browser("myapp").Page("myPage").WebEdit("mytext2").Set "someText2" If Err.Number <> 0 Then Reporter.ReportEvent micFail, "some step", "some description" Err.Clear End If
So the complexity is, we need to add the error check block after each step which is not good.So what can we do better is;Function CheckForError
Environment.Value("IsError") = False
If Err.Number <> 0 Then
Reporter.ReportEvent micFail, "some step", "some description"
Environment.Value("IsError") = True
End If
CheckError = Environment.Value("IsError")
End Function
'##########################################################
' ---------------- COMPONENTS ----------------------------
'##########################################################
Function COMPONENT_1
Browser("myapp").Page("myPage").WebEdit("mytext1").Set "someText1"
If CheckForError Then Exit Function
Browser("myapp").Page("myPage").WebEdit("mytext2").Set "someText2"
If CheckForError Then Exit Function
End Function
From your Driver Script, you can check for Environment.Value("IsError") after executing each keyword and take decision. What else we can do still to avoid even these calls but need this error handling.
Using Recovery Scenario:
You can create a Recovery Scenario with the event "Test Run Error" and add this CheckError function as part of recovery function. Now it should call and check for errors, do the recovery steps described as part of your function whenever an error happens.
Also you can write some common function to do all events with error handling like this and use.
Function Simulate(objUICtrl, strValue) On Error Resume Next Select UCase(objUICtrl.GetROProperty("micClass")) Case "WEBEDIT": objUICtrl.Set Trim(strValue) Case "WEBLIST": objUICtrl.Select Trim(strValue) Case "WEBELEMENT": objUICtrl.Type Trim(strValue) End Select If Err.Number <> 0 Then 'Your recovery steps... End If Err.Clear 'always safety End Function RegisterUserFunc "WebEdit", "Set", "Simulate", True RegisterUserFunc "WebList", "Select", "Simulate", True RegisterUserFunc "WebElement", "Type", "Simulate", True
Usage: Browser("myApp").Page("myPage").WebEdit("someText").Simulate "someValue" Browser("myApp").Page("myPage").WebList("someList").Simulate "someValue"
Comments
Post a Comment