How to do a Validation based on a Local Variable in Code

Ask general questions here.
nas
Posts: 5
Joined: Wed Mar 08, 2017 7:01 pm

How to do a Validation based on a Local Variable in Code

Post by nas » Wed May 17, 2017 3:38 pm

How do I do a validation action based on a variable I created in the UserCode.cs section. For example,

I want to see if my local int variable is greater than 0, and if it is then pass the step. Else, fail it.

if (int myDefinedVar) > 0
Pass
Else
Fail

User avatar
Stub
Posts: 173
Joined: Fri Jul 15, 2016 1:35 pm

Re: How to do a Validation based on a Local Variable in Code

Post by Stub » Thu May 18, 2017 8:21 am

Use the Validate API for that. You have IsTrue, IsFalse, AreEqual and more to play with. You can have them fail your test. Lots of options. Very useful.

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

Re: How to do a Validation based on a Local Variable in Code

Post by odklizec » Thu May 18, 2017 8:32 am

Hi,

In case you are not sure about exact usage of a certain Ranorex action in code (in this case Validation), examine the code behind a recorded/manually added action. Simply add an action to recording module an then examine its code via context menu >> "View Code" (or Ctrl+Enter shortcut).
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