how to get true or false from validation

Technology specific object identification, supported applications, web technologies, and 3rd party controls.
rholdberh
Posts: 27
Joined: Mon Jan 13, 2014 3:45 pm

how to get true or false from validation

Post by rholdberh » Thu Jul 31, 2014 12:38 pm

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

rholdberh
Posts: 27
Joined: Mon Jan 13, 2014 3:45 pm

Re: how to get true or false from validation

Post by rholdberh » Thu Jul 31, 2014 1:15 pm

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

Bat
Posts: 16
Joined: Thu Jul 03, 2014 2:16 pm

Re: how to get true or false from validation

Post by Bat » Thu Jul 31, 2014 2:45 pm

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
}

rholdberh
Posts: 27
Joined: Mon Jan 13, 2014 3:45 pm

Re: how to get true or false from validation

Post by rholdberh » Fri Aug 01, 2014 8:16 am

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

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: how to get true or false from validation

Post by krstcs » Mon Aug 04, 2014 1:54 pm

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.
Shortcuts usually aren't...