Page 1 of 1

Condition execution based on Parameter value

Posted: Mon Sep 18, 2017 4:57 pm
by bk_tester
Hello Ranorex,

In my test I need to handle two types of the dialog which are invoked by double clicking table rows. Table is traced in DDT loop. Based of the appeared dialog type different smart folder should be executed. I used Code Module to identify which type of dialog appears and set appropriate value for the Module variable (DialogType). Than, following smart folders has a condition based on that variable value. For better understanding please have a look at the attached screenshot ConditionalExecution.png
The issue is that DialogType variable looks changed, and SmartFolder condition ignore that value.

So what is the reason why condition is not triggered during test run?

Thanks!

Re: Condition execution based on Parameter value

Posted: Mon Sep 18, 2017 5:14 pm
by Vaughan.Douglas
Could it because you're setting the DialogType to "NewItemDialog" and testing for "NewItemType"?
ConditionalExecution.png

Re: Condition execution based on Parameter value

Posted: Mon Sep 18, 2017 5:25 pm
by bk_tester
It's a mistake in text on the screenshot. Sorry for that.
DialogType variable could have value as "NewItemType" or "RequestSeriesDialog". And condition checks whether DialogType is equal to first or second value.

Thanks

Re: Condition execution based on Parameter value

Posted: Mon Sep 18, 2017 5:41 pm
by Vaughan.Douglas
I figured as much, but you always double check the easy stuff. :lol:

How are you binding your parameter? In the Data Binding column for Define_NewItemType_Dialog I don't see anything about variables being bound. This could be because your text just covers it or you're not using a module variable to bind the parameter.

So I'm guessing you're just setting the parameter from 005_01_Open_and_preview_all_requests directly from code rather than binding the value to a module variable and binding that module variable back to the DialogType parameter back on the rxtst page. I have no idea if this is causing your problem, but that would be the first thing I'd try.

Re: Condition execution based on Parameter value

Posted: Mon Sep 18, 2017 6:21 pm
by bk_tester
I'm setting DialogType parameter in the code in Define_NewItemType_Dialog module, like this:

Code: Select all

TestSuite.CurrentTestContainer.Parameters["DialogType"] = "NewItemType";
This module does not have any data bindings.

It seems that during run time DialogType variable do have required value, because in code i have:

Code: Select all

Report.Info("User code", "Dialog type is: " + TestSuite.CurrentTestContainer.Parameters["DialogType"]);
and in report:
17:49:26 Info User code Dialog type is: NewItemType

Hope this info helps to understand the problem better.

Regards

Re: Condition execution based on Parameter value

Posted: Mon Sep 18, 2017 9:07 pm
by Vaughan.Douglas
It looks like Ranorex doesn't like it when you set the parameter directly. You need to user a module variable and bind that back to the parameter. See the attached solution.
HoldMyBeer.zip

Re: Condition execution based on Parameter value

Posted: Tue Sep 19, 2017 3:24 pm
by bk_tester
Thanks a lot for your idea. It works fine for me. And in the same time my solution uncover a bug or at least possible improvement :)

Re: Condition execution based on Parameter value

Posted: Tue Sep 19, 2017 3:43 pm
by krstcs
I do not think this needs any improvement, and it's definitely not a bug.

The expected and recommend way to handle parameters/variables is to create module variables and bind them to parameters, as Vaughan said. Then you use that variable in your module. You should not be setting the test suite parameter directly as it may not be guaranteed to be updated or used in the way you are expecting, where using it through a local module variable will work every time.

Re: Condition execution based on Parameter value

Posted: Tue Sep 19, 2017 6:13 pm
by Vaughan.Douglas
bk_tester wrote:Thanks a lot for your idea. It works fine for me. And in the same time my solution uncover a bug or at least possible improvement :)
I do see why you'd expect it to work by setting the parameter directly. From a strictly .net standpoint, it should work. I suspect krstcs is right though simply because this functionality is ONLY used in conjunction with Ranorex Studio conditional statements. I'm fairly sure that if you set a parameter directly you can access the value in another module programmatically, or at least you could in prior versions of Ranorex.

On the purely pragmatic level of test design, by not using the module variable as an intermediary you're obfuscating a variable from that rxtst page which acts as an overview for the scenario. You just need to know your audience.

Re: Condition execution based on Parameter value

Posted: Wed Sep 20, 2017 12:05 pm
by Marcel
Hello,

Setting a local parameter programmatically and using its value in an IF conditions works normally if you use the parameter inside of its scope (see:lesson-4-ranorex-test-suite and then “Scope of data containers”). The easiest way to demonstrate this is if we take the sent solution “HoldMyBeer” and look at the parameters “Beer” and “MoreBeer” that are defined inside of the “Six_Pack” TC. If we want to access the local parameter “Beer” and “MoreBeer” inside of the child “Mmmmmm_Beer” Smart folder we need to bind them to the module variable like “Better_Beer”.

If not, we need to access the parent parameter with the right code path, in our case we change/update the code in the “WhatToDo” code module to:
// TestSuite.CurrentTestContainer.Parameters["Beer"] = "Good Beer";
TestSuite.CurrentTestContainer.ParentContainer.Parameters["Beer"] = "Good Beer";
So we are setting the value of the “Six_Pack” TC parameter to “Beer”.

Or for example we can create a new code module in our case “SetParameterForIF”:
test_suite_set_param.png
In this module you write your “normal” code for modifying the local parameter of the “Six_pack” TC:
TestSuite.CurrentTestContainer.Parameters["Beer"] = "Good Beer";
and then the IF condition should work as expected.

Best regards, Marcel

Re: Condition execution based on Parameter value

Posted: Thu Sep 21, 2017 2:55 pm
by Vaughan.Douglas
Marcel wrote:wisdom dropped here...
great explanation. Thanks!

Re: Condition execution based on Parameter value

Posted: Mon Sep 25, 2017 2:15 pm
by krstcs
The problem with that logic is that is assumes that it will always be that way. You can't make that assumption. You should be using local (module) variables, bound to parameters or data columns, not setting them directly. The back-end of many of the objects that Ranorex exposes are not guaranteed to be static for any length of time and they can change on any given release.