简体   繁体   English

如何使黄瓜测试中的“方案大纲”中的“示例”中的多行字符串起作用?

[英]How to get multiline strings in Examples in Scenario Outline in cucumber tests to work?

I would like to use multiline strings in the Examples section of The Scenario Outline. 我想在“方案大纲”的“示例”部分中使用多行字符串。 How to do that ? 怎么做 ?

eg 例如

Scenario Outline:
  Given something
  When `<action>` happens
    I should get elaborative `<duuh>`
  Examples:
    |action|duuh|
    |"""
    tututuut
    """|"""blablabla m
    ultiline"""|

it does not look clean neither works 它看起来不干净也不起作用

I prioritize the cucumber output , not the Gherkin input , although first prize is for both to be beautiful. 我将黄瓜的输出放在优先位置,而不是小黄瓜的输入放在了首位,尽管两者都是一等奖。 So multiline example values don't make sense for me, because they absolutely wreck the cucumber output. 因此,多行示例值对我来说没有意义,因为它们绝对破坏了黄瓜的输出。

Cucumber encourages readable output for multiline data with doc strings . 黄瓜鼓励带有文档字符串的多行数据的可读输出。 It encourages readable output for data matrices with scenario outlines . 它鼓励带有方案概述的数据矩阵的可读输出。 I don't think it encourages readable output of multiline data matrices. 我认为这不鼓励多行数据矩阵的可读输出。

If you could come up with great examples of how the output would look in such cases, they might be well received on the Cukes forum . 如果您能提出很好的例子说明这种情况下的输出结果,那么在Cukes论坛上可能会收到好评。

Alternatively, if all you're trying to do is iterate over multiline data in your Cucumber features, come up with mnemonic names for the multiline data, provide those mnemonics in the Examples matrix of your Scenario Outline , and treat the mnemonics as the names of fixture files that you read for the actual data in your glue code. 另外,如果您要做的只是遍历Cucumber功能中的多行数据,请为多行数据提供助记符名称,在“ Scenario Outline的“ Examples矩阵中提供这些助记符,然后将助记符视为您为粘合代码中的实际数据读取的夹具文件。

What I did, was to separate the long strings in files (in my case it was pieces of json) and when I need the strings, I just load the needed file. 我所做的是将文件中的长字符串分开(在我的情况下是json片段),当我需要字符串时,我只是加载了所需的文件。

I did it in Grails, but should be very similar: 我在Grails中做到了,但应该非常相似:

Method to read the file 读取文件的方法

static String getMockJsonFile(String fileName){
    new File("${BOOKING_JSON_FILES_PATH}${fileName}.json").text
}

Json file Json文件

"collectionSummary": {
"attempts": [
{
"collectionMethod": {
"creditCardCollectionMethod": {
"id": 2,
"collectionMethodType": "CREDITCARD",
"creditCardType": {
"code": "CA",
"name": "Master Card Credit"
}
}
},
"billingCurrency": "EUR"
}
],
"creationDate": "2017-05-30 14:46:19",
"currency": "EUR",
"collectedAmount": 9.1
}

If you set """ triple quotes in the file, the string result will have it too. 如果在文件中设置““”三引号,则字符串结果也将具有它。

您是否考虑过在字符串中使用\\ n表示回车?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM