Skip to content

Commit

Permalink
Fixes #364 #303 class SoftAsserts is now thread-safe
Browse files Browse the repository at this point in the history
it doesn't hold a single instance of ErrorsCollector, but creates a new one for every test
  • Loading branch information
asolntsev committed Aug 3, 2016
1 parent 09f1e16 commit 566022e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/main/java/com/codeborne/selenide/testng/SoftAsserts.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
* Annotate your test class with {@code @Listeners({ SoftAsserts.class})}
*/
public class SoftAsserts extends ExitCodeListener {
private final ErrorsCollector errorsCollector = new ErrorsCollector();

public SoftAsserts() {
SelenideLogger.addListener("softAssert", errorsCollector);
@Override
public void onTestStart(ITestResult result) {
super.onTestStart(result);
SelenideLogger.addListener("softAssert", new ErrorsCollector());
}

@Override
Expand Down Expand Up @@ -40,6 +40,7 @@ public void onConfigurationFailure(ITestResult result) {
}

private void failIfErrors(ITestResult result) {
ErrorsCollector errorsCollector = SelenideLogger.removeListener("softAssert");
errorsCollector.failIfErrors(result.getTestClass().getName() + '.' + result.getName());
}
}
24 changes: 23 additions & 1 deletion src/test/java/integration/testng/SoftAssertTestNGTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,34 @@ public void resetDefaultProperties() {
Configuration.timeout = 4000;
}

@Test(enabled = false)
@Test//(enabled = false)
public void userCanUseSoftAssertWithTestNG() {
$("#radioButtons input").shouldHave(value("777"));
$("#xxx").shouldBe(visible);
$$("#radioButtons input").shouldHave(size(888));
$("#radioButtons").$$("input").shouldHave(size(999));
$("#radioButtons select").click();
}

@Test
public void successfulTest() {
}

@Test//(enabled = false)
public void userCanUseSoftAssert2() {
$("#radioButtons input").shouldHave(value("777"));
$("#xxx").shouldBe(visible);
$$("#radioButtons input").shouldHave(size(888));
$("#radioButtons").$$("input").shouldHave(size(999));
$("#radioButtons select").click();
}

@Test//(enabled = false)
public void userCanUseSoftAssert3() {
$("#radioButtons input").shouldHave(value("777"));
$("#xxx").shouldBe(visible);
$$("#radioButtons input").shouldHave(size(888));
$("#radioButtons").$$("input").shouldHave(size(999));
$("#radioButtons select").click();
}
}

0 comments on commit 566022e

Please sign in to comment.