Page 1 of 1

Skip a module based on a previous result

Posted: Thu Nov 21, 2013 10:34 am
by AccidentReport
Is it possible to make a test skip a module depending on the result of a previous module? I'll explain. I have two modules:

CheckNameModule - This checks the displayed name of the center the user is currently connected to.

ChangeCenterModule - This changes the center for the user.

These are setup in a test case like so:

1. CheckNameModule
2. ChangeCenterModule
3. CheckNameModule

Scenario 1 - The current center is "Alpha" and the required center is "Gamma". When the CheckNameModule runs it checks if the current is the same as the required. In this case it is not so I want it to run steps 2 & 3.

Scenario 2 - The current center is "Alpha" and the required center is "Alpha". When the CheckNameModule runs it checks if the current is the same as the required. In this case it is so I want it to skip steps 2 & 3.

I can probably convert all this into user code and achieve what I want but I'm wondering if there is an easier way to do this.

Re: Skip a module based on a previous result

Posted: Thu Nov 21, 2013 12:25 pm
by Swisside
Hello !

Since conditions are not (yet?) available without code you'll need a bit of code.

If you put the 3 modules in the same test case what you can do is throw an exception at the beginning of the second module if you don't need to execute them. It will end the current test case and go to the next one.

So in practice you add a UserCode action at the beginning of ChangeCenterModule.

Then add the following code
if (currentCenter==requiredCenter){  
throw new Ranorex.ValidationException("No need to change the center");
}
This is a bit of a hack since it will make the test case fail.

If you want to do it in a proper way it is required to use a bit more code.

For instance you could use a global parameter to store the center value (you can access or set parameters using TestSuite.Current.Parameters["myparam"])

Then you would need to put all the actions from step 2 and 3 inside a condition like this
if(currentCenter!=requiredCenter){
ChangeCenterModuleActions
CheckNameModuleActions
}
Regards

Re: Skip a module based on a previous result

Posted: Thu Nov 21, 2013 12:27 pm
by AccidentReport
Thought it wouldn't be as easy as I hoped (or lazy I guess). Thanks. i'll get into the code and do it that way then!

Re: Skip a module based on a previous result

Posted: Thu Nov 21, 2013 12:43 pm
by swmatisa