Page 1 of 1

How to Use ErrorBehaviour in code module?

Posted: Tue Aug 07, 2018 8:33 pm
by kumprave5
Hello,

Please look at the screenshot, I want if TC01 fail then continue with TC02 or it siblings using code. How do I do that?
Namespace Workshop.Web
{
	[TestModule("F1A7D951-2CFE-4D8B-A568-037DBE1CCC99", ModuleType.UserCode, 1)]
	public class TestCaseRunner : ITestModule
	{
		public TestCaseRunner()
		{	}
		void ITestModule.Run()
		{
			var  iTM =TestReport.CurrentTestModuleActivity;
			try
			{
				Report.CurrentReportLevel = ReportLevel.Info;
				TestReport.EnableTracingScreenshots =false;
                                //some code goes here
			}
			catch(Exception e)
			{
				LogUtility._failure(e.Message);
			}
			
			finally
			{ 
				if(iTM.Status== ActivityStatus.Failed)
				{
						var beh = ErrorBehavior.ContinueParent;    [quote]//I believe some problem is in this line.[/quote]  [/b]                                                      LogUtility._info(beh.ToString());
				}
			
		}
	}}
Edit by Support Team: Use code tag for better readability

Re: How to Use ErrorBehaviour in code module?

Posted: Thu Aug 09, 2018 4:44 am
by Support Team
Hi kumprave5,

Thank you for reaching out to us in regards to your error behavior question.

Are you using the Test Suite in any shape or form? From the info you have provided it would appear so, I just want to be able to give you the best possible solution for your scenario. The error behavior you are seeking is actually the default error behavior for the test suite:
  • 1.png
  • 2.png
If you would like to learn more about the Test Suite error behavior, please visit the following link: https://www.ranorex.com/help/latest/ran ... orbehavior

So long story short if you are using the Ranorex Test Suite, then all error behavior can me adjusted there and not within the module itself. If this will not work in your scenario or is not what you are looking for then please let me know as I would be happy to provide an alternate suggestion.

I hope this helps!

Regards,

Jon

Re: How to Use ErrorBehaviour in code module?

Posted: Thu Aug 09, 2018 1:08 pm
by kumprave5
No, I don't want to use ranorex test suite, I need to write the code to handle the Errorbehaviour .

I am not able to find any API Documentation on how to use ErrorBehavior.ContinueParent in code module?
var beh = ErrorBehavior.ContinueParent; class="text-strong">
LogUtility._info(beh.ToString());

Re: How to Use ErrorBehaviour in code module?

Posted: Mon Aug 13, 2018 3:19 am
by Support Team
Hi kumprave5,

Thank you for the reply.

Currently, there is no officially documented API for managing error behavior at runtime. The below snippet should get you going but please know that undocumented API is unsupported and should be used with caution. The below snippet is a very simple example of how you can adjust error behavior at runtime as a work around.
      
using System.Linq;
 
 public void setEB()
        {
            var TS = (TestSuite) TestSuite.Current;
            IList<TestSuiteEntry> entryList = TS.GetAllTestSuiteEntries();
            TestSuiteEntry entry = entryList.Single(s => s.Name == "myTestCase"); //Specify your test container

            var node = (TestCaseNode)entry;
            
            //Report Error behavior
            Report.Info("Entry Name: "+ entry.Name + " | Error Behavior: " +node.ErrorBehavior.ToString());
            
            //Change Errory Behavior
            Report.Info("Changing Error Behavior");
             node.ErrorBehavior = Ranorex.Core.Testing.ErrorBehavior.ContinueParent;
            
            //Report Error behavior after change
            Report.Info("Entry Name: "+ entry.Name + " | [CHANGED]Error Behavior: " +node.ErrorBehavior.ToString());
        }
The above code will report the current error behavior of the test entry "myTestSuite" (which is a Test Case in my example) and will then change it to ContinueParent or whatever you wish to use.

If having officially documented API to change error behavior is an important feature to you, then I would highly recommend making a post on our User Voice platform. This is a platform where users can submit and vote on features to improvements to Ranorex. User Voice is reviewed by our product management team so it is the best way to get your requests to us. Please find our Ranorex User Voice here.

I hope this helps!

Jon