-
-
Notifications
You must be signed in to change notification settings - Fork 694
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
allow more steps to execute after step failure #2161
Comments
I moved this to the common repo because I think it's a broader thing. There's no mechanism to retroactively amend the result status of a step, and I don't think this is something we would do anyway because it would break the contract with formatters that consume results as they happen and expect them to be immutable. @mattwynne @mpkorstanje @luke-hill has this handling of soft assertions come up before in other flavours? |
It is sometimes requested. Though for most, making the soft assertions hard after the scenario is done seems to suffice.Looking at the essence of the problem I'm seeing the following requirements:
And the last one is the essence of the request. Unlike Playwright Cucumber doesn't tightly integrate its own assertion library so we can't just collect the problems after the test step, mark it as failed and continue. For pending steps we use a dedicated pending exception. But we can't really tell the difference between an exception thrown by making a soft assertion hard, and a regular assertion. Or for that matter, soft assertions made hard with the purpose of failing the step. So we'd need a mechanism to mark certain exceptions as "soft". Let's suppose we have the following step definitions for Java using AssertJs public class StepDefinitions {
SoftAssertions softly = new SoftAssertions();
@Given("I have {int} cukes in my belly")
public void I_have_cukes_in_my_belly(int cukes) {
// stuff
}
@When("I wait {int} hour")
public void i_wait_hour(Integer int1) {
Duration waited = /* stuff */;
softly.assertThat(waited).isCloseTo(ofHours(1), ofSeconds(10));
}
@Then("my belly should growl")
public void my_belly_should_growl() throws InterruptedException {
// stuff
}
} Wrapping with a dedicated exception @AfterStep
public void assertSoftly(){
Cucumber.throwSoftly(() -> softly.assertAll());
} By using Marking a hook or steps as failing softly @AfterStep
@ContinueOn(AssertionFailedError.class)
public void assertSoftly(){
softly.assertAll();
} Same idea as above, but now Cucumber will treat any @When(value = "I wait {int} hour")
@ContinueOn(AssertionFailedError.class)
public void i_wait_hour(Integer int1) {
Duration waited = /* stuff */;
assertThat(waited).isCloseTo(ofHours(1), ofSeconds(10));
} And that could also be done for whole steps. @When(value = "I wait {int} hour")
@ContinueOn(AssertionFailedError.class)
public void i_wait_hour(Integer int1) {
Duration waited = /* stuff */;
assertAll(
() -> assertThat(waited).isCloseTo(ofHours(1), ofSeconds(10)),
() -> /* something else */
);
} To continue on and test multiple assertions, use |
The first time I heard about soft assertions was in 2013 with selenium IDE (Legacy), where you had Imo the best way to solve this would be in your assertion library, switching that to just doing something like
|
@luke-hill that means the exceptions won't show up in any of the cucumber reports though. Unless Ruby works differently, in that case I'd like to know how. 😄 |
Agreed. The actual mechanics of it - a certain type of exception, extra support code or config, etc - would be down to the implementation per platform norms and probably not too hard. But my thought is more, are we okay with marking a step failed and then doing more steps within a test case attempt? If so, do we need anything extra in messages? I'm leaning to yes and no respectively - I don't think this breaks any contract per se. |
For now we have a workaround logic by capturing the error using try catch and storing it in Error array and doing an assertion at @after to check if array has more than 0 and displaying the captured errors. By this way the error is captured, step get passed and continue and fail is reported at after. Cucumber report is not looking good by this way as it shows step as passed inspite of error captured and reporting them at after hooks. couldnt refer to which step the error relates to as well as pickleStep from ITestStepHookParameter are available only at AfterStep
After
|
I agree with the conclusion but it is definitely a breaking change. Tools that collate steps into test cases will not have to deal with the possibility that there are multiple failing steps(i.e. multiple |
My suggestion is that we create a new step result status of A I don't see why we couldn't make I agree that the implications of this change are breaking and a bit hard to predict. I suggest we run some kind of exploratory spike in cucumber-js before we commit to adding it to the message protocol etc. |
I'm not sure I agree re At any rate, I think we're agreed across the core team that a first step would be to experiment in cucumber-js with allowing this - without a particular focus on the mechanism and interface for doing so - and see what effects there would be on formatters and plugins. I'm leaving it unassigned though as it's unlikely to be a high enough priority to get serious attention in the short term. We can direct people with similar asks here and start to gauge the demand. |
🤔 What's the problem you're trying to solve?
Playwright soft assertions are not working with cucumber runner. They work well with playwright runner.
✨ What's your proposed solution?
Looking for option to capture error and set status manually as Failed when soft exception occurs and continue the testing steps.
⛏ Have you considered any alternatives or workarounds?
Tried by capturing the exception and print at end of After hooks and fail test there but still not satisfier compared with soft assertion which fails the test step but still continues the test. Tried custom method for capturing error and assigning test step status as failure but current cucumber library doesn't allow that
📚 Any additional context?
Please let me know if there alternate option available within cucumber to fail step for soft assert type error and still continue execution. If we are able to update the error programmatically and still continue the process will also help.
This text was originally generated from a template, then edited by hand. You can modify the template here.
The text was updated successfully, but these errors were encountered: