Cucumber not identifying scenario without examples - cucumber

I have a gherkin scenario similar to following:
Scenario Outline: Test some behaviour
Given a set of preconditions
When an event occurs
Then my application has to behave in a particular manner
And respond as expected
When I execute this scenario my report says
0 Scenarios, 0 steps executed.
How ever when I execute a scenario with Examples, my setup works fine.
Am I missing something?

Scenario Outline is specific to Examples. If you swap to just Scenario you should be fine.

Related

Scenario outlines use multiply threads

I use JUnit5 and Cucumber in my tests. When running the tests in parallel, everything works as I want, but when it comes to the Scenario outline, the examples create additional threads. That is, if I set cucumber.execution.parallel.config.fixed.parallelism=4, the scenarios will run in 4 threads, but when they get to the Examples scenario, 1 additional thread is created for each example. How can I run a parallelism of exactly the scenarios and not the feature files? Or make the feature with scenario outline run one by one?
My junit-platform.properties
cucumber.publish.quiet=true
cucumber.execution.parallel.enabled=true
cucumber.execution.parallel.config.strategy=fixed
cucumber.execution.parallel.config.fixed.parallelism=4
A scenario outline is not a single scenario. It is multiple scenarios written in a compact form. When an outline is processed by cucumber it generates a standard scenario for each set of examples. Each example is going to run in its own thread.

Separate executions of BDD scenario outline examples in to different TestRail test cases (per example)

For reporting in to TestRail on automated BDD (cucumber-jvm) runs are using the Jenkins test rail plugin https://github.com/jenkinsci/testrail-plugin and we are getting false positives for test cases from scenario outlines.
The default implementation logs scenario outline example executions as multiple executions of the same test case in the same run. If the last example to run passed then the test case is passed for the run, even if all other examples actually failed.
Has anyone experienced this behaviour and did you find a way to change it so if any fail then the test case is failed or to list each example execution as a different test case?
I would report this behaviour to the authors of the plugin. The behaviour you describe is clearly very wrong.

Is there an equivalent to the Background section to run steps after scenarios?

When writing cucumber tests in gherkin one can define a series of steps, that will be executed before each scenario
I could not find any equivalent to that for running a series of steps after each scenario.
My use case would be:
Background:
- login
- go to products page
- select product
Scenario Outline:
- Configure product in different ways
Examples:
| options |
| values |
After Each:
- go to checkout
- fill in personal data
- fill in payment data
- submit
Is there such an equivalent option that I missed in the docs?
There isn't an after equivalent by design. The point of each scenario in Cucumber is to drive the development of a particular bit of behaviour specified by the When. Because new behaviour mostly builds on existing behaviour its expected that a number of scenarios will have a common background. For example if you are writing scenarios about signing into a website (good sign in, bad password, forgotten password ...), your users will have to be registered.
The Then in a scenario is to assert that the When has worked. Anything after that should be in a different scenario.
So your examples could be
Given a product is configured with ...
When I buy the product
Then ...
All the after stuff gets moved into the before stuff, and possibly the When.

Gherkin: Is it correct to repeat steps?

I am reading a lot about Gherkin, and I had already read that it was not good to repeat steps, and for this it is necessary to use the keyword "Background", but in the example of this page they are repeating the same "Given" again and again, Could it be that I am doing wrong? I need to know your opinion about it:
Like with several things, this a topic that will generate different opinions. On this particular example I would have moved the "Given that I select the post" to the Background section as this seems to be a pre-requisite to all scenarios on this feature. Of course this would leave the scenarios in the feature without an actual Given section but those would be incorporated from the Background section on execution.
I have also seen cases where sometimes the decision of moving steps to the Background is a trade-off between having more or less feature files and how these are structured. For example, if there are 10 scenarios for a particular feature with a lot of similar steps between them - but there are 1 or 2 scenarios which do not require a particular step, then those 1 or 2 scenarios would have to moved into a new feature file in order to have the exact same steps on the Background section of the original feature.
Of course it is correct to keep the scenarios like this. From a tester's perspective, the Scenarios/Test cases should run independently, therefore, you can keep these tests separately for each functionality.
But in case you are doing an integration testing, then some of these test cases can be merged, thus you can cover multiple test cases in one scenario.
And the "given" statement is repeating, therefore you can put that in the background, so you don't have to call it in each scenarios.
Note: These separate scenarios will be handy when you run the scripts separately with annotation tags, when you just have to check for a specific functionality, or a bug fix.

How to implement If condition in Cucumber Scenarios

I have a specific scenario as follows:
if (element shows up on UI)
validate it
else
no harm done; move on...
If I know upfront if the element shows up or not, I can frame two different scenarios, when the element shows up and when not.
But, in this case, it may or may not be present. If it is present, it should function as expected.
Any suggestions on how this can be implemented in a Cucumber scenario(s) ?
I am using Cucumber-jvm.
You have two separate scenarios, you just need to be able to make sure you setup the preconditions to assume one scenario vs the other.
In general, you should not be implementing a conditional inside a single scenario, because your intent is to test two scenarios.

Resources