Search code examples
citrus-framework

Citrus-Framework - Parameter handling for Custom-Actions


To solve the issue described here: Citrusframework - Java action - Get result, I created a Custom-Action, which basically wraps the Java-Call to provide me options inside my Java-Code to validate the Java-Program result as I need.

But transferring parameters/variables from the Test-Case to the Java-Program is difficult. I need to call this program -times during a test and each time, with different parameters. So, I added the following before calling the custom action:

variable("param1", "myValue1");
variable("expectedReturnCode", "0");
action(myCustomAction);

Later in the test, after some other actions, I want it like this:

variable("param1", "myValue2");
variable("expectedReturnCode", "99");
action(myCustomAction);

In my Custom-Action-Class I have the following:

String param1 = context.getVariable("param1");
expectedReturnCode = Integer.parseInt(context.getVariable("expectedReturnCode"));

The problem is, that the Text-Context isn't filled before the Custom-Action Call, it seems, that the Context is set completely before the first action is called, so even the first CustomAction gets 99 as the expected RC.

So, my question would be: How can I transfer individual parameters to my Custom-Action?


Solution

  • Do not use variable() as it is only used for initializing variables before the test is run. That is why your second call overwrites the variable value immediately. variable() is only for setting things up at the very beginning of a test.

    Instead you should be using createVariable(String variableName, String value) that is performed as test action within your test case at runtime.