Comment obtenir des chaînes multilignes dans des exemples de contour des scénarios dans les tests de concombre au travail?

StackOverflow https://stackoverflow.com/questions/5056976

  •  15-11-2019
  •  | 
  •  

Question

J'aimerais utiliser des chaînes multilignes dans la section Exemples du contour des scénarios. Comment faire ça?

EG

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

Il n'a pas l'air propre, ni fonctionne

Était-ce utile?

La solution

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.

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.

Autres conseils

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.

I did it in Grails, but should be very similar:

Method to read the file

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

Json file

"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.

Have you considered using \n in your strings to denote the carriage return?

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top