Skip to content

Commit

Permalink
Merge pull request #281 from Xceptance/#280-configuration-for-selenid…
Browse files Browse the repository at this point in the history
…e-messages

#280 configuration for selenide messages
  • Loading branch information
wurzelkuchen authored Nov 22, 2024
2 parents 2a4a003 + c08f931 commit 97d7a2e
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 2 deletions.
4 changes: 3 additions & 1 deletion config/neodymium.properties
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ neodymium.report.enableTestDataInReport = true
# The password of the root certificate for the MITM proxy
# neodymium.localproxy.certificate.password = MITMCertificatePassword


#############################
#
# Allure Report properties
Expand All @@ -359,6 +360,8 @@ neodymium.report.enableTestDataInReport = true
# Enable the saving of links of called pages in the report
# neodymium.report.enableStepLinks =

neodymium.report.showSelenideErrorDetails = false


#############################
#
Expand All @@ -375,4 +378,3 @@ neodymium.report.enableTestDataInReport = true
# The delay between two checks for a popup in milliseconds
#neodymium.popupInterval = 1000


Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package com.xceptance.neodymium.errorformatter;
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,10 @@ public interface NeodymiumConfiguration extends Mutable
@Key("neodymium.logNeoVersion")
@DefaultValue("true")
public boolean logNeoVersion();

@Key("neodymium.report.showSelenideErrorDetails")
@DefaultValue("false")
public boolean showSelenideErrorDetails();

@Key("neodymium.report.enableTestDataInReport")
@DefaultValue("true")
Expand Down Expand Up @@ -355,5 +359,4 @@ public interface NeodymiumConfiguration extends Mutable
@Key("neodymium.popupInterval")
@DefaultValue("1000")
public int getPopupBlockerInterval();

}
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();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
com.xceptance.neodymium.util.SelenideErrorDetailsFormatter
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);
}

}

0 comments on commit 97d7a2e

Please sign in to comment.