If examples has too many columns ,every row will be too long to read!

假如想象 提交于 2019-12-12 18:47:01

问题


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

  1. As you asked we can define the Examples: tables before Scenario 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!