0

Wanted to ask for recommendation on how to implement one Cucumber scenarios in more then one way in Java.

Here is what I mean by that - suppose there is a scenario that I would like to be verified from backed (regular JUnit Test) and from GUI (Selenium-Webdriver). Is there any way I could create two scenario implementations and run each\both of them?

Thank you, Vlad

Vlad
  • 121
  • 1
  • 2
  • 7

1 Answers1

1

Not sure I understand your question, because there is no reason you cannot have two scenarios that do the same thing but essentially in different ways. You would have to describe the scenarios in slightly different ways ofcourse

Scenario: Given <>
          When I <something that indicates that it will be done via UI>
Scenario: Given <>
          When I <something that indicates that it will be done via backend.

The above is straightforward, but does have duplication.

Another way would be to create non capturing groups.

Scenario: Given <>
          When I (?:<run via UI>|<run via backend>)

And create steps for {run via UI} and {run via backend}

The success of the second method essentially depends on the DSL you use for the steps that are run via UI vs the backend. If the scenarios are intuitive enough it should be fine.

  • The idea is to test the same scenarios on different levels. On a code level against the core implementation on a rest level against the Rest API on a UI level against the UI. The same scenarios should be reused only the driver is different. I guess the Impelemtation of the steps should use a driver API for which you can have multiple implementations. E.g. UnitTests, Selenium, Rest etc. – Nils Rommelfanger Jul 14 '23 at 11:31