How to run further steps, based on previous image validation

Ranorex Studio, Spy, Recorder, and Driver.
jpinto
Posts: 5
Joined: Wed Apr 26, 2017 8:01 am

How to run further steps, based on previous image validation

Post by jpinto » Fri May 19, 2017 10:26 am

Hello everyone,

I'm quite new to Ranorex.
Within a test case I would like to run further steps, but depending on previous image validation.
Being more specific: if the validation fails or passes the further step will be different.
Something like this:
(pseudo-code)

Code: Select all

if (validation = success) then
Do step 2 
else
Ignore step 2
I suspect that's only possible using User Code modules. But how can I evaluate the result of a previous Validation?

Could some share some small examples?
It would be appreciated.

Thanks.

zivshapirawork
Posts: 65
Joined: Wed Sep 24, 2014 7:47 am
Location: Israel

Re: How to run further steps, based on previous image validation

Post by zivshapirawork » Mon May 22, 2017 5:22 am

Hi jpinto

You can populate a variable of the recording (e.g. true, false), according to the validation, and then use its value in consecutive steps, to asses whether to perform them or not.

jpinto
Posts: 5
Joined: Wed Apr 26, 2017 8:01 am

Re: How to run further steps, based on previous image validation

Post by jpinto » Mon May 22, 2017 8:02 am

zivshapirawork wrote:Hi jpinto

You can populate a variable of the recording (e.g. true, false), according to the validation, and then use its value in consecutive steps, to asses whether to perform them or not.
Hi zivshapirawork,

first thank you for your answer.

Could you be a bit more specific?
Small example would be of great help... :)

Thanks again!

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: How to run further steps, based on previous image validation

Post by Support Team » Fri May 26, 2017 1:21 pm

Hello jpinto,

Here is a simple example how to use the validation feature in user code. I would recommend taking a look at ouronline API documentation to get a collection of all public API calls.
var doesContain = Validate.ContainsImage(buttonInfo, RanorexStudio_Screenshot1, RanorexStudio_Screenshot1_Options, "Your message", false);

if(doesContain)
{
	Report.Info("The image is available");
}
else
{
	Report.Info("The image is not available");
}
I hope this information helps.

Sincerely,
Bernhard

zivshapirawork
Posts: 65
Joined: Wed Sep 24, 2014 7:47 am
Location: Israel

Re: How to run further steps, based on previous image validation

Post by zivshapirawork » Tue May 30, 2017 6:17 am

hi jpinto

in the validation recording, add a variable (variables button) and populate it in the step of the validation (populate it wit the result: true or false). example

Code: Select all

try 
{
 Ranorex.Validate(...) [or similar]
 myRecording.var_result=Boolean.TrueString
}
catch (exception e)
{
 myRecording.var_result=Boolean.FalseString
}

In the next user code steps, check the value of the variable and act accordingly

Code: Select all

If (myRecording.var_result.eqauls(Boolean.FalseString))
{
//do something
}

jpinto
Posts: 5
Joined: Wed Apr 26, 2017 8:01 am

Re: How to run further steps, based on previous image validation

Post by jpinto » Thu Jun 01, 2017 8:17 am

Thank you both for your answers.

@zivshapirawork:
But that means that after the step with a variable for validation, we can only use User Code steps, right? Otherwise they will always be executed, no matter if our variable is true or false... Am I seeing this correctly?

Vaughan.Douglas
Posts: 254
Joined: Tue Mar 24, 2015 5:05 pm
Location: Des Moines, Iowa, USA

Re: How to run further steps, based on previous image validation

Post by Vaughan.Douglas » Thu Jun 01, 2017 12:11 pm

jpinto wrote:Thank you both for your answers.

@zivshapirawork:
But that means that after the step with a variable for validation, we can only use User Code steps, right? Otherwise they will always be executed, no matter if our variable is true or false... Am I seeing this correctly?
Based on this approach you are correct. You can get a bit more fancy and either check or uncheck subsequent Test Cases/Smart folders based on your result.

Note: the code in those examples may not be compatible with Ranorex 7.x, you will probably have to make adjustments.
Doug Vaughan