-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding unit tests to test and reproduce several scenarios with readin… #1436
Closed
joelpramos
wants to merge
4
commits into
karatelabs:develop
from
joelpramos:bugfix/issues-with-reuse-features-and-background
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ee59ef0
Adding unit tests to test and reproduce several scenarios with readin…
joelpramos 0383174
Adding more tests from comment https://github.com/intuit/karate/pull/…
joelpramos 9f60139
Making magic variables (__arg, __row, __num, __loop) available only w…
joelpramos c9ade51
Updating unit tests - since magic variables are now only used within …
joelpramos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,7 +95,7 @@ public ScenarioRuntime(FeatureRuntime featureRuntime, Scenario scenario, Scenari | |
// detaching is as good as cloning | ||
// the detach is needed as the js-engine will be different | ||
Map<String, Variable> detached = background.engine.detachVariables(); | ||
detached.forEach((k, v) -> magicVariables.put(k, v.getValue())); | ||
detached.forEach((k, v) -> this.engine.vars.put(k, v)); // maybe this should go into this.engine.vars | ||
result.addStepResults(background.result.getStepResults()); | ||
} | ||
dryRun = featureRuntime.suite.dryRun; | ||
|
@@ -248,6 +248,8 @@ protected void logError(String message) { | |
} | ||
|
||
private Map<String, Object> initMagicVariables() { | ||
// do not init anything in this map that couldn't be considered a magic var (e.g. __arg, __loop) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need to add the other two vars in the comment for documentation purposes |
||
// those should remain in the scope of the scenario being executed only | ||
Map<String, Object> map = new HashMap(); | ||
if (caller.isNone()) { // if feature called via java api | ||
if (caller.arg != null && caller.arg.isMap()) { | ||
|
@@ -256,13 +258,9 @@ private Map<String, Object> initMagicVariables() { | |
} else { | ||
map.put("__arg", caller.arg); | ||
map.put("__loop", caller.getLoopIndex()); | ||
if (caller.arg != null && caller.arg.isMap()) { | ||
map.putAll(caller.arg.getValue()); | ||
} | ||
} | ||
if (scenario.isOutlineExample() && !scenario.isDynamic()) { // init examples row magic variables | ||
Map<String, Object> exampleData = scenario.getExampleData(); | ||
exampleData.forEach((k, v) -> map.put(k, v)); | ||
map.put("__row", exampleData); | ||
map.put("__num", scenario.getExampleIndex()); | ||
// TODO breaking change configure outlineVariablesAuto deprecated | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 0 additions & 11 deletions
11
karate-core/src/test/java/com/intuit/karate/core/js-read.feature
This file was deleted.
Oops, something went wrong.
29 changes: 29 additions & 0 deletions
29
karate-core/src/test/java/com/intuit/karate/core/jsread/js-read-2.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
Feature: | ||
|
||
Background: | ||
* def anotherVariable = 'hello' | ||
* def data = [{ name: 'one' }, { name: 'two' }] | ||
|
||
Scenario Outline: | ||
* match name == "#present" | ||
* match anotherVariable == "hello" | ||
|
||
Examples: | ||
| data | | ||
|
||
Scenario Outline: | ||
* match name == "#present" | ||
* match anotherVariable == "hello" | ||
|
||
Examples: | ||
| name | | ||
| test | | ||
|
||
Scenario Outline: | ||
* match name == "#present" | ||
* match anotherVariable == "hello" | ||
* def params = { 'foo': 'bar' } | ||
* call read('js-read-called-2.feature') params | ||
|
||
Examples: | ||
| data | |
1 change: 1 addition & 0 deletions
1
karate-core/src/test/java/com/intuit/karate/core/jsread/js-read-2.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"errorvar":[{"id":1},{"id":2}]} |
44 changes: 44 additions & 0 deletions
44
karate-core/src/test/java/com/intuit/karate/core/jsread/js-read-3.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
Feature: | ||
|
||
Background: | ||
* def anotherVariable = 'hello' | ||
* def x = read('js-read-3.json') | ||
* def data = x.thirderror | ||
* def backgroundVar = | ||
""" | ||
{"foo": '#(data)' } | ||
""" | ||
|
||
Scenario Outline: | ||
* match backgroundVar == { "foo": "#(data)" } | ||
* match id == "#present" | ||
* match anotherVariable == "hello" | ||
|
||
Examples: | ||
| data | | ||
|
||
Scenario Outline: | ||
* def param = | ||
""" | ||
{ bar: '#(backgroundVar)'} | ||
""" | ||
* match param == { bar: '#(backgroundVar)'} | ||
* match id == "#present" | ||
* match anotherVariable == "hello" | ||
|
||
Examples: | ||
| data | | ||
|
||
|
||
Scenario Outline: | ||
* def params = | ||
""" | ||
{ backgroundVar: '#(backgroundVar)'} | ||
""" | ||
* print params | ||
* match id == "#present" | ||
* match anotherVariable == "hello" | ||
* call read('js-read-called-2.feature') params | ||
|
||
Examples: | ||
| data | |
1 change: 1 addition & 0 deletions
1
karate-core/src/test/java/com/intuit/karate/core/jsread/js-read-3.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"thirderror":[{"id":1},{"id":2}]} |
11 changes: 11 additions & 0 deletions
11
karate-core/src/test/java/com/intuit/karate/core/jsread/js-read-4.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Feature: | ||
|
||
Background: | ||
|
||
Scenario: | ||
* def params = { 'foo': 'bar' } | ||
* call read('js-read-called-2.feature') params | ||
|
||
Scenario: | ||
* def params = { 'foo': 'bar' } | ||
* call read('js-read-called-3.feature') params |
1 change: 1 addition & 0 deletions
1
karate-core/src/test/java/com/intuit/karate/core/jsread/js-read-4.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"fourtherror":[{"id":1},{"id":2}]} |
1 change: 1 addition & 0 deletions
1
karate-core/src/test/java/com/intuit/karate/core/jsread/js-read-5.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"fiftherror":[{"id":1},{"id":2}]} |
10 changes: 10 additions & 0 deletions
10
karate-core/src/test/java/com/intuit/karate/core/jsread/js-read-called-2.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Feature: | ||
|
||
Background: | ||
#* call read('js-read-3.json') | ||
* call read('../utils-reuse-common.feature') | ||
|
||
Scenario: | ||
* print 'arg: ' + __arg | ||
* match __arg == "#present" | ||
* match __arg == "#notnull" |
11 changes: 11 additions & 0 deletions
11
karate-core/src/test/java/com/intuit/karate/core/jsread/js-read-called-3.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Feature: | ||
|
||
#see https://github.com/intuit/karate/pull/1436 | ||
Background: js-read-called-3 is calling a feature in background and assigning it's result. | ||
* def called = call read('../utils-reuse-common.feature') | ||
|
||
Scenario: | ||
* print 'arg: ' + __arg | ||
* match __arg == "#present" | ||
* match __arg == "#notnull" | ||
* match __arg == { 'foo': 'bar' } |
25 changes: 25 additions & 0 deletions
25
karate-core/src/test/java/com/intuit/karate/core/jsread/js-read-called.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
Feature: | ||
|
||
@name=checkUsageOfFunc | ||
Scenario: trigger call fun from parent read feature | ||
* def val = call fun | ||
* match val == 2 | ||
|
||
@name=checkReadingJsonKeys | ||
Scenario: check json data from parent read feature | ||
#* print error | ||
* match error[0].id == 1 | ||
|
||
@name=checkReadingSecondJsonKeys | ||
Scenario: check json data from parent read feature | ||
#* print error | ||
* match errorvar[0].id == 1 | ||
|
||
@name=checkReadingThirdJsonKeys | ||
Scenario: check json data from parent read feature | ||
* match thirderror[0].id == 1 | ||
|
||
@name=checkReadingFourthJsonKeys | ||
Scenario: check json data from parent read feature | ||
* match fourtherror[0].id == 1 | ||
|
10 changes: 10 additions & 0 deletions
10
karate-core/src/test/java/com/intuit/karate/core/jsread/js-read-reuse-2.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Feature: | ||
|
||
Background: | ||
* call read 'js-read-5.json' | ||
* def storedVar2 = call read 'js-read-5.json' | ||
|
||
Scenario: | ||
* print 'step in Scenario to trigger background steps' | ||
#* karate.set('storedVar', storedVar) | ||
#* karate.set('storedVar', `call read 'js-read-3.json'`) |
8 changes: 8 additions & 0 deletions
8
...te-core/src/test/java/com/intuit/karate/core/jsread/js-read-reuse-only-background.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Feature: | ||
|
||
Background: | ||
* call read 'js-read-4.json' | ||
* def storedVarBackground = call read 'js-read-4.json' | ||
|
||
Scenario: | ||
* print 'test' |
10 changes: 10 additions & 0 deletions
10
karate-core/src/test/java/com/intuit/karate/core/jsread/js-read-reuse.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Feature: | ||
|
||
Background: | ||
* call read 'js-read-3.json' | ||
* def storedVar = call read 'js-read-3.json' | ||
|
||
Scenario: | ||
* print 'step in Scenario to trigger background steps' | ||
#* karate.set('storedVar', storedVar) | ||
#* karate.set('storedVar', `call read 'js-read-3.json'`) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
forgot to remove the comment from the check in