/
test-outline-name-js.feature
99 lines (81 loc) · 2.58 KB
/
test-outline-name-js.feature
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
Feature:
@setup
Scenario:
* 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.scenario.name
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.scenario.name
Examples:
| karate.setup().js_data |
Scenario Outline: `name is ${name.first} and age is ${age}`
* match name.first == "#? _ == 'Bob' || _ == 'Nyan'"
* match title == karate.scenario.name
Examples:
| karate.setup().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.scenario.name
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.scenario.name == "one plus one equals 2"
Scenario: `one plus one equals ${1 + 1}`
* match karate.scenario.name == "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.scenario.name == "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.scenario.name == "math scenario: should return " + powResult
* match karate.scenario.name == "math scenario: should return 4"