vb script to stop execution of functions if conditions fail - visitjaga - 12-04-2013
Hi I’m Jagadeesh. It would be helpful to me, if anyone can provide me an idea to below problem
I’ve a scenario in which my script will be executing each test step line by line and for each test step it will report pass and fail result in html result page. If test step result is pass, it will proceed to next test step and further on. Similarly for failed cases it proceeds to next test step and executes it. Is it possible to stop the script when it fails?
Below is the sample outline script
Code: Call webEdit_check (“google”,”google”,”nametxtbox”,”xxxx”)
Call Link_check (strbrowser,strpage,strlink)
Call WebButton_check (strbrowser,strpage,strWebbutton)
So according to above script, it will call webEdit function and check whether object is displayed and visible and will enter value in webEdit textbox and result will be written as pass in html result, if all conditions are satisfied.
After completing above function, now it will call link function and will initiate execution .Here also it will check if object is displayed .
If success, it will go to next step. Let us assume link is not visible, here second step in this function fails and so result is written as fail and execution of third function begins( call WebButton_check).
What I need is entire execution should be stopped as previous test step is failed. Is there any function to run at back end, to stop the execution? When test step fails? Is there any solution to my problem?
(Please note I’ve multiple scenarios so “Exit Test/Exit function” is not applicable.)
Functions are
Code: Function webEdit_check(strbrowser,strpage,strwebEdit,strvalue)
Testobject=Browser(strbrowser).Page(strpage).WebEdit(strlink)
If Testobject.exist(10) Then
blnvisible= testobject.getRoproperty(visible)
If blnvisible =True Then
Testobject.set strvalue
Environment.value(result)=pass
‘It will write result to html page
Call html (“test step is success”,Environment(result))
Else
Environment.value(result)=fail
Call html (“test step is fail”,Environment(result))
End If
Else
Environment.value(result)=fail
Call html (“test object is not visible fail”,Environment(result))
End If
End Function
Function Link_check(strbrowser,strpage,strLink)
Testobject=Browser(strbrowser).Page(strpage).Link(strlink)
If Testobject.exist(10) Then
blnvisible= testobject.getRoproperty(visible)
If blnvisible =True Then
Testobject.click
Environment.value(result)=pass
‘It will write result to html page
Call html (“test step is success”,Environment(result))
Else
Environment.value(result)=fail
Call html (“test step is fail”,Environment(result))
End If
Else
Environment.value(result)=fail
Call html (“test object is not visible fail”,Environment(result))
End If
End Function
Function WebButton_check(strbrowser,strpage,strWebButton)
Testobject=Browser(strbrowser).Page(strpage).WebButton(strWebButton)
If Testobject.exist(10) Then
blnvisible= testobject.getRoproperty(visible)
If blnvisible =True Then
Testobject.click
Environment.value(result)=pass
‘It will write result to html page
Call html (“test step is success”,Environment(result))
Else
Environment.value(result)=fail
Call html (“test step is fail”,Environment(result))
End If
Else
Environment.value(result)=fail
Call html (“test object is not visible fail”,Environment(result))
End If
End Function
Environment.value(result)=fail
Call html (“test step is fail”,Environment(result))
Function (strverify,Result)
If Environment(result)=pass Then
Td.write(<td(strverify)/>td<xxx><td(Result)/>td)
(please note this is sample, which I typed, it’s just for concept)
Else
Td.write(<td(strverify)/>td<xxx><td(Result)/>td)
End If
End Function
If possible please mail (visitjaga@gmail.com) me the solution as in my office I’ve limited access to outside website. I’ll not be able to check immediately. I’ve been strucked with this issue for pass 20 days.
Thanks& Regard’s
Jagadeesh Mani
visitjaga@gmail.com
RE: vb script to stop execution of functions if conditions fail - ravi.gajul - 12-05-2013
your approach should be like the code written below for your reference.
Code: Dim globalErrHanlder
OnErrorGoTo "errHandler"
'Execute the Error wrapper function
Call CodeToBeExecutedWithErrorHanlder()
Function CodeToBeExecutedWithErrorHanlder()
On Error Resume Next
Call TestErrorHandler()
If Err.Number <> 0 Then
Call globalErrHanlder(Err.description)
End If
End Function
Public Function OnErrorGoTo(byVal FunctionName)
Set globalErrHanlder = GetRef(FunctionName)
End Function
Public Function errHandler(des)
msgbox "Fail" &"Error Occured" &des
End Function
Function TestErrorHandler()
x=1/0
msgbox x
End Function
This means each function should be called from "CodeToBeExecutedWithErrorHanlder" function. When error occurs in the called function it returns back to the calling function and in calling function because we have on error resume next...it proceeds to the next step where error number is checked and based on the error number you can decide whether or not to continue with the remainder of the test execution.
This should help you.
|