Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass List of strings from Cucumber Scenario

I need to pass the List of strings from cucumber scenario which works fine as below

Scenario Outline: Verify some scenario 
Given something
When user do something 
Then user should have some "<data>" 
Examples: Some example
|data|
|Test1, Test2, Test3, Test4|

In the step definition I use List to retrieve the values of something variable. But when one of the value of data variable contains comma(,) e.g. Tes,t4 it becomes complex,since it considers "Tes" and "t4" as two different values

 Examples: Some example
 |something|
 |Test1, Test2, Test3, Tes,t4|  

So is there any escape character that i can use or is there is there any other way to handle this situation

like image 573
Yogiraj Avatar asked Jul 11 '17 11:07

Yogiraj


People also ask

How do you pass string parameters in Cucumber?

When using the anonymous parameter type Cucumber will guess what you want to do based on the type of the argument. And this works for Boolean , String , Numbers , ect because they have a single way to writ them down. There are however many ways to write down a list of strings so Cucumber won't guess.

How do you pass multiple values in Cucumber?

When we have multiple test data to pass in a single step of a feature file, one way is to pass multiple parameters and another way is to use Data Tables. Data Tables is a data structure provided by cucumber. It helps you to get data from feature files to Step Definitions.


2 Answers

Found an easy way. Please see the below steps.

  • Here is my feature file.

    feature file

  • Here is the corresponding code to map feature step with code.

    code for the corresponding feature

  • Oh yes. Result is important. You can see the debug view.

    result in the debug view

like image 190
SUMIT Avatar answered Sep 21 '22 06:09

SUMIT


This should work for you:

Scenario: Verify some scenario 
Given something
When user do something 
Then user should have following
| Test1 |
| Test2 |
| Test3 |
| Tes,t4| 

In Step definitions

Then("^user should have following$")
 public void user_should_have_following(List<String> testData) throws Throwable {
 #TODO user your test data as desired
 }
like image 37
Ranjith's Avatar answered Sep 20 '22 06:09

Ranjith's