2

Whenever I try to call the feature file(one.feature) from another feature file(starter.feature), I am not able to access the info(caller) in specific scenario

But It is working fine and I am able to access info(caller),

  1. when I run one.feature file standalone.
  2. when I run one.feature file through Junit test case.

CODE WORK-FLOW : In one.feature : In the scenario(Scenario: matching two Strings) we are trying to match two Strings and configuring afterScenario JS function to get the info of the scenario and If the info contains any errors, The function will call the other scenario(Scenario: getting caller details) with info details assigned in the variable caller

starter.feature :

 Feature: call another feature

Scenario: calling feature file

* def callFeat = call read('one.feature')

one.feature :

Feature: get details

Background:

* configure afterScenario =
"""
function() {
var info = karate.info;

if(info.errorMessage){
karate.call('one.feature@CallCaller', { caller : info });
}
}
"""


@CreateErrorMsg
Scenario: matching two Strings
* def Text1 = 'Hey'
* def Text2 = 'Hello'
* match Text1 == Text2

@CallCaller @ignore
Scenario: getting caller details

* print caller

  • first let me say this is a textbook case of over-engineering your tests. please take some time to read this and pass this on to your team-leads or managers if needed: https://stackoverflow.com/a/54126724/143475 - if you still need help, follow this process: https://github.com/karatelabs/karate/wiki/How-to-Submit-an-Issue – Peter Thomas May 19 '22 at 06:37
  • @PeterThomas Thanks for the quick response. We are trying to get the info and errors particularly related to particular scenario so that we can proceed further to follow up with our use case – Virupakshappa Janadri May 19 '22 at 10:20
  • 1
    based on your question, my recommendation is please don't use karate. you will end up with a mess that future developers will blame on karate instead of the people who decided to do this over-engineering. karate is a framework used by many teams around the world and a lot of work has gone into the HTML reports and embedded logs. no one has asked for features like what you are expecting. this is my humble request. – Peter Thomas May 19 '22 at 10:47

1 Answers1

0

Can't you use karate.log from the JS function rather than calling another scenario to just print the info? Also, note that karate.info has been deprecated from 1.0 version of Karate and replaced by karate.scenario - https://github.com/karatelabs/karate/wiki/1.0-upgrade-guide#karateinfo-deprecated

    * configure afterScenario =
    """
      function() {
        var info = karate.info;
        
        if(info.errorMessage){
          karate.log(info.scenarioName);
        }
      }
    """
Vijay
  • 13
  • 4
  • Hey @Vijay, thanks for the suggestion, Please read the above comments (We are trying to get the info and errors particularly related to particular scenario so that we can proceed further to follow up with our use case ) – Virupakshappa Janadri May 20 '22 at 07:54