I have the following scenario:
Scenario Outline: Searching for something on Google
Given user goes to google.com
When user search for "<something>"
Then <somethingHappens>
I would like to prevent Then <somethingHappens>
from being executed if a condition in When user search for "<something>"
is not met.
Let say that google does not find something, how do I stop the execution of the test?
I found some post saying that this is not the way Cucumber works. Instead, I'd rather create another scenario that would match what I'm looking for. Is that correct?
Thanks in advance for your help
There are few ways you gan go:
Scenario Outline: Searching for something on Google
Given user goes to google.com
When user search for "<something>"
And there are results returned
Then <somethingHappens>
and
Scenario Outline: Searching for something on Google
Given user goes to google.com
When user search for "<something>"
And there are no results returned
Then <nothingHappens>
Hence your logic would look more like a test..
@When("user search for something")
public void when(){
boolean condition = testForConditionMet();
Assume.assumeTrue(condition)
}
The above code would make your test skip
if condition is false
.
If you would like to fail the test then use Assert.assertTrue(condition
) instead of Assume
.
I would not recommend to use the second approach since you are stuck to unit-test framework in that case.