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

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

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

Comments

Projects
None yet
4 participants
@asolntsev
Member

asolntsev commented Mar 6, 2016

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

This comment has been minimized.

Show comment
Hide comment
@asolntsev

asolntsev Aug 4, 2016

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)
Member

asolntsev commented Aug 4, 2016

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 added a commit that referenced this issue Aug 4, 2016

@jasw

This comment has been minimized.

Show comment
Hide comment
@jasw

jasw 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.

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

This comment has been minimized.

Show comment
Hide comment
@asolntsev

asolntsev Oct 26, 2016

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).

Member

asolntsev commented Oct 26, 2016

@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

This comment has been minimized.

Show comment
Hide comment
@jasw

jasw Oct 27, 2016

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
.

jasw commented Oct 27, 2016

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 added a commit to BorisOsipov/selenide that referenced this issue Nov 23, 2016

BorisOsipov added a commit to BorisOsipov/selenide that referenced this issue Nov 23, 2016

@asolntsev

This comment has been minimized.

Show comment
Hide comment
@asolntsev

asolntsev Nov 29, 2016

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 {
Member

asolntsev commented Nov 29, 2016

@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 {
@karol1204

This comment has been minimized.

Show comment
Hide comment
@karol1204

karol1204 Sep 6, 2018

To enable Soft asserts in JUnit (see example):
public class SoftAssertJUnitTest {
@rule public SoftAsserts softAsserts = new SoftAsserts();

It works for jUnit4, how to use it for jUnit5?

karol1204 commented Sep 6, 2018

To enable Soft asserts in JUnit (see example):
public class SoftAssertJUnitTest {
@rule public SoftAsserts softAsserts = new SoftAsserts();

It works for jUnit4, how to use it for jUnit5?

@rosolko

This comment has been minimized.

Show comment
Hide comment
Collaborator

rosolko commented Sep 6, 2018

@asolntsev asolntsev removed the help wanted label Sep 7, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment