问题
If examples has too many columns ,every row will be too long to read!
Feature:
Background:
Scenario Outline:
* match '<msg>' == <prefix> + ',' + '<end>'
Examples:
| prefix | end | msg |
| hello | mike | hello,mike |
| hello | jerry | hello,jerry |
Could it be like that:
Feature:
Background:
Examples:
| prefix |
| hello |
Scenario Outline:
* match '<msg>' == <prefix> + ',' + '<end>'
Examples:
| end | msg |
| mike | hello,mike |
| jerry | hello,jerry |
I want to divide the examples in several parts, or set a base examples before Outline.What should I do?
回答1:
karate address this in many different ways in its latest versions 0.9.X
, Let see
- As you asked we can define the
Examples:
tables beforeScenario Outline:
using table in karate,
Feature: my feature
Background: BG
* table myExample
| prefix | end | msg |
| 'hello' | 'mike' | 'hello,mike' |
| 'hello' | 'jerry' | 'hello,jerry' |
Scenario Outline: SOW
* match '<msg>' == '<prefix>' + ',' + '<end>'
Examples:
| myExample |
the same can be kept in another feature file and read it in this feature file, but don't complicate as we have some other solutions coming below..
2.karate sees all these table
, Examples:
as array of JSON's
typically you example above will be represented as,
[
{
"prefix": "hello",
"end": "mike",
"msg": "hello,mike"
},
{
"prefix": "hello",
"end": "jerry",
"msg": "hello,jerry"
}
]
so karate allows you to define these Examples
also from JSON
or csv
formats using karate's dynamic scenario outline feature
if you feel like you examples are too large to accommodate in your feature file keep it in a csv
file and do read in your Examples
Feature: my feature
Background: BG
* def myExample = read("myExample.csv")
Scenario Outline: SOW
* match '<msg>' == '<prefix>' + ',' + '<end>'
Examples:
| myExample |
The same applies to JSON also, providing data as JSON array.
来源:https://stackoverflow.com/questions/56135110/if-examples-has-too-many-columns-every-row-will-be-too-long-to-read