1

I found in the karate docs that the java method can be run like this:

* def JavaDemo = Java.type('com.app.DBUtils').prepareData(arg1, arg2)

I created karate-config.js file where I stored environment variables. Now I need to run some java methods after every scenario, but just for some environments. So I have there some conditions.

But I didn't find a way to run a java method from karate-config.js after every scenario. Is it possible?

Marcus
  • 131
  • 9

1 Answers1

1

Yes if you wrap it in JS or a Feature: https://github.com/intuit/karate#hooks

var fun = function(){ var MyClass = Java.type('com.myco.MyClass'); MyClass.doWork() }
karate.configure('afterScenario', fun);
Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • 1
    @PeterSmith There are 2 scenarios in my feature file. One variable(named Id) is unique for both. Now in case of parallel run, how do i pass 'id' to above function(lets say my function deletes entry from DB) so that it deletes correct 'id' after it's respective scenario. It should not delete another scenario's id. assume: i have defined this JS code under Background of feature file. – Yash Aug 22 '23 at 13:39
  • @Yash Karate is designed to not have scenarios depend on each other: https://stackoverflow.com/a/46080568/143475 - so if you really want to do this, you are on your own: https://stackoverflow.com/a/54571844/143475 – Peter Thomas Aug 22 '23 at 14:57
  • 1
    PeterSmith, sorry you didn't get my question. I am not asking to use variable of one scenario into another scenari. My question was: Can we pass scenario variable into afterscenario block? – Yash Aug 22 '23 at 16:34