Page 1 of 1

Validation Exception

Posted: Fri Mar 27, 2015 2:44 pm
by CookieMonster
Hi,

May someone can help me out, I have small "cosmetic" problem.

My problem is when Validation.Attribute is called, even if it fails it will enter a report log. But I want only that code line in the exception is called, when it fails!
That means, if the validation passes, then it should write the message which I pass, and if it throws an exception, only the Report.Log should be called.

I hope I was somehow clear, if not please let me know.

Thanks in advance for your help

Cheers
Dan

Ranorex 5.3.0 / Win 7 / IE 11
public string GetAndValidateText(RepoItemInfo repoInfo, string attributeValue, string expectedValue)
{
	string elementValue = string.Empty;
	
	try
	{
		repoInfo.WaitForExists(new Duration(AutomationLayerConstants.thirtySecDuration));
				
		var element = repoInfo.CreateAdapter<Unknown>(true);
		if(base.ValidateElementAttributeNoReport(repoInfo, "Visible", true))
		{
			if(element.Element.FlavorName.Equals("web") && element.Element.PreferredCapability.ShortName.Equals("select"))
			{
				WebElement webElement = element.Element;
				GetOptionTagAttributeValue(repoInfo, webElement, attributeValue, expectedValue, false);
			}
			else
			{
				elementValue = element.Element.GetAttributeValueText(attributeValue);
				Validate.Attribute(repoInfo, attributeValue, expectedValue, "The expected value {3} from item " + repoInfo.Name + " of type: " + element.Element.PreferredCapability.DisplayName + " on attribute {1} could be validated");
			}
		}
				
	}
	catch(ValidationException)
	{
		Report.Log(ReportLevel.Failure, string.Format("The expected value {0}, doesn't match with value {1} found on the validated element", expectedValue, elementValue));
	}
		
	return elementValue;
}

Re: Validation Exception

Posted: Fri Mar 27, 2015 3:03 pm
by krstcs
Validate will always print to the report.

If you don't want that, then you should use an equality operation instead of the Validate object.

Re: Validation Exception

Posted: Fri Mar 27, 2015 3:29 pm
by CookieMonster
Hi,

I found a solution and this does exactly what I wanted to do. It only writes a log when it passed otherwise the exception Report will be called, so no equality equation is needed :) . Just add and pass Validate.Options when you call the function Validate.Attribute.

Just change code line from:
Validate.Attribute(repoInfo, attributeValue, expectedValue, "The expected value {3} from item " + repoInfo.Name + " of type: " + element.Element.PreferredCapability.DisplayName + " on attribute {1} could be validated");
To (the magic stuff is at the end):
Validate.Attribute(repoInfo, attributeValue, expectedValue, "The expected value {3} from item " + repoInfo.Name + " of type: " + element.Element.PreferredCapability.DisplayName + " on attribute {1} could be validated", new Validate.Options(true, ReportLevel.Parse("Custom;1")));

Dan

Re: Validation Exception

Posted: Fri Mar 27, 2015 3:30 pm
by krstcs
Ah, yeah, I always forget about the validation options. Nice!