Create Custom Validation Attribute instead of AttributeEqual

Mobile Testing, Android App Testing.
vikram_u_k
Posts: 15
Joined: Tue Mar 15, 2016 12:16 pm

Create Custom Validation Attribute instead of AttributeEqual

Post by vikram_u_k » Mon Mar 28, 2016 7:35 am

Hi Support,
We would need a method to validate the actual/expected values to be within a range/offset. The code for this is attached. Could you guide us on how to create this a Custom Validate Actions' Method?.

The expectation is that a Validation would be compared for 2 Values(actual, expected) to be within a bound(+/- Offset).

public bool testEqual(int expected, int actual, int offset)
{
if (Math.Abs(actual - expected)< offset)
{
Console.WriteLine("value is within Bounds");
return true;
}
else
{
Console.WriteLine("value is out of Bounds");
return false;
}

}

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Create Custom Validation Attribute instead of AttributeEqual

Post by odklizec » Mon Mar 28, 2016 9:00 am

Hi,

I'm not quite sure what exactly you want to achieve? The method you posted is basically all you need to use it as a custom validation method. In recording module, add new User Code action and simply add the content of your method to just created User Code action. To record success or failure in report, use Report.Success or Report.Failure methods (described here). To make the test to fail (in case of failed comparison) you can use Validate.Fail(string) method instead of Report.Failure. Hope this helps?
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

vikram_u_k
Posts: 15
Joined: Tue Mar 15, 2016 12:16 pm

Re: Create Custom Validation Attribute instead of AttributeEqual

Post by vikram_u_k » Wed Mar 30, 2016 6:57 am

Thank you Support.
The information helps. what was not clear was the ability to Pick additional attributes for the Object from the repository