Asked  6 Months ago    Answers:  5   Viewed   206 times

I have 2 feature files and trying to perform below operation

FEATURE 1: [calling.feature]

Feature: Test loop over by calling a feature file

Scenario Outline: Testing loop over feature file
* call read('called.feature') { argument = '<arg>' }

Examples:
|arg| 
|"HELLO"|
|"WORLD"|

FEATURE 2: [called.feature]

Feature: Test loop over in Karate framework

Scenario Outline: Testing loop over feature
* def callingArg = arg
* match '<arg2>' == callingArg
Examples:
|arg2| 
|"TEST1"|
|"WORLD"|

When I call 'Called.feature' using read in 'Calling.feature' I was expecting it will iterate using across all the examples in both feature file

but Karate exits whenever it finds the failure, in this case when parameter "HELLO" is passed from Calling.feature it fails during match step in 'called.feature' for example 'TEST1' and never tests for 'WORLD'.

Is there a way I can force Karate to complete all the scenario examples in the called.feature???

Below is the logs:

calling: [com.intuit.karate.exception.KarateException: path: $, actual: 'HELLO', expected: 'TEST1', reason: not equal
    at com.intuit.karate.StepDefs.matchNamed(StepDefs.java:540)
    at com.intuit.karate.StepDefs.matchEquals(StepDefs.java:526)
    at ✽.* match fileName == "TEST1"(called.feature:16)
, com.intuit.karate.exception.KarateException: path: $, actual: 'WORLD', expected: 'TEST1', reason: not equal
    at com.intuit.karate.StepDefs.matchNamed(StepDefs.java:540)
    at com.intuit.karate.StepDefs.matchEquals(StepDefs.java:526)
    at ✽.* match fileName == "TEST1"(called.feature:16)
, com.intuit.karate.exception.KarateException: feature call (loop) failed: called.feature
caller: calling.feature
items: [{mdbName=HELLO}, {mdbName=WORLD}]
errors:
-------
feature call (loop) failed at index: 0
caller: calling.feature
arg: {mdbName=HELLO}

path: $, actual: 'HELLO', expected: 'TEST1', reason: not equal
-------
feature call (loop) failed at index: 1
caller: calling.feature
arg: {mdbName=WORLD}

path: $, actual: 'WORLD', expected: 'TEST1', reason: not equal
    at com.intuit.karate.Script.evalFeatureCall(Script.java:1636)
    at com.intuit.karate.Script.call(Script.java:1579)
    at com.intuit.karate.Script.callAndUpdateConfigAndAlsoVarsIfMapReturned(Script.java:1669)
    at com.intuit.karate.StepDefs.callAndUpdateConfigAndVars(StepDefs.java:571)
    at ✽.* call read('called.feature') mdbData(calling.feature:9)

 Answers

2

Your formatting is very hard to understand. Anyway Karate is supposed to evaluate all example rows even if there is a failure. Here is a simple example:

Feature:    
Scenario Outline:

* call read('called.feature') { a: <value> }    

Examples:
| value |
| 1     |
| 2     |
| 3     |

And called.feature is:

Feature:
Scenario:

* match a == 2

And it works as expected. Even though rows 1 and 3 fail, all rows are executed. So you may be on an old version of Karate. Please upgrade.

EDIT: This was fixed in 0.8.0: https://github.com/intuit/karate/issues/421

Friday, November 26, 2021
 
ollien
 
3

Please use below code in the karate-config.js

function() {    
    return priceBaseUrl='http://localhost:8080';
}
Wednesday, June 2, 2021
 
RahulG
 
5

call and karate.callSingle() take only one argument, but you can easily create a new JSON out of other JSONs. Actually since you seem to be passing config as the argument - you can easily access config.refreshToken as __arg.refreshToken.

Your code is very confusing - but hope that this hint is what gets you on your way:

Given def json = __arg.refreshToken

If you need to create a JSON out of other data - I think you already know how to do that:

var temp = { config: config, refreshToken: refreshToken };
var token = karate.callSingle('classpath:features/Utils/GetToken.feature', temp);
Saturday, July 31, 2021
 
KouiK
 
4

Normally it is better to rely on hooks at the start, because of the risk that the hook failed the last time - or your test suite did not complete.

Achieving this is easy, just use Java at the end of the test-run in your parallel-runner, very similar to how the cucumber-reports are generated here: DemoTestParallel.java

Results results = Runner.parallel(getClass(), 5);
MyUtils.cleanUp();
Monday, December 13, 2021
 
sawyer
 
5

See Execute Commands From C#

public static int ExecuteCommand(string Command, int Timeout)
{
    int exitCode;
    var processInfo = new ProcessStartInfo("cmd.exe", "/C " + Command);
    processInfo.CreateNoWindow = true;
    processInfo.UseShellExecute = false;
    Process process = Process.Start(processInfo);
    process.WaitForExit(Timeout);
    exitCode = process.ExitCode;
    process.Close();
    return exitCode;
}
Thursday, January 13, 2022
 
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :  
Share