Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 814
Cyryl Płotnicki Avatar asked Feb 20 '11 12:02

Cyryl Płotnicki


People also ask

Can scenario outline have multiple examples?

Each scenario outline can have multiple tables with examples. The parameters in scenario outlines allow test runners to paste the examples from the table into the outline.

How do you write a multiple scenario outline in Cucumber?

Feature file can contain multiple scenarios or scenario outlines. We can write all possible Scenarios of a particular feature in a feature file. By using the keyword "Scenario" or "Scenario Outline", One Scenario can be separated from another.

Can we pass different data using scenario instead of scenario outline in Cucumber?

Scenario and Scenario Outline serve different purposes, they are written the same way but Scenario Outline takes user data in the form of Example table and run the scenario. So rather than duplicating same scenario with different data, one can write one Scenario Outline and write all data in Example table.


1 Answers

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.

like image 159
GSAN Avatar answered Nov 09 '22 01:11

GSAN