Marking a module as Passed when some validation fails

Ranorex Spy, Recorder, and Studio.
AccidentReport
Posts: 76
Joined: Tue Dec 04, 2012 2:30 pm

Marking a module as Passed when some validation fails

Post by AccidentReport » Thu Jan 23, 2014 11:21 am

I am currently working on a module that checks to see if a plan on my application has activated yet (after clicking the activate button in the previous module). The easiest way to do this is to check the plan name at the top of the screen. When inactive it is shown as "Call(INACT - WEBCPE_TEST)" and when active it is shown as "Call(ACTIV - WEBCPE_TEST)". I am therefore doing a validation on this object to check the InnerText.

As you can see in my code below I have got it looping whilst checking if the plan has activated every 5 seconds. More often than not it takes a while to activate so the validation fails the first few times before finally passing. Once passed I then report success.

The issue is that the module gets marked as failed overall because some of the steps failed (I'm assuming the validation). I have already implemented the suggestion from http://www.ranorex.com/forum/trying-to- ... t3844.html but all that has done is get rid of any red on the report, the test itself is still failed.

The question is, how do I get the module to get marked as passed even though some of the validation has failed?

Code: Select all

public void CheckForActivation(string argument1)
{
	bool planActive = false;
	int waitTimer = 0;
	callPlanName = "WEBCPE_TEST";
	Validate.Options option = new Validate.Options(ReportLevel.Info);
	option.ExceptionOnFail = false;

	while ((planActive == false) && (waitTimer < 60))
	{
		repo.BTInboundArchitect2.Form1.BtnRefresh.Click("63;9");
		Delay.Duration(5000, false);
		waitTimer += 5;
		planActive = Validate.Attribute(repo.BTInboundArchitect2.Form1.INVALID598935Info, "InnerText", "Call(ACTIV - " + callPlanName + ")", "Attempting to validate is callplan '" + callPlanName + "' is active.", option);
	}

	if (planActive == true)
	{
		Report.Log(ReportLevel.Success, "Validation", "Validating AttributeEqual (InnerText='Call(ACTIV - WEBCPE_TEST)') on item 'BTInboundArchitect2.Form1.INVALID598935'.", repo.BTInboundArchitect2.Form1.INVALID598935Info);
	} else {
		Report.Log(ReportLevel.Failure, "Module", "Callplan  '" + callPlanName +"' has failed to activate after 60 seconds.");
	}

}


Swisside
Posts: 92
Joined: Thu Oct 10, 2013 10:40 am

Re: Marking a module as Passed when some validation fails

Post by Swisside » Thu Jan 23, 2014 11:48 am

Hello !

Instead of ReportLevel.Failure you could use ReportLevel.Warning which would show the yellow sign but won't fail the module.


Not sure this is what you want tho.


Cheers


Swiss'
A simple thank you always does wonders !

AccidentReport
Posts: 76
Joined: Tue Dec 04, 2012 2:30 pm

Re: Marking a module as Passed when some validation fails

Post by AccidentReport » Thu Jan 23, 2014 11:56 am

If you are referring to the ReportLevel.Failure in the final "if" statement then it doesn't matter. That "if" statement simply determines if the pla activated or not and reports a ReportLevel.Success if it did and a ReportLevel.Failure if it didn't. The problem is that when it reports the ReportLevel.Success the overall test module is still being marked as failed because some of the validation failed.

AccidentReport
Posts: 76
Joined: Tue Dec 04, 2012 2:30 pm

Re: Marking a module as Passed when some validation fails

Post by AccidentReport » Thu Jan 23, 2014 1:39 pm

OK, I've managed to work out a solution. Not what I would have liked to do but it works so I thought I'd share. Basically I put it in a try catch and then manually threw an exception to force it to catch. Code below:

Code: Select all

        public void CheckForActivation(string argument1)
        {
        	bool planActive = false;
        	int waitTimer = 0;
        	Validate.Options option = new Validate.Options(ReportLevel.Info);
			option.ExceptionOnFail = false;
        	
			try {

				while ((planActive == false) && (waitTimer < 60))
	        	{
	        		repo.BTInboundArchitect2.Form1.BtnRefresh.Click("63;9");
	        		Delay.Duration(5000, false);
	        		waitTimer += 5;
	        		planActive = Validate.Attribute(repo.BTInboundArchitect2.Form1.INVALID598935Info, "InnerText", "Call(ACTIV - " + callPlanName + ")", "Attempting to validate is callplan '" + callPlanName + "' is active.", option);
	        	} 
				if (planActive != true) {throw new Ranorex.ValidationException("");}
				
			} catch (Exception) {

				Report.Log(ReportLevel.Failure, "Module", "Callplan  '" + callPlanName +"' has failed to activate after 60 seconds.");

			}
						
			if (planActive == true) {
				Report.Log(ReportLevel.Success, "Validation", "Validating AttributeEqual (InnerText='Call(ACTIV - WEBCPE_TEST)') on item 'BTInboundArchitect2.Form1.INVALID598935'.", repo.BTInboundArchitect2.Form1.INVALID598935Info);
			}
            
        }

User avatar
rprehm
Posts: 24
Joined: Tue Dec 17, 2013 6:43 pm

Re: Marking a module as Passed when some validation fails

Post by rprehm » Fri Jan 24, 2014 4:41 pm

Hi AccidentReport,

If I understand your problem correctly you are waiting for the activation of your plan? If the plan shows up within 60sec’s the test run should fail otherwise succeed? Hopefully I understood your problem correctly.

I would suggest that you use Validate.Exists:

Code: Select all

Validate.Exists(repo.BTInboundArchitect2.Form1.INVALID598935);
Modify the RxPath of your repository item by adding the attribute “inner text”:

Code: Select all

/form[@caption='Form1']//however/your/tree/structure/looks/like[@innertext='Call(ACTIV - WEBCPE_TEST)']
So the validation will just pass if “Form1” gets the “inner text” Call(ACTIV - WEBCPE_TEST).
The search time can be defined via setting the search timeout of the repository element.

Regards,
Robert