diff --git a/karate-core/src/test/java/com/intuit/karate/core/FeatureRuntimeTest.java b/karate-core/src/test/java/com/intuit/karate/core/FeatureRuntimeTest.java index f5fb6124d..23ae98944 100644 --- a/karate-core/src/test/java/com/intuit/karate/core/FeatureRuntimeTest.java +++ b/karate-core/src/test/java/com/intuit/karate/core/FeatureRuntimeTest.java @@ -181,7 +181,22 @@ void testSetXml() { @Test void testJsRead() { - run("js-read.feature"); + run("jsread/js-read.feature"); + } + + @Test + void testJsRead2() { + run("jsread/js-read-2.feature"); + } + + @Test + void testJsRead3() { + run("jsread/js-read-3.feature"); + } + + @Test + void testJsRead4() { + run("jsread/js-read-4.feature"); } @Test diff --git a/karate-core/src/test/java/com/intuit/karate/core/js-read.feature b/karate-core/src/test/java/com/intuit/karate/core/js-read.feature deleted file mode 100644 index b5e25f9b0..000000000 --- a/karate-core/src/test/java/com/intuit/karate/core/js-read.feature +++ /dev/null @@ -1,11 +0,0 @@ -Feature: - -Scenario: reading json 1 - * def fun = function(){ var temp = read('js-read.json'); return temp.error[1].id } - * def val = call fun - * match val == 2 - -Scenario: reading json 2 - * def fun = function(){ var temp = karate.read('js-read.json'); return temp.error[1].id } - * def val = call fun - * match val == 2 \ No newline at end of file diff --git a/karate-core/src/test/java/com/intuit/karate/core/jsread/js-read-2.feature b/karate-core/src/test/java/com/intuit/karate/core/jsread/js-read-2.feature new file mode 100644 index 000000000..23f682827 --- /dev/null +++ b/karate-core/src/test/java/com/intuit/karate/core/jsread/js-read-2.feature @@ -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 | diff --git a/karate-core/src/test/java/com/intuit/karate/core/jsread/js-read-2.json b/karate-core/src/test/java/com/intuit/karate/core/jsread/js-read-2.json new file mode 100644 index 000000000..a56a93874 --- /dev/null +++ b/karate-core/src/test/java/com/intuit/karate/core/jsread/js-read-2.json @@ -0,0 +1 @@ +{"errorvar":[{"id":1},{"id":2}]} diff --git a/karate-core/src/test/java/com/intuit/karate/core/jsread/js-read-3.feature b/karate-core/src/test/java/com/intuit/karate/core/jsread/js-read-3.feature new file mode 100644 index 000000000..ebb6be999 --- /dev/null +++ b/karate-core/src/test/java/com/intuit/karate/core/jsread/js-read-3.feature @@ -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 | diff --git a/karate-core/src/test/java/com/intuit/karate/core/jsread/js-read-3.json b/karate-core/src/test/java/com/intuit/karate/core/jsread/js-read-3.json new file mode 100644 index 000000000..f9ba0ca6c --- /dev/null +++ b/karate-core/src/test/java/com/intuit/karate/core/jsread/js-read-3.json @@ -0,0 +1 @@ +{"thirderror":[{"id":1},{"id":2}]} diff --git a/karate-core/src/test/java/com/intuit/karate/core/jsread/js-read-4.feature b/karate-core/src/test/java/com/intuit/karate/core/jsread/js-read-4.feature new file mode 100644 index 000000000..3f0390134 --- /dev/null +++ b/karate-core/src/test/java/com/intuit/karate/core/jsread/js-read-4.feature @@ -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 diff --git a/karate-core/src/test/java/com/intuit/karate/core/jsread/js-read-4.json b/karate-core/src/test/java/com/intuit/karate/core/jsread/js-read-4.json new file mode 100644 index 000000000..0cda08bb1 --- /dev/null +++ b/karate-core/src/test/java/com/intuit/karate/core/jsread/js-read-4.json @@ -0,0 +1 @@ +{"fourtherror":[{"id":1},{"id":2}]} diff --git a/karate-core/src/test/java/com/intuit/karate/core/jsread/js-read-5.json b/karate-core/src/test/java/com/intuit/karate/core/jsread/js-read-5.json new file mode 100644 index 000000000..4e33829fa --- /dev/null +++ b/karate-core/src/test/java/com/intuit/karate/core/jsread/js-read-5.json @@ -0,0 +1 @@ +{"fiftherror":[{"id":1},{"id":2}]} diff --git a/karate-core/src/test/java/com/intuit/karate/core/jsread/js-read-called-2.feature b/karate-core/src/test/java/com/intuit/karate/core/jsread/js-read-called-2.feature new file mode 100644 index 000000000..5f7e38d83 --- /dev/null +++ b/karate-core/src/test/java/com/intuit/karate/core/jsread/js-read-called-2.feature @@ -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" \ No newline at end of file diff --git a/karate-core/src/test/java/com/intuit/karate/core/jsread/js-read-called-3.feature b/karate-core/src/test/java/com/intuit/karate/core/jsread/js-read-called-3.feature new file mode 100644 index 000000000..77d17a11b --- /dev/null +++ b/karate-core/src/test/java/com/intuit/karate/core/jsread/js-read-called-3.feature @@ -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' } \ No newline at end of file diff --git a/karate-core/src/test/java/com/intuit/karate/core/jsread/js-read-called.feature b/karate-core/src/test/java/com/intuit/karate/core/jsread/js-read-called.feature new file mode 100644 index 000000000..d50042e15 --- /dev/null +++ b/karate-core/src/test/java/com/intuit/karate/core/jsread/js-read-called.feature @@ -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 + diff --git a/karate-core/src/test/java/com/intuit/karate/core/jsread/js-read-reuse-2.feature b/karate-core/src/test/java/com/intuit/karate/core/jsread/js-read-reuse-2.feature new file mode 100644 index 000000000..31f066051 --- /dev/null +++ b/karate-core/src/test/java/com/intuit/karate/core/jsread/js-read-reuse-2.feature @@ -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'`) diff --git a/karate-core/src/test/java/com/intuit/karate/core/jsread/js-read-reuse-only-background.feature b/karate-core/src/test/java/com/intuit/karate/core/jsread/js-read-reuse-only-background.feature new file mode 100644 index 000000000..5785f07c7 --- /dev/null +++ b/karate-core/src/test/java/com/intuit/karate/core/jsread/js-read-reuse-only-background.feature @@ -0,0 +1,8 @@ +Feature: + +Background: + * call read 'js-read-4.json' + * def storedVarBackground = call read 'js-read-4.json' + +Scenario: + * print 'test' \ No newline at end of file diff --git a/karate-core/src/test/java/com/intuit/karate/core/jsread/js-read-reuse.feature b/karate-core/src/test/java/com/intuit/karate/core/jsread/js-read-reuse.feature new file mode 100644 index 000000000..92d11da2a --- /dev/null +++ b/karate-core/src/test/java/com/intuit/karate/core/jsread/js-read-reuse.feature @@ -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'`) diff --git a/karate-core/src/test/java/com/intuit/karate/core/jsread/js-read.feature b/karate-core/src/test/java/com/intuit/karate/core/jsread/js-read.feature new file mode 100644 index 000000000..ca82a8385 --- /dev/null +++ b/karate-core/src/test/java/com/intuit/karate/core/jsread/js-read.feature @@ -0,0 +1,69 @@ +Feature: + +Background: + * call read 'js-read-2.json' + * def varInContext = callonce read('this:js-read-reuse.feature') + * call read('this:js-read-reuse.feature') + * call read 'this:js-read-reuse-2.feature' + * def varInBackgroundContext = callonce read('this:js-read-reuse-only-background.feature') + * call read('this:js-read-reuse-only-background.feature') + +Scenario: reading json 1 + * def fun = function(){ var temp = read('js-read.json'); return temp.error[1].id } + * def val = call fun + * match val == 2 + +Scenario: reading json 2 + * def fun = function(){ var temp = karate.read('js-read.json'); return temp.error[1].id } + * def val = call fun + * match val == 2 + +Scenario: reading json, calling feature and reusing json + * def fun = function(){ var temp = karate.read('js-read.json'); return temp.error[1].id } + * def result = call read('js-read-called.feature@name=checkUsageOfFunc') + +Scenario: reading json, calling feature and reusing json + * call read 'js-read.json' + * def result = call read('js-read-called.feature@name=checkReadingJsonKeys') + +Scenario: reading json (with callonce), calling feature and reusing json + * callonce read 'js-read.json' + * def result = call read('js-read-called.feature@name=checkReadingJsonKeys') + +Scenario: calling feature and reusing json read in background section + * def result = call read('js-read-called.feature@name=checkReadingSecondJsonKeys') + +Scenario: calling feature that will read a json file in its background (no scenario defined), then call a feature that uses data from that json + * print storedVarBackground + * match varInBackgroundContext.storedVarBackground.fourtherror[0].id == 1 + * match varInBackgroundContext.fourtherror[0].id == 1 + * def result = call read('js-read-called.feature@name=checkReadingFourthJsonKeys') + + +Scenario: calling feature that will read a json (with space after the read keyword) file and then call a feature that uses data from that json +# note that when reading the reusable feature like this: * call read 'this:js-read-reuse-2.feature' +# the scope of that feature file is not available in the caller + * def matchVar2 = karate.get('storedVar2') + * match matchVar2 == null + * def matchFifthError = karate.get('fiftherror') + * match matchFifthError == null + + +Scenario: calling feature that will read a json file and then call a feature that uses data from that json + * match varInContext.storedVar.thirderror[0].id == 1 + * match varInContext.thirderror[0].id == 1 + * match storedVar.thirderror[0].id == 1 + * match thirderror[0].id == 1 + * def result = call read('js-read-called.feature@name=checkReadingThirdJsonKeys') + +Scenario Outline: using a scenario outline, call feature that will read a json file and then call a feature that uses data from that json + * match varInContext.storedVar.thirderror[0].id == + * match varInContext.thirderror[0].id == + * match storedVar.thirderror[0].id == + * match thirderror[0].id == 1 + * def result = call read('js-read-called.feature@name=checkReadingThirdJsonKeys') + +Examples: + | value | + | 1 | + | 1 | \ No newline at end of file diff --git a/karate-core/src/test/java/com/intuit/karate/core/js-read.json b/karate-core/src/test/java/com/intuit/karate/core/jsread/js-read.json similarity index 100% rename from karate-core/src/test/java/com/intuit/karate/core/js-read.json rename to karate-core/src/test/java/com/intuit/karate/core/jsread/js-read.json