0

For example, I have two steps. This is just an example, my step definitions, originally these are written in Russian language:

When I press the button "Enter"

When I have pressed the button "Enter"

So, as the result we have two methods:

@When("^I press the button \"([^\"]*)\"$")
public void iPressTheButton(String arg1){ }

@When("^I have pressed the button \"([^\"]*)\"$")
public void iHavePressedTheButton(String arg1){ }

The main idea is, that these two methods do the same thing, but due to lexical difference of the description I can't unify them. So, maybe, I need to do something with regExp? In fact we need to say something like that: "If we have 'I press' or 'I have pressed' in the begining of the phrase (... button \"([^\"]*)\"), then we call the function".

Or there is some way to do something with annotations?

1
  1. In cases where the implied behaviour of the step is identical; simply rewrite the Gherkin/feature file so that it is consistent.
  2. BDD steps should be written in the third person impersonal form.
  3. BDD steps should be written in a style that focuses on the objective and not in an imperative programming style. What does 'pressing enter' achieve and use that objective.
  4. Reconsider if you really need to parametrise "Enter".
  5. You need to learn regular expressions, a few examples.

    (?:is|are) - will match 'is' or 'are'.
    (?:the|an) - will match either 'the' or 'an' but not capture.
    Cats? - will match Cat or Cats.
    Colou?r - will match British Colour or American Color.

  • I strongly question the third person form. First person is far more common and officially preferred, IME. As evidence of this, look at the documentation on Gherkin from the Cucumber github project: github.com/cucumber/cucumber/blob/master/docs/gherkin.md "The Cucumber Book" also uses the first person convention. Upvoted mainly for regex advice - you can easily resolve these grammar issues with regexes in most cases. agileforall.com/just-enough-regular-expressions-for-cucumber is a great starting place and easier to read than the article linked above. – Ethel Evans Feb 16 '17 at 23:31
  • First person pronouns are common, they most certainly are not 'official preferred'. It is considered a BDD Anti-Pattern. First person pronouns are the same as get/set or webDriver directly in steps. Used to help newbies learn, not as exemplars of best practice. The stories do not concern you, they concern the identified role. They lead to imperative steps 'I do Y'. Avoiding the first person opens the mind to richer scenarios based on objectives. – Martin Spamer Feb 16 '17 at 23:56
  • 1
    Thank you for the link - I see the value of reflecting multiple actors using third-person now. Especially like the idea of tying user story names into the UATs. I think the first person convention has been so common in my experience due to working primarily on back-end services that are consumed by other services, so the most relevant "human" story we have is often one about another developer trying to use our service(s) manually before writing software to integrate with them. In that case, the "I" language is less problematic. – Ethel Evans Feb 17 '17 at 0:12
0

Above problem you are referring to, those two can't be unified its same like created two different methods in Java for the same problem statement. Instead you can refer to below for getting better at describing test in feature file. https://saucelabs.com/blog/write-great-cucumber-tests

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.