Need to pass a method reference to a library

I have a feature-rich library (TeamControlium Controlium) that I am trying to integrate with Katalon. The library produces messages (debug, information, etc…). The library has a method that takes a consumer and passes the messages out to that consumer.

However, I can seem to get the wiring correct in Katalon.

In Java world I’d have a method; IE (bad example but get the idea…);

private void messageReceiver(String line) {
println(line);
}

and as part of test startup I say;

Logger.setTestToolLog(this::messageReceiver);

All output from the libraries (and indeed in-test writes) gets written to messageReceiver that - in this case - just puts it out to the stdout stream.

In Katalon, i want to say:-

def messageReceiver(String line) {
new KeywordLogger().logInfo(line);
}

However, I cant seem to get it right. I’ve tried in a Keyword package and I’ve tried in a ‘Test case’, but always get an error along the lines of MissingPropertyException. Is there a trick to being able to do this?

For external libs integration, you need to add the jar into external libs of Katalon Studio first. I am not sure if I understood your scenarios

Yeah, I’ve got them working fine in the External libs. I can call out to them all good no worries.
But, &. to the rescue!!

Logger.setTestToolLog(this&.messageReceiver);

Woohoo!!

Thanks tho Trong.

1 Like