Poll: Is my question clear ?
You do not have permission to vote in this poll.
Yes
100.00%
2 100.00%
No
0%
0 0%
Total 2 vote(s) 100%
* You voted for this item. [Show Results]

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
vb script to stop execution of functions if conditions fail
#1
Not Solved
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
Reply
#2
Not Solved
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question adding two conditions into a while statement lotos 4 4,789 11-10-2017, 04:49 AM
Last Post: lotos
  UFT 12.02 Compatibility for IE 11.0 : Fail to identify the defined Object Amruta_121 9 10,482 01-11-2016, 12:45 PM
Last Post: vinod123
  Inserting variable values into Descriptive Programming Functions eske99 2 3,140 12-18-2015, 01:47 PM
Last Post: vinod123
  How to catch the script execution when QTP scripts are executed from command line Sreeni.lutukurthy 0 2,685 03-19-2015, 05:55 PM
Last Post: Sreeni.lutukurthy
  Passing objects to Functions vinod.nhce 0 3,205 03-13-2014, 06:09 PM
Last Post: vinod.nhce

Forum Jump:


Users browsing this thread: 1 Guest(s)