Reputation: 29
I'm using the Java DSL with the TestRunner to define my tests and basically want to have the following steps:
Basically like this:
http(builder -> builder.client("client").send()
.get("/config").header("Content-Type", "application/json"));
http(builder -> builder.client("client").receive()
.response(HttpStatus.OK).messageType(MessageType.JSON)
.extractFromPayload("$", "myConfig"));
The variable is set:
echo("${myConfig}")
shows the desired output. But how can I get access to that variable to do something with it in pure Java?
I tried this approach:
variable("chgConfig", MyClassABC.myStaticFunctionXZY("${myConfig}");
And I already tried to use a Citrus Function
, but I don't know how to call/include it using the Java DSL.
Is there perhaps any way, to get the actual TestContext and hand it over to my Java-Code?
My understanding was, when using the TestRunner, everything is immediately executed and I was thinking: Oh, that's cool, as I can just insert standard Java-Code when needed.
Upvotes: 0
Views: 349
Reputation: 29
Yeah, I found the solution myself, just reading a second (or maybe a third ) time the documentation.
I have changed my Test-Class like this:
@CitrusTest
@Test @Parameters("context")
public void run(@Optional @CitrusResource TestContext context) {
...
.....
...
MyClassABC.myStaticFunctionXZY(context.getVariable("myConfig"));
This injects me the actual Test-Context and allows me to access & manipulate variables from my Java-Code. Great stuff.
Upvotes: 1