Skip to content
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 for Engine #1438

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 0 additions & 11 deletions karate-core/src/test/java/com/intuit/karate/core/js-read.feature

This file was deleted.

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 |
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"errorvar":[{"id":1},{"id":2}]}
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 |
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"thirderror":[{"id":1},{"id":2}]}
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"fourtherror":[{"id":1},{"id":2}]}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"fiftherror":[{"id":1},{"id":2}]}
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"
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' }
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

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'`)
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'
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'`)
Original file line number Diff line number Diff line change
@@ -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 == <value>
* match varInContext.thirderror[0].id == <value>
* match storedVar.thirderror[0].id == <value>
* match thirderror[0].id == 1
* def result = call read('js-read-called.feature@name=checkReadingThirdJsonKeys')

Examples:
| value |
| 1 |
| 1 |