1

I have created a Java object in karate scripts using Java interop and have used it as required. Now, I want to retrieve that same instance in another Java class. Is there a way to do that? In karate, we have an equivalent method like karate.get('objectName'). Is there any equivalent API available in Karate lib?

rexD
  • 21
  • 2

1 Answers1

0

Please assume that the answer is no. I'd like to mention that the whole point of creating Karate was to avoid using Java for API test automation. I say this because I suspect based on your questions that you have made the same mistake I've seen a few other teams make - which is attempting to make Karate work like the Seleniums and Rest Assureds of the world. That always ends badly. And what's worse is that these teams blame Karate for that and go around telling everyone. I'd rather have that not happen - so if this is a "blocker" please consider using some other tool.

If you are already calling Java, you have plenty of ways to pass objects around right? Just use that and don't over-complicate your tests. Or you can use the "singleton" pattern, nothing to do with Karate, you can look it up.

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • 1
    Not a blocker.. Changed Java class pattern to Singleton. Thanks – rexD Feb 02 '23 at 13:08
  • @rexD make sure you read this also: https://stackoverflow.com/a/46080568/143475 - if you use a singleton you are very likely to not be able to run your scenarios in parallel. there are reasons why karate is designed the way it is – Peter Thomas Feb 02 '23 at 14:34