Current Iteration is still continuing even a step is failed

Ask general questions here.
vivek.guvva
Posts: 31
Joined: Mon Feb 22, 2016 7:21 pm

Current Iteration is still continuing even a step is failed

Post by vivek.guvva » Thu Mar 10, 2016 10:42 pm

Hi, I am doing data driven testing with multiple iterations. I have set Error behaviour as "Continue with iteration". When one of the step is failed, it is still trying to execute the next steps in the same iteration instead of stopping the iteration and proceeding with next iteration. It was working earlier but today it is not working. Please let me know if there will be any difference when the error is captured in Catch portion of Try-Catch block.

Thanks
Vivek

log
Certified Professional
Certified Professional
Posts: 14
Joined: Tue Mar 24, 2015 6:28 am
Location: Sydney, Australia

Re: Current Iteration is still continuing even a step is failed

Post by log » Fri Mar 11, 2016 12:21 am

Hi Vivek,

In the recording module, it sounds you have enabled Continue On Fail for the step that fails. Is the text of the action in italics and is the sequence number is surrounded in [] brackets? The effect is that the subsequent actions in the recording will proceed even if that action fails.

Disable Continue On Fail for that action by right-clicking on the action and selecting "Disable Continue On Fail" in the context menu. That will remove the Try-Catch block around that action in the generated code.

With Continue On Fail disabled, the subsequent actions for the recording module will not be executed when the action fails, and execution will proceed immediately to the next iteration if you use the "Continue with iteration" error behaviour.

http://www.ranorex.com/support/user-gui ... tions.html says:
Set an action item to 'Continue On Fail' if, in cases of an error, module execution should not stop at that position.

Hope that helps,
Gabriel

vivek.guvva
Posts: 31
Joined: Mon Feb 22, 2016 7:21 pm

Re: Current Iteration is still continuing even a step is failed

Post by vivek.guvva » Fri Mar 11, 2016 3:59 am

Thanks Gabriel for the reply. I never enabled "Continue on Fail" (I have checked now as well, that options is disabled) but still the iteration is not stopping after failure. It worked 3 days before but now it is not working. I am not able to figure out what the issue is.

log
Certified Professional
Certified Professional
Posts: 14
Joined: Tue Mar 24, 2015 6:28 am
Location: Sydney, Australia

Re: Current Iteration is still continuing even a step is failed

Post by log » Fri Mar 11, 2016 4:03 am

Hi Vivek,

Would you be able to share a copy of your Ranorex solution?

Thanks,
Gabriel

vivek.guvva
Posts: 31
Joined: Mon Feb 22, 2016 7:21 pm

Re: Current Iteration is still continuing even a step is failed

Post by vivek.guvva » Fri Mar 11, 2016 4:43 am

Hi Gabriel,

I don't think, I will be able to share the solution. I am able to see "Enable Continue on Fail" for all the steps in recording which means that "Continue On Fail" is displayed and I have selected "Continue with Iteration" on error in the "General" tab of Data Connector. I am not sure what else might be the problem. I have created my own functions/subs in VB and using those subs as steps in recording module for the project. Any help is appreciated.

Thanks and Regards
Vivek.

log
Certified Professional
Certified Professional
Posts: 14
Joined: Tue Mar 24, 2015 6:28 am
Location: Sydney, Australia

Re: Current Iteration is still continuing even a step is failed

Post by log » Fri Mar 11, 2016 5:57 am

Hi Vivek,

Okay, that's fine, I'll still try to help you without seeing the Ranorex solution.

In the functions/subs that you have created in VB, have you used the overload of any of the methods in the Validate class where the last argument is a Boolean and you've passed it a False value?

For example, http://www.ranorex.com/Documentation/Ra ... qual_3.htm.

The effect of using False for the exceptionOnFail parameter is that only a failure message will be added to the log when the validation fails, and execution will still proceed to the next step instead of stopping execution.

You also mention in your original post that you're catching the error in the Catch portion. Is that in your VB function/sub? It could be that you are swallowing the exception and not re-throwing it. An exception that is thrown when a Validate method fails will only stop execution if it isn't swallowed.

This might work for you:

Code: Select all

Try
  ' your code here which can throw an exception
Catch ex as Exception
  ' your code here to do custom handling of the exception

  ' Re-throw the exception so test execution stops here
  Throw
End Try
However, there should be a better way to structure your code than using Try-Catch.

Gabriel

vivek.guvva
Posts: 31
Joined: Mon Feb 22, 2016 7:21 pm

Re: Current Iteration is still continuing even a step is failed

Post by vivek.guvva » Fri Mar 11, 2016 1:08 pm

Public Shared Sub Search(SearchName as string)
Try

If repo.object1Info.Exists Then
repo.objSearchName = SearchName
repo.object.PressKeys("=" & objSearchName)

If repo.objectInfo.Exists Then
repo.object.Click
Report.Log(reportlevel.Success, "SearchOptionsSelection", "Success | Search value selected successfully")
Else
Report.log(reportlevel.Failure, "SearchOptionsSelection", "Failure | Search value is not displayed in search list")
Logout application
End If

Else
Report.Log(reportlevel.Failure, "SearchOptionsSelection", "Failure | Search text box is not displayed search screen")
Logout application
End If

Catch e As Exception
Report.Log(reportlevel.Failure, "SearchOptionsSelection", "Failure | Search text box is not displayed search screen")
Logout application
End Try

End Sub


Here is my code, Gabriel. The problem is even that the iteration is not stopping even if condition in Try block is failing and not going to Catch block at all. Please let me know if there is any better way to write code.

log
Certified Professional
Certified Professional
Posts: 14
Joined: Tue Mar 24, 2015 6:28 am
Location: Sydney, Australia

Re: Current Iteration is still continuing even a step is failed

Post by log » Mon Mar 14, 2016 12:27 am

Hi Vivek,

Have you stepped through the code with the debugger to see which path is taken when the condition in the Try block fails? I'm not sure which condition you're referring to, as there are two checks for existence, and the Exists property returns a boolean value.

On the other hand,

Code: Select all

Validate.Exists(repo.object1Info)
would throw an exception and stop the iteration if object1 does not exist.

Where are you expecting the exception to be thrown?

It seems to me that

Code: Select all

repo.object.PressKeys("=" & objSearchName)
should be

Code: Select all

repo.object1.PressKeys("=" & objSearchName)
since you are checking if object1 exists before setting repo.objSearchName and calling PressKeys.

The Report.Log methods do not throw exceptions, but they just add entries to the Ranorex log with the specified ReportLevel.

As for a different way of organizing your code, can you try

Code: Select all

Validate.Exists(repo.object1Info, "Validating search text box is displayed search screen")
repo.objSearchName = SearchName
repo.object1.PressKeys("=" & repo.objSearchName)
				
Validate.Exists(repo.objectInfo, "Validating search value is displayed in search list")
repo.object.Click
And then have a different module in the Teardown section of the test case to handle logout.

Hope that helps,
Gabriel

vivek.guvva
Posts: 31
Joined: Mon Feb 22, 2016 7:21 pm

Re: Current Iteration is still continuing even a step is failed

Post by vivek.guvva » Thu Mar 17, 2016 3:14 am

log wrote:Hi Vivek,

Have you stepped through the code with the debugger to see which path is taken when the condition in the Try block fails? I'm not sure which condition you're referring to, as there are two checks for existence, and the Exists property returns a boolean value.

On the other hand,

Code: Select all

Validate.Exists(repo.object1Info)
would throw an exception and stop the iteration if object1 does not exist.

Where are you expecting the exception to be thrown?

It seems to me that

Code: Select all

repo.object.PressKeys("=" & objSearchName)
should be

Code: Select all

repo.object1.PressKeys("=" & objSearchName)
since you are checking if object1 exists before setting repo.objSearchName and calling PressKeys.

The Report.Log methods do not throw exceptions, but they just add entries to the Ranorex log with the specified ReportLevel.

As for a different way of organizing your code, can you try

Code: Select all

Validate.Exists(repo.object1Info, "Validating search text box is displayed search screen")
repo.objSearchName = SearchName
repo.object1.PressKeys("=" & repo.objSearchName)
				
Validate.Exists(repo.objectInfo, "Validating search value is displayed in search list")
repo.object.Click
And then have a different module in the Teardown section of the test case to handle logout.

Hope that helps,
Gabriel

Hi Gabriel,

When I put Validate.Exists functions, then only it is stopping the current iteration immediately and then proceeding to next iteration. If I use If condition checking the existence of the object without using Validate.Exists function, then current iteration is proceeding even after the step is failed. Please let me know what is the issue with If condition. Execution is taking more time if I use Validate.Exists function. I am really trying very hard with this issue.

Thanks and Regards
Vivek

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3932
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Current Iteration is still continuing even a step is failed

Post by odklizec » Thu Mar 17, 2016 10:19 am

Hi Vivek,

I'm afraid, it's too hard (impossible) to track the source of your problem without seeing your Ranorex solution and at least a simplified sample app you are trying to automate. Plus I believe most of users here are C# guys? );

My guess is that the structure of your solution is wrong, so the "Continue with iteration" behavior you set does not apply to the test case, which actually fails? Either this or there is something wrong with your code. But again, it's impossible to tell what exactly is wrong without the chance to debug your solution up to the point where it fails.

I would suggest test the "Continue with iteration" behavior by a failure initiated in a recording module. Just create a recording module with purposely added failing action. If failure in recording module correctly triggers error behavior, try another (the same) failure initiated from code module placed at the same level as previously used recording module (the one with failure). If error behavior works as expected also this time, try add your code (line by line) until you find the one which does not trigger the error behavior. Hope this helps?
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

lucian.teodorescu
Posts: 82
Joined: Fri Oct 24, 2014 10:58 am
Location: Bucharest

Re: Current Iteration is still continuing even a step is failed

Post by lucian.teodorescu » Thu Mar 17, 2016 11:23 am

Hi guys,

I used this behavior as a feature :P I hope they don't change it. :wink:
Validate.Exists() throws a RanorexException (or RanorexCoreException?) if the item is not found, but Report.Failure() does not. Check more about this here: http://www.ranorex.com/Documentation/Ranorex/ and search by Failure Method.

In "Namespaces ► Ranorex ► Report ► Failure(String)" you can find this remark:
Calling this method marks the current test case as failed, but does not stop execution of the current module or test case. If you want the execution of the current module to stop immediately, call Validate.Fail(String) instead.
So basically in your code, wherever you want the iteration to stop and jump to Teardown, if available, or the next iteration, after you Report.Log(ReportLevel.Failure...) or Report.Failure(...) you should also add 'throw RanorexException'. Or, to be more specific and post a nice and useful message use Validate.Fail(String).

Just give it a try and let us know if the issue still occurs.

EDIT TO ADD: Validate.Exists(itemToFind) takes longer because it is looking for that item using default search time (which is 30s for the first level and adds 30s for each deeper level in the repository structure, when using Rooted Folder instead of Simple Folder). In repository right-click your item > Properties and check 'Effective timeout' to see how long you are looking for it. But for that specific validation you can give a specific timeout, like Validate.Exist(itemToFind, Duration)
Lucian Teodorescu
NetSun Software

log
Certified Professional
Certified Professional
Posts: 14
Joined: Tue Mar 24, 2015 6:28 am
Location: Sydney, Australia

Re: Current Iteration is still continuing even a step is failed

Post by log » Thu Mar 17, 2016 11:49 pm

Hi everyone,

Thanks for the replies, Pavel and Lucian.

Lucian is correct and Report.Failure() and Report.Log() do not throw RanorexExceptions and therefore, do not stop execution at that line. I also use the documented behaviour of the Report.Failure() method in my projects, so I see it as a feature.

With our limited knowledge of your solution, I believe Ranorex is behaving in exactly the way that it should, according to the code that you've written, when you say:
When I put Validate.Exists functions, then only it is stopping the current iteration immediately and then proceeding to next iteration. If I use If condition checking the existence of the object without using Validate.Exists function, then current iteration is proceeding even after the step is failed
With regards to execution taking longer with Validate.Exists compared to If repo.objectInfo.Exists Then, I would have thought that they would take relatively the same amount of time when you use the same repository item, which is determined by the Effective Timeout as Lucian mentioned.

If your objective is to have Validate.Exists execute faster, you can either
a) change the timeouts on the repository item leading to object1 as described by Lucian
b) Use this overload of Validate.Exists
http://www.ranorex.com/Documentation/Ra ... ists_9.htm
and pass it the AbsolutePath of your repository item and the desired wait time.
Example:

Code: Select all

Dim waitTime As Duration
waitTime = new Duration(1000)
Validate.Exists(repo.Computer.Explorer.object1Info.AbsolutePath, waitTime)
where the Effective Timeout of object1 is 1.5m (because Computer, Explorer, and object1 are all 30s), the code above results in this in the log file
Element for path '/form[@title='Computer']/element[@class='WorkerW']/container[@controlid='40965']//container[@class='DirectUIHWND']/text[@automationid='SearchEditBox']' does not exist (No element found for path '/form[@title='Computer']/element[@class='WorkerW']/container[@controlid='40965']//container[@class='DirectUIHWND']/text[@automationid='SearchEditBox']' within 1000ms.).
Note, I don't recommend option B, but I'm just putting it out there.

Hope that helps,
Gabriel

vivek.guvva
Posts: 31
Joined: Mon Feb 22, 2016 7:21 pm

Re: Current Iteration is still continuing even a step is failed

Post by vivek.guvva » Fri Mar 18, 2016 3:50 am

Thank you all for the reply. I don't know whether this is the issue with Ranorex or not but the same code is working fine by stopping the iteration immediately and proceeding to the next iteration. This is happening to me intermittently with the same code. I will implement your solutions when I face the issue again.

Thanks
Vivek