Skip to content

Commit

Permalink
resolve variable access in called features #1687
Browse files Browse the repository at this point in the history
introduced by #1685
  • Loading branch information
ptrthomas committed Jul 22, 2021
1 parent 990eadf commit ef6b28b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1627,7 +1627,7 @@ private void set(String name, String path, boolean isWithinParentheses, Variable
name = nameAndPath.left;
path = nameAndPath.right;
}
Variable target = vars.get(name);
Variable target = JS.bindings.hasMember(name) ? new Variable(JS.get(name)) : null; // should work in called features
if (isXmlPath(path)) {
if (target == null || target.isNull()) {
if (viaTable) { // auto create if using set via cucumber table as a convenience
Expand Down Expand Up @@ -1678,7 +1678,6 @@ private void set(String name, String path, boolean isWithinParentheses, Variable
json.set(path, value.<Object>getValue());
}
}

}

private static final String PATH = "path";
Expand Down Expand Up @@ -2112,11 +2111,13 @@ private static Variable nodeToValue(Node node) {
}

public Variable evalJsonPathOnVariableByName(String name, String path) {
return evalJsonPath(vars.get(name), path);
Variable v = new Variable(JS.get(name)); // should work in called features
return evalJsonPath(v, path);
}

public Variable evalXmlPathOnVariableByName(String name, String path) {
return evalXmlPath(vars.get(name), path);
Variable v = new Variable(JS.get(name)); // should work in called features
return evalXmlPath(v, path);
}

public Variable evalKarateExpression(String text) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ void testOutlineConfigJsParallel() {
.parallel(2);
assertEquals(0, results.getFailCount());
}

@Test
void testOutlineConfigJsCallSingleParallel() {
Results results = Runner.path("classpath:com/intuit/karate/core/outline-config-js.feature")
Expand Down Expand Up @@ -278,25 +278,30 @@ void testIgnoreStepFailure() {
report.render("target/report-test");
// error log will should have logs on all failures
}

@Test
void testKarateFork() {
run("fork.feature");
}
}

@Test
void testCsv() {
run("csv.feature");
}
}

@Test
void testXmlPretty() {
run("xml-pretty.feature");
}

@Test
void testMatchStep() {
run("match-step.feature");
}
}

@Test
void testCallJsonPath() {
run("call-jsonpath.feature");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@ignore
Feature:

Scenario:
* def vals = $foo[*].id
* print vals
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Feature:

Scenario:
* def foo = [{a: 1}, {a: 2}]
* def bar = call read('call-jsonpath-called.feature')

0 comments on commit ef6b28b

Please sign in to comment.