本文介绍了如果示例的列过多,则每一行都将太长而无法阅读!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果示例的列过多,则每一行都将太长而无法阅读!

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 |

会不会是这样:

Feature:

  Background:
    Examples:
    | prefix |
    | hello  |

  Scenario Outline:
    * match '<msg>' == <prefix> + ',' + '<end>'
    Examples:
      | end   | msg         |
      | mike  | hello,mike  |
      | jerry | hello,jerry |

我想将示例分成几部分,或者在Outline之前设置一个基础示例.我该怎么办?

I want to divide the examples in several parts, or set a base examples before Outline.What should I do?

推荐答案

空手道在其最新版本0.9.X中以多种方式解决了这一问题,让我们看看

karate address this in many different ways in its latest versions 0.9.X, Let see

  1. 按照您的要求,我们可以在Scenario Outline:之前使用定义Examples:表空手道,
  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将所有这些tableExamples:视为JSON的数组

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

如果您觉得示例太大而无法容纳在功能文件中,请将其保存在csv文件中,并在Examples

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 |

这同样适用于JSON,它以JSON数组的形式提供数据.

The same applies to JSON also, providing data as JSON array.

这篇关于如果示例的列过多,则每一行都将太长而无法阅读!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 18:19