Reputation: 121
Trying to see a working example on using Soft assertion in cucumber. I have the below simple feature and step definitions, i intentionally make some of the validation failed however the cucumber test still shows "PASSED". Am i doing something wrong here.
@Given("^I have a scenario for Soft assert$") public void i_have_a_scenario_for_soft_assert() throws Throwable {
System.out.println("Inside the given of soft assestion.. All Good");
}
@When("^I validate the first step for soft assertion$")
public void i_validate_the_first_step_for_soft_assertion() throws Throwable {
sa = new SoftAssertions();
System.out.println("Executing the FIRST");
sa.assertThat("bal".equalsIgnoreCase("BAL"));
System.out.println("Executing the SECOND");
sa.assertThat("bal".equalsIgnoreCase("AM"));
System.out.println("Executing the THIRD");
sa.assertThat("123".equalsIgnoreCase("321"));
}
@And("^i validate the second step for soft assertion$")
public void i_validate_the_second_step_for_soft_assertion() throws Throwable {
System.out.println("Second validation.. All Good");
}
@Then("^I complete my validation for soft assertion example$")
public void i_complete_my_validation_for_soft_assertion_example() throws Throwable {
sa.assertAll();
System.out.println("Final Validation.. All Good");
}
Upvotes: 0
Views: 1786
Reputation: 64
The sa.assertThat() method takes the actual value as parameter, and returns an assertion object that must be checked with one of the available methods. In your example, it must be checked with the isEqualToIgnoringCase(expected) method.
@Given("^I have a scenario for Soft assert$")
public void i_have_a_scenario_for_soft_assert() throws Throwable {
System.out.println("Inside the given of soft assestion.. All Good");
}
@When("^I validate the first step for soft assertion$")
public void i_validate_the_first_step_for_soft_assertion() throws Throwable {
sa = new SoftAssertions();
System.out.println("Executing the FIRST");
sa.assertThat("bal").isEqualToIgnoringCase("BAL");
System.out.println("Executing the SECOND");
sa.assertThat("bal").isEqualToIgnoringCase("AM");
System.out.println("Executing the THIRD");
sa.assertThat("123").isEqualToIgnoringCase("321");
}
@And("^i validate the second step for soft assertion$")
public void i_validate_the_second_step_for_soft_assertion() throws Throwable {
System.out.println("Second validation.. All Good");
}
@Then("^I complete my validation for soft assertion example$")
public void i_complete_my_validation_for_soft_assertion_example() throws Throwable {
sa.assertAll();
System.out.println("Final Validation.. All Good");
}
Upvotes: 0