Selenide must throw error if soft assert is used without annotation #302

Closed
asolntsev opened this Issue Mar 6, 2016 · 5 comments

Projects

None yet

2 participants

@asolntsev
Member

For example, this test doesn't fail:

@test(description = "test")
public void test() throws Exception{
    System.out.println("Test started");
    try {
        Configuration.assertionMode = Configuration.AssertionMode.SOFT;
        $"#record_text_area").shouldHave(Condition.value("texts is changed!"));
        $"#record_text_area").shouldHave(Condition.value("users is changed!"));
    } catch (Exception e) {
        throw e;
    } finally {
        Configuration.assertionMode = Configuration.AssertionMode.STRICT;
        System.out.println("Test finished");
    }
}

But it should. See Selenide report:

Test started
+--------------------+----------------------------------------------------------------------+----------+----------+
|Element             |Subject                                                               |Status    |ms.       |
+--------------------+----------------------------------------------------------------------+----------+----------+
|#record_text_area   |should have(value 'texts is changed!')                                |FAIL      |4092      |
|#record_text_area   |should have(value 'users is changed!')                                |PASS      |28        |
+--------------------+----------------------------------------------------------------------+----------+----------+
Test finished

The problem is that annotation/listener is not added to the test (SoftAssert listener).

@asolntsev asolntsev self-assigned this Aug 4, 2016
@asolntsev asolntsev added this to the 3.8 milestone Aug 4, 2016
@asolntsev asolntsev added the lets do it label Aug 4, 2016
@asolntsev
Member

Now Selenide throws an exception in this case:

java.lang.IllegalStateException: Using soft asserts, but without @SoftAsserts annotation
    at com.codeborne.selenide.logevents.ErrorsCollector.validateAssertionMode(ErrorsCollector.java:45)
    at com.codeborne.selenide.impl.SelenideElementProxy.invoke(SelenideElementProxy.java:55)
    at com.sun.proxy.$Proxy10.shouldHave(Unknown Source)

or, for collections:

java.lang.IllegalStateException: Using soft asserts, but without @SoftAsserts annotation

    at com.codeborne.selenide.logevents.ErrorsCollector.validateAssertionMode(ErrorsCollector.java:45)
    at com.codeborne.selenide.ElementsCollection.should(ElementsCollection.java:54)
    at com.codeborne.selenide.ElementsCollection.shouldHave(ElementsCollection.java:50)
@asolntsev asolntsev closed this in 67dcb35 Aug 4, 2016
@asolntsev asolntsev added a commit that referenced this issue Aug 4, 2016
@asolntsev asolntsev #302 fix checkstyle issue 6487c23
@jasw
jasw commented Oct 26, 2016

Seen this exact error in 4.0 when upgrading from 3.5.1. Is it a known issue? Will try 3.8.

@asolntsev
Member

@jasw What error did you see? Do you mean IllegalStateException: Using soft asserts, but without @SoftAsserts annotation?

If yes, this is expected behaviour. Selenide should throw this error. You need to add @SoftAsserts (for JUnit) or SoftAsserts listener (for TestNG).

@jasw
jasw commented Oct 27, 2016 edited

Thanks @asolntsev . Do I need any other dependencies to get such annotation? The
only SoftAsserts I can see in selenide is a class not a annotation.

Or you mean as a rule?
@Rule public SoftAsserts softAsserts = new SoftAsserts();
Please clarify.

Regards

On Thu, 27 Oct 2016, 12:32 Andrei Solntsev notifications@github.com wrote:

@jasw https://github.com/jasw What error did you see? Do you mean IllegalStateException:
Using soft asserts, but without @SoftAsserts annotation?

If yes, this is expected behaviour. Selenide should throw this error. You
need to add @SoftAsserts (for JUnit) or SoftAsserts listener (for TestNG).


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#302 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAGlxakJIiBgeDXur8eTWnugul9TDEjSks5q3-MYgaJpZM4HqNjW
.

@BorisOsipov BorisOsipov added a commit to BorisOsipov/selenide that referenced this issue Nov 23, 2016
@asolntsev @BorisOsipov asolntsev + BorisOsipov Fixes #302 Selenide throws an error if soft assert is used without an…
…notation
823cfd0
@BorisOsipov BorisOsipov added a commit to BorisOsipov/selenide that referenced this issue Nov 23, 2016
@asolntsev @BorisOsipov asolntsev + BorisOsipov #302 fix checkstyle issue 11697b4
@asolntsev
Member

@jasw Sorry for the long delay.

See http://selenide.org/2015/05/05/selenide-2.16-and-2.17/

  1. To enable Soft asserts in JUnit (see example):
public class SoftAssertJUnitTest {
  @Rule public SoftAsserts softAsserts = new SoftAsserts();
  1. To enable Soft asserts in TestNG (see. example):
@Listeners(SoftAsserts.class)
public class SoftAssertTestNGTest {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment