Is it possible to stop the vb script(in QTP) when it fails? - vbscript

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
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
webEdit_check
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
webEdit_check
Function webEdit_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
WebButton_check
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
(strverify,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

May be try this
On Error Resume Next
Call Link_check (strbrowser,strpage,strlink)
Err.Raise 6 ' Raise an overflow error.
MsgBox "Error # " & CStr(Err.Number) & " " & Err.Description
Err.Clear ' Clear the error.
In the above if the Function Link_check results in an error then, the execution will not move forward.If you want to execute next function use
On Error Resume Next
Call Link_check (strbrowser,strpage,strlink)
Err.Raise 6 ' Raise an overflow error.
MsgBox "Error # " & CStr(Err.Number) & " " & Err.Description
Err.Clear ' Clear the error.
On Error goto 0
WebButton_check
I hope this is what you have asked for.

To make my question more simple, i've 15 scenario's and for each scenario below function will be executed every time
Call WebEdit_check (“google”,”google”,”nametxtbox”,”xxxx”)
Call Link_check (strbrowser,strpage,strlink)
Call WebButton_check (strbrowser,strpage,strWebbutton)
so if when executing 3 rd scenario, Below step function fails
Call Link_check (strbrowser,strpage,strlink)
It will write fail in html result file and 3 rd scenario execution should be stopped and exceution of 4 th scenario should begin. This Err.Raise 6 will raise a user predefined error msg

for cnt i=0 to 15
Call WebEdit_check (“google”,”google”,”nametxtbox”,”xxxx”)
Error Resume Next
Call Link_check (strbrowser,strpage,strlink)'If the Error Occurs here then add On Error Resume Next above this statement
Call WebButton_check (strbrowser,strpage,strWebbutton)
Err.Clear 'This will clear the error.As,you want to keep this process to run for 15 times for each scenario.just add On Error goto 0
add On Error goto 0
Next
This might help

Related

VB6 Update Error Sheridan Grid

I'm making some changes to a program that was written by another developer, which uses an SSDB Grid.
I'm writing the code for the BeforeUpdate method.
On Error GoTo BeforeUpdate_Err
Dim ans%
ans% = MsgBox("These changes will be committed to the database. These changes cannot be undone. " & _
"Would you like to continue?", vbYesNo, "Confirm Changes")
If ans% = 7 Then
Grd_Collection.CancelUpdate
End If
Exit Sub
BeforeUpdate_Err:
MsgBox (Err.Description)
The only other code for the grid is the InitColumnProps method.
However, after hitting the Exit Sub line, I get an error message "Update Error".
I've searched the code for this being hard-coded but it isn't, so it's coming from the grid.
What is causing the error and how do I fix it?
Doesn't the BeforeUpdate method pass in an integer? (Cancel As Integer) or something?
Therefore, you should just be able to change your code (and tidy it up) to this:
On Error GoTo BeforeUpdate_Err
If MsgBox("These changes will be committed to the database. These changes cannot be undone. " & _
"Would you like to continue?", vbYesNo, "Confirm Changes") = vbNo Then
Cancel = 1
End If
Exit Sub
BeforeUpdate_Err:
MsgBox (Err.Description)

How to wait for object and page load

I wrote this function which is being called after clicking any links or buttons.
Function BrowerSync
If Browser("micclass:=Browser").Page("micclass:=Page").Exist(60) then
BrowerSync = 1
End if
End Function
It works fine most of the cases. However, I am experiencing two issues:
If the browser is already loaded before UFT calls the function, I have seen that UFT is still waiting for the page to be loaded. Instead, it should not wait and move on to the next step.
If UFT calls the function but the browser is not opened, UFT still waits for the browser to open and load. Instead it should not wait and move on to the next step.
How can I edit my function to fix the above two issues?
Your code is not dynamic at all. Also the ideal way to wait is to wait for an element to load in the page (in other word to be visible) that will make sure that the browser loaded successfully. In your case anytime you call the function BrowerSync it waits for to find that object for 60 seconds and then it will exit the function.
I will suggest you that you wait for an element in the page an make it dynamic by using the time as parameter for the method so you can wait sometimes 60 seconds and sometimes 10seconds , based on your browser. Below is my function that i use to wait for a webelement
PageLoad_Performance = 10 'this will be used in DWaitForWebElement Function , set the time in seconds, if time less than time added,element found and pages loaded
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'Function Name: WaitForWebElement
'Description: Its a dynamic Conditional Wait, It will wait for
' Webelement until It Exists
'Arguments: classVal - The class property Value of the Object
' innertextVal - The innertext Value of the object
'Created By:
'Date: 10/25/2016
'Usage: Call WaitForWebElement (classVal,innertextVal)
Function WaitForWebElement(classVal,innertextVal)
Dim Total_Time,oDesc
Total_Time=1
'create description of the object
Set oDesc = Description.Create
oDesc.Add "MicClass","WebElement"
oDesc.Add "class",classVal
oDesc.Add "innertext",innertextVal
With Browser("title:=yourtitleofthepage.*").Page("title:=yourtitleofthepage.*")
'this while loop , it will wait until the object exist , it will never exit the loop unless object is Found
While .WebElement(oDesc).Exist(1) = False
wait 1 ' we loop and check and then wait one second
'every time we loop we increment total time by 1 second , to check at the end to total time to load that page
Total_Time = Total_Time+1
Wend
If Total_Time < PageLoad_Performance Then 'if the page loads in less than 10 seconds Performance Report will Pass
'do your report
Else
'do your report
End If
End With
'clean up
Set oDesc = nothing
End Function

How do I perform print images on screen?

I am completely new to VB6, and I need to print images on a page. I am having print options in 2 different places on the same page.
What I have tried:
I tried to write a common method to perform the print operation:
Private Sub mnuPrintImage_Click()
On Error GoTo mnuPrintImage_Click_Error
gobjRLItemImage.PrintImage imgItem
Exit Sub
mnuPrintImage_Click_Error:
ShowError "frmItem.mnuPrintImage_Click"
End Sub
I tried to use Me.PrintForm, but when I do so, I am getting a popup to save the complete page. However, I need to print the image directly and don't want to save it locally.
Public Sub PrintImage()
On Error GoTo PrintImageError
me.printform
Exit Sub
PrintImageError:
Select Case Err.Number
Case 440:
' Cancel button pressed; do nothing
Case Else
Err.Raise Err.Number
End Select
End Sub

Wrong number of arguments or invalid property assignment error in hp UFT

Set ParentObject=Browser("Title:=Sign-In").Page("Title:=Sign-In Home Page")
PropertyRequired="name"
PropertyValue="Agree and Login"
Result="yes"
Function WebButton(ParentObject,PropertyRequired,PropertyValue,Result)
Call ReportResult(Result)
Dim hit
hit=0
If PropertyRequired="" then
PropertyRequired="name"
End If
If ParentObject.WebButton(PropertyRequired &":="&PropertyValue).exist then
ParentObject.WebButton(PropertyRequired &":="&PropertyValue).click
hit=1
End if
If hit>0 then
Reporter.reportevent micpass,"The button: "&PropertyValue,"Clicked sucessfully"
else
Reporter.reportevent micpass,"The button: "&PropertyValue,"not Clicked sucessfully"
End if
End Function
After I Call this function, then an error " Wrong number of arguments or invalid property assignments" displayed.
Call WebButton(ParentObject,PropertyRequired,PropertyValue,Result)
I just executed your piece of code .I dont find any issues .
Try using parenthesis when calling Reporter.reportevent so it's like this:
Reporter.reportevent (micpass, "The button: " & PropertyValue, "Clicked sucessfully")

QTP Link object does not support the Exist property

I have a weird problem with QTP 11. The following piece of code worked so far, but suddenly stopped working and throws Object does not support this property or method.: 'objPage.Link' for the line with 'if link exist'
Set objBrowser = Browser("creationtime:=" & Desktop.ChildObjects(oDesc).Count - 1 & "")
Set objPage = objBrowser.Page("title:=.*")
If objPage.Link("class:=menu_link_tab_.*", "html id:=.*DesktopTab").Exist(3) Then
msgbox "ok"
End If
Can anyone tell me what is wrong and/or how to do it right?
EDIT: I solved this but still have no idea what happened. I just cut this part from QTP script and pasted it into Notepad and then copied it from Notepad to QTP. Everything works fine. I did not change anything... Any ideas what the hell happened are welcomed.
ANOTHER EDIT: The problem reappears randomly. With no changes to anything I can just run the test 10 times to have it fail randomly with the 'Object does not support this property or method' message
I have a startBrowser function where I set the objPage and objBrowser :
Function startBrowser(vURL)
Dim oDesc
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate vURL
Window("hwnd:=" & IE.HWND).Maximize
Set oDesc = Description.Create
oDesc( "micclass" ).Value = "Browser"
If Desktop.ChildObjects(oDesc).Count > 0 Then
Set objBrowser = Browser("creationtime:=" & Desktop.ChildObjects(oDesc).Count - 1 & "")
End If
Set objPage = objBrowser.Page("title:=.*")
End Function
I have added lots of msgboxes with GetROProperty to verify whether the objects are ok. They seem to be.
Now my function to click the link looks like this :
Function clickMainMenuLink(vIdentifier)
Set objLink = objPage.Link("class:=menu_link_tab_.*", "html id:=.*" & vIdentifier, "index:=0")
If objLink.Exist(timeOut) Then
objLink.Click
Else
reporter.ReportEvent micFail, "Click the " & vIdentifier & " menu link", "Cannot find the " & vIdentifier & " menu link"
ExitTestIteration
End If
End Function
So at the moment my test just opens the browser and clicks a link as I try to debug the thing, but it still fails or passes randomly. The run error indicates line with 'Set objLink'. Any ideas for further debugging? I'm on QTP11 and IE8 if it matters.
From your error does not support this property or method: objPage.Link it would appear that the problem isn't with the .Exist part of line but the .Link part (you can verify this by separating the line into two lines and see which fails
set objLink = objPage.Link("class:=menu_link_tab_.*", "html id:=.*DesktopTab")
If objLink.Exist(3) Then
From your comment it seems that you're creating objPage in a different location from where you're using it, I suggest making sure that the object arrives OK.
Thanks Motti, your reasoning was right. The problem was with the objPage part. Despite the fact that I could read every property of objPage in a function QTP sometimes just did not see this objPage as a Page object. I guess it has something to do with not declaring type explicitly, but that's just a guess. As a dirty workaround I set up the objBrowser and objPage in every function now and it works 100%.

Resources