1

I am using Karate '* configure afterScenario = ' in feature file and getting results successfully and able to have DB calls as well. How to implement same in Karate-config.js?

Note: I have a Java class call as well.

Any implementation like this?

Code using in feature file

Background:
* def inFluxDb = Java.type('aPITests.InfluxDBCall');
* def dbCDB = new inFluxDb();
* configure afterScenario = 
"""
function(){
  var info = karate.info; 
  karate.log('after', info.scenarioType + ':', info.scenarioName);
  karate.log('after', info.scenarioType + ':', info.errorMessage);
  karate.log('after', info.scenarioType + ':', info.featureDir);
  karate.log('after', info.scenarioType + ':', info.featureFileName);
  karate.log('after', info.scenarioType + ':', info.scenarioDescription);
  var featurenameupdate = info.featureFileName.substring(0, info.featureFileName.length-8);
  var status="Fail";
  if(!info.errorMessage){
  status="Pass";
  }
  dbCDB.DBConnection( "http://localhost:8086", "root", "root");
  dbCDB.DBwrite( featurenameupdate, info.scenarioName, info.errorMessage, status );
  dbCDB.connectionClose();
}
"""

Update: Concern after using karate.configure

Scenario: I have two feature files

Feature1: API) contains @smoke @test tags

Feature2: UI) contains @dropdown @Angular

My * def configure afterScenariois declared into Feature2 file While executing only @smoke test, my karate.configure('afterScenario', 'UI.feature'); is not loading.

is this as expected or else anything need to be updated from my end?

1 Answer 1

1

Use the karate.configure() API to move any feature configure step into the JS config.

karate.configure('afterScenario', read('some.feature'));

I don't recommend "bloating" your karate-config.js unless absolutely necessary, because it is called for every Scenario or Examples row. Consider using a ExecutionHook instead.

Sign up to request clarification or add additional context in comments.

4 Comments

After using karate.configure('afterScenario', read('some.feature')); i have a concern. Updated into original post. please Check 'Concern after using karate.configure' and let me know your valuable inputs.
@SandeepPadala sorry I don't understand. ask a new question. if it is not clear, you will have to follow this process: github.com/intuit/karate/wiki/How-to-Submit-an-Issue
Sorry Peter Thomas, i was asking like if i am loading my afterScenario from some.feature in karate-config.js and while executing my tests(with a specific tag which dont include some.feature scenario file tags). Unable to load afterScenario from some.feature while executing . Hope you got it.
@SandeepPadala of course if the afterScenario has not been configured, it will not work, I may be missing something, you know what to do now :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.