-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…e-messages #280 configuration for selenide messages
- Loading branch information
Showing
6 changed files
with
147 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
src/main/java/com/xceptance/neodymium/errorformatter/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package com.xceptance.neodymium.errorformatter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/main/java/com/xceptance/neodymium/util/SelenideErrorDetailsFormatter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.xceptance.neodymium.util; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
import com.codeborne.selenide.Driver; | ||
import com.codeborne.selenide.ex.SelenideErrorFormatter; | ||
import com.codeborne.selenide.impl.Screenshot; | ||
|
||
public class SelenideErrorDetailsFormatter extends SelenideErrorFormatter | ||
{ | ||
@Nonnull | ||
@Override | ||
public String generateErrorDetails(AssertionError error, Driver driver, Screenshot screenshot, long timeoutMs) | ||
{ | ||
|
||
if (Neodymium.configuration().showSelenideErrorDetails()) | ||
{ | ||
return super.generateErrorDetails(error, driver, screenshot, timeoutMs); | ||
} | ||
|
||
// The screenshot path is always unique. Also the caused by message is dependent on the browser, so just ignore | ||
// those. | ||
// Timeout might be interesting, but to keep the message clean we add it as a step parameter to the current step | ||
StringBuilder sb = new StringBuilder(); | ||
return sb.append("(") | ||
.append(timeout(timeoutMs)) | ||
.append(")") | ||
.toString(); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
src/main/resources/META-INF/services/com.codeborne.selenide.ex.ErrorFormatter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
com.xceptance.neodymium.util.SelenideErrorDetailsFormatter |
108 changes: 108 additions & 0 deletions
108
src/test/java/com/xceptance/neodymium/util/SelenideErrorDetailsFormatterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package com.xceptance.neodymium.util; | ||
|
||
import static com.codeborne.selenide.Condition.exist; | ||
import static com.codeborne.selenide.Selenide.$; | ||
import static com.codeborne.selenide.Selenide.$$; | ||
import static com.codeborne.selenide.Selenide.open; | ||
|
||
import java.time.Duration; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
|
||
import com.codeborne.selenide.CollectionCondition; | ||
import com.xceptance.neodymium.common.browser.Browser; | ||
import com.xceptance.neodymium.junit5.NeodymiumTest; | ||
|
||
@Browser("Chrome_headless") | ||
public class SelenideErrorDetailsFormatterTest | ||
{ | ||
@NeodymiumTest | ||
public void testErrorDetailesDeactivated() | ||
{ | ||
Neodymium.configuration().setProperty("neodymium.report.showSelenideErrorDetails", "false"); | ||
Assertions.assertFalse(Neodymium.configuration().showSelenideErrorDetails()); | ||
|
||
open("http://www.xceptance.com"); | ||
try | ||
{ | ||
$("#someUnknownIDForThisSepcificTest").should(exist, Duration.ZERO); | ||
Assertions.fail("Expected an AssertionError, which was not thrown!"); | ||
} | ||
catch (AssertionError e) | ||
{ | ||
Assertions.assertEquals("Element not found {#someUnknownIDForThisSepcificTest}\n" | ||
+ "Expected: exist\n" | ||
+ "(Timeout: 0 ms.)", e.getMessage(), "Wrong exception Message catched!"); | ||
} | ||
} | ||
|
||
@NeodymiumTest | ||
public void testErrorDetailesActivated() | ||
{ | ||
Neodymium.configuration().setProperty("neodymium.report.showSelenideErrorDetails", "true"); | ||
Assertions.assertTrue(Neodymium.configuration().showSelenideErrorDetails()); | ||
|
||
try | ||
{ | ||
$("#someUnknownIDForThisSepcificTest").should(exist, Duration.ZERO); | ||
Assertions.fail("Expected an AssertionError, which was not thrown!"); | ||
} | ||
catch (AssertionError e) | ||
{ | ||
assertExpectedMessageContains(e.getMessage(), "Element not found {#someUnknownIDForThisSepcificTest}\n"); | ||
assertExpectedMessageContains(e.getMessage(), "Expected: exist\n"); | ||
assertExpectedMessageContains(e.getMessage(), "Screenshot: "); | ||
assertExpectedMessageContains(e.getMessage(), "Page source: "); | ||
assertExpectedMessageContains(e.getMessage(), "Timeout: 0 ms.\n"); | ||
assertExpectedMessageContains(e.getMessage(), | ||
"Caused by: NoSuchElementException: no such element: Unable to locate element: {\"method\":\"css selector\",\"selector\":\"#someUnknownIDForThisSepcificTest\"}"); | ||
} | ||
} | ||
|
||
@NeodymiumTest | ||
public void testCollectionErrorDetailesDeactivated() | ||
{ | ||
Neodymium.configuration().setProperty("neodymium.report.showSelenideErrorDetails", "false"); | ||
Assertions.assertFalse(Neodymium.configuration().showSelenideErrorDetails()); | ||
|
||
open("http://www.xceptance.com"); | ||
try | ||
{ | ||
$$("#someUnknownIDForThisSepcificTest").shouldHave(CollectionCondition.sizeGreaterThan(5), Duration.ZERO); | ||
Assertions.fail("Expected an AssertionError, which was not thrown!"); | ||
} | ||
catch (AssertionError e) | ||
{ | ||
Assertions.assertEquals("List size mismatch: expected: > 5, actual: 0, collection: #someUnknownIDForThisSepcificTest\n" | ||
+ "(Timeout: 0 ms.)", e.getMessage(), "Wrong exception Message catched!"); | ||
} | ||
} | ||
|
||
@NeodymiumTest | ||
public void testCollectionErrorDetailesActivated() | ||
{ | ||
Neodymium.configuration().setProperty("neodymium.report.showSelenideErrorDetails", "true"); | ||
Assertions.assertTrue(Neodymium.configuration().showSelenideErrorDetails()); | ||
|
||
try | ||
{ | ||
$$("#someUnknownIDForThisSepcificTest").shouldHave(CollectionCondition.sizeGreaterThan(5), Duration.ZERO); | ||
Assertions.fail("Expected an AssertionError, which was not thrown!"); | ||
} | ||
catch (AssertionError e) | ||
{ | ||
System.out.println(e.getMessage()); | ||
assertExpectedMessageContains(e.getMessage(), "List size mismatch: expected: > 5, actual: 0, collection: #someUnknownIDForThisSepcificTest\n"); | ||
assertExpectedMessageContains(e.getMessage(), "Screenshot: "); | ||
assertExpectedMessageContains(e.getMessage(), "Page source: "); | ||
assertExpectedMessageContains(e.getMessage(), "Timeout: 0 ms."); | ||
} | ||
} | ||
|
||
private void assertExpectedMessageContains(String errorMessage, String expectedContent) | ||
{ | ||
Assertions.assertTrue(errorMessage.contains(expectedContent), | ||
"Unexpected exception Message catched: " + errorMessage + "\n, missing content: " + expectedContent); | ||
} | ||
|
||
} |