-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1416 from joelpramos/feature/string-interpolation…
…-scenario-name-#1413 Adding support for JavaScript String interpolation in Scenario Names a…
- Loading branch information
Showing
6 changed files
with
180 additions
and
2 deletions.
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
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
98 changes: 98 additions & 0 deletions
98
karate-core/src/test/java/com/intuit/karate/core/parser/test-outline-name-js.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,98 @@ | ||
Feature: | ||
|
||
Background: | ||
* def sum = function(x,y){ return x + y; } | ||
* def js_data = | ||
""" | ||
[ | ||
{ | ||
"name": "Bob", | ||
"age": 10, | ||
"title": "name is Bob and age is 10" | ||
}, | ||
{ | ||
"name": "Nyan", | ||
"age": 5, | ||
"title": "name is Nyan and age is 5" | ||
} | ||
] | ||
""" | ||
|
||
* def nested_js_data = | ||
""" | ||
[ | ||
{ | ||
"name": { | ||
"first": "Bob", | ||
"last": "Dylan" | ||
}, | ||
"age": 10, | ||
"title": "name is Bob and age is 10" | ||
}, | ||
{ | ||
"name": { | ||
"first": "Nyan", | ||
"last": "Cat" | ||
}, | ||
"age": 5, | ||
"title": "name is Nyan and age is 5" | ||
} | ||
] | ||
""" | ||
|
||
Scenario Outline: `name is ${name} and age is ${age}` | ||
* def name = '<name>' | ||
* match name == "#? _ == 'Bob' || _ == 'Nyan'" | ||
* match title == karate.info.scenarioName | ||
|
||
Examples: | ||
| name | age | title | | ||
| Bob | 10 | name is Bob and age is 10 | | ||
| Nyan | 5 | name is Nyan and age is 5 | | ||
|
||
|
||
Scenario Outline: `name is ${name} and age is ${age}` | ||
* def name = '<name>' | ||
* match name == "#? _ == 'Bob' || _ == 'Nyan'" | ||
* match title == karate.info.scenarioName | ||
|
||
Examples: | ||
| js_data | | ||
|
||
|
||
Scenario Outline: `name is ${name.first} and age is ${age}` | ||
* match name.first == "#? _ == 'Bob' || _ == 'Nyan'" | ||
* match title == karate.info.scenarioName | ||
|
||
Examples: | ||
| nested_js_data | | ||
|
||
|
||
Scenario Outline: `name is ${name.first} ${name.last} and age is ${age}` | ||
* match name.first == "#? _ == 'Bob' || _ == 'Nyan'" | ||
* match name.last == "#? _ == 'Dylan' || _ == 'Cat'" | ||
* match title == karate.info.scenarioName | ||
|
||
Examples: | ||
| name! | age | title | | ||
| { "first": "Bob", "last": "Dylan" } | 10 | name is Bob Dylan and age is 10 | | ||
| { "first": "Nyan", "last": "Cat" } | 5 | name is Nyan Cat and age is 5 | | ||
|
||
|
||
# String interpolation allows you to use operators | ||
Scenario: one plus one equals ${1 + 1} | ||
* match karate.info.scenarioName == "one plus one equals 2" | ||
|
||
Scenario: `one plus one equals ${1 + 1}` | ||
* match karate.info.scenarioName == "one plus one equals 2" | ||
|
||
# can even access the karate object | ||
Scenario: scenario execution (env = ${karate.env}) | ||
# the env is set on the unit test in FeatureParserTest.java | ||
* match karate.info.scenarioName == "scenario execution (env = unit-test)" | ||
|
||
# functions can also be used, including access to the Java Interop API | ||
Scenario: math scenario: should return ${java.lang.Math.pow(2, 2)} | ||
* def powResult = java.lang.Math.pow(2, 2) | ||
* match karate.info.scenarioName == "math scenario: should return " + powResult | ||
* match karate.info.scenarioName == "math scenario: should return 4" |
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