1

I want to be able to send the scenario result (testName + status) to an external endpoint, right after the execution of the scenario.

My karate-config looks like this:

function fn() {   
  var config = { // base config JSON
    testPusher: function(testResult) {
      var url = 'http://localhost:5000';

      var data = JSON.stringify(testResult);

      fetch(url, {
        headers: { "Content-Type": "application/json; charset=utf-8" },
        method: 'POST',
        body: data
      })
    }
  };
  return config;
}

In de Background part of my feature I've added

Background:
  * configure afterScenario = 
        """
          function(){
              var info = karate.info; 
              var status="Fail";
              if(!info.errorMessage){
                  status="Pass";
              };
              var testResult = {
                  testName: info.scenarioName,
                  result: status
              }
              testPusher(testResult)
            }
        """

Fetch seems to be unknown to karate, so is there any possibility to add fetch (or node-fetch or axios...) to the modules which can be used.

If I'm totally missing out on the way of doing it, what will be the best approach to send me the result of each scenario in the afterscenario hook?

StefDaems
  • 103
  • 8
  • Thanks for the quick response @ptrthomas but this still kept me a bit in the dark. The docs referred to aren't shining much light on my question. Does this indicate I don't need to use the afterscenario any longer and look for the ExecutionHook to be implemented somewhere, somehow? I expect the need to implement something like Kafka.post(url, body, header).... – StefDaems Nov 21 '20 at 15:46

0 Answers0