Forum Discussion

julien-le-foll's avatar
julien-le-foll
New Contributor
4 years ago
Solved

Scenario Outline: parameters are converted to string when the feature is uploaded to cucumberStudio

Hello,

Given the following feature file:

Feature: numeric arguments are lost

Scenario Outline: show loss of numeric types
Given a price of <price>
And the price parameter is an int in step implementation
When the scenario is uploaded to cucumberStudio
Then the price parameter becomes a string

Examples:
| price |
| 30 |
| 40 |

And a java step definition such as:

@Given("a price of {int}")
public void a_price_of(Integer int1) {
//
}

When the feature file is uploaded to cucumberStudio

And the feature file is generated for a given test run

Then the step become "Given a price of "<price>"" (additional quotes around the parameter)

And cucumber expect this definition:

@Given("a price of {String}")
public void a_price_of(String price) {
//
}

 

How to keep numeric types for step parameters?

 

Note the feature file generated by hiptest-publisher is:

Feature: numeric arguments are lost


Scenario Outline: show loss of numeric types (<hiptest-uid>)
Given a price of "<price>"
And the price parameter is an int in step implementation
When the scenario is uploaded to cucumberStudio
Then the price parameter becomes a string

Examples:
| price | hiptest-uid |
| 30 | uid:61e34ec9-130f-49de-b8ab-8a007c11d1ce |
| 40 | uid:ecc15e25-fc84-48cc-a79c-1092df7d44ce |
  • julien-le-foll's avatar
    julien-le-foll
    4 years ago

    Hello,

     

    Finally your R&D show me a better solution:

    • In CucumberStudio set 0 as default value for numeric parameter (add = 0)
    • and the following step implementation can be used:
    @Given("a price of "(.*)"$")
        public void a_price_of(double price) {
            //....
        }

     

    The deal is that numeric types can't be used in annotations but it is acceptable

4 Replies

  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)

    Hi julien-le-foll,

    Thanks for submitting your question to the CucumberStudio community. I was told that you are already working with the R&D team on this topic. Please continue working with them and share the solution with us. 

    • julien-le-foll's avatar
      julien-le-foll
      New Contributor

      Hello,

       

      R&D replied me that they won't be able to fix it quickly.

      For the time being here the workaround that I suggested to our dev team:

      1/ use string parameter in feature files such as:

      Feature: numeric arguments are lost
      
        Scenario Outline: show loss of numeric types
          Given a price of "<price>"
          And the price parameter is an int in step implementation
          When the scenario is uploaded to cucumberStudio
          Then the price parameter becomes a string
      
          Examples:
          | price |
          | 30 |
          | 40 |

      2/ Parse strings in step's implementation:

      @Given("a price of {string}")
          public void a_price_of(String sInt1) {
              int int1 = Integer.parseInt(sInt1);
              //....
          }

       

      • julien-le-foll's avatar
        julien-le-foll
        New Contributor

        Hello,

         

        Finally your R&D show me a better solution:

        • In CucumberStudio set 0 as default value for numeric parameter (add = 0)
        • and the following step implementation can be used:
        @Given("a price of "(.*)"$")
            public void a_price_of(double price) {
                //....
            }

         

        The deal is that numeric types can't be used in annotations but it is acceptable