Page 1 of 1

how to get true or false from validation

Posted: Thu Jul 31, 2014 12:38 pm
by rholdberh
Hi,
i want to make such validation in my test, but i cant find how to get true or flase from Validate.Attribute

if(text=="test" && Validate.Attribute(repo.smth.smthInfo, "Checked","True"); ){
than bla bla bla
}

but i am getting syntax errors, cant convert void to bool

Do you know how to solve my problem?

Regards

Re: how to get true or false from validation

Posted: Thu Jul 31, 2014 1:15 pm
by rholdberh
i have tried in such way

if(textSearchable=="y" && Validate.Attribute(repo.smthInfo, "Checked","True","",true)==true){
Report.Log(ReportLevel.Info, "Yes");
}
else {
Report.Log(ReportLevel.Info, "No");
}

but in first validation if validate.Attribute statement returns false my test fails on
at Ranorex.Validate.IsTrueInternal(Boolean condition, String message, Options options, RepoItemInfo itemInfo) at Ranorex.Validate.AttributeInternal(Element element, String name, Object value, String message, Options options, RepoItemInfo itemInfo) at Ranorex.Validate.Attribute(RepoItemInfo itemInfo, String name, Object value, String message, Options options) at Ranorex.Validate.Attribute(RepoItemInfo itemInfo, String name, Object value, String message, Boolean exceptionOnFail) at

Re: how to get true or false from validation

Posted: Thu Jul 31, 2014 2:45 pm
by Bat
Validate.Attribute() returns void (Which you found out). I'm pretty sure if the validation fails on the object it'll break the current case and report it on the log.

Instead of using validation use something like

Code: Select all

if(textSearchable=="y" && repo.smth.Checked==TRUE){
//do this
}
else {
//this
}

Re: how to get true or false from validation

Posted: Fri Aug 01, 2014 8:16 am
by rholdberh
you are right if validation fails it is breaking my test. So my solution was to use this:

Code: Select all

Validate.Options option = new Validate.Options(ReportLevel.Info);
option.ExceptionOnFail=false;
if(textSearchable=="y" && Validate.Attribute(repo.smthInfo, "Checked","True","",option)){
				do smth
}
now if it fails it is just reporting on Info level

Re: how to get true or false from validation

Posted: Mon Aug 04, 2014 1:54 pm
by krstcs
The Validation object should ONLY be used for validating something, not for logical comparison. It is not designed for that and could cause unwanted side-effects.

You should use the method outlined by Bat instead.