diff --git a/junit5/src/main/java/com/github/automatedowl/tools/JSErrorsExtension.java b/junit5/src/main/java/com/github/automatedowl/tools/JSErrorsExtension.java index fe277c1..729df18 100644 --- a/junit5/src/main/java/com/github/automatedowl/tools/JSErrorsExtension.java +++ b/junit5/src/main/java/com/github/automatedowl/tools/JSErrorsExtension.java @@ -49,13 +49,13 @@ public void afterTestExecution(ExtensionContext context) { // Check for JS errors assertion boolean flag. // Skip error throwing in case of negative unit test. - if (isAssertJSErrorsEnabled(context) && getJSErrorsFromLogEntries(logEntries).anyMatch(e -> true) + if (isAssertJSErrorsEnabled(context) && getJSErrorsFromLogEntries(logEntries).count()!=0 && context.getTestClass().toString().contains("com.github.automatedowl") && context.getRequiredTestMethod().getName().equals("referenceErrorTest")) { assertThrows(WebDriverException.class, ()->{ throw new WebDriverException(JS_ERRORS_EXCEPTION_STRING); }); - } else if (isAssertJSErrorsEnabled(context) && getJSErrorsFromLogEntries(logEntries).anyMatch(e -> true)) { + } else if (isAssertJSErrorsEnabled(context) && getJSErrorsFromLogEntries(logEntries).count()!=0) { throw new WebDriverException(JS_ERRORS_EXCEPTION_STRING); } } diff --git a/testng/src/main/java/com/github/automatedowl/tools/JSErrorsCollectorListener.java b/testng/src/main/java/com/github/automatedowl/tools/JSErrorsCollectorListener.java index ca616b6..95d1aad 100644 --- a/testng/src/main/java/com/github/automatedowl/tools/JSErrorsCollectorListener.java +++ b/testng/src/main/java/com/github/automatedowl/tools/JSErrorsCollectorListener.java @@ -1,7 +1,6 @@ package com.github.automatedowl.tools; import com.github.automatedowl.tools.drivers.testngholder.JSErrorsDriverHolder; -import org.openqa.selenium.WebDriverException; import org.openqa.selenium.logging.LogEntry; import org.openqa.selenium.logging.LogType; import org.testng.*; @@ -10,6 +9,7 @@ import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.stream.Collectors; import java.util.stream.Stream; /** TestNG listener for JSErrorsCollectorTestNG annotation. @@ -54,7 +54,7 @@ public void afterInvocation(IInvokedMethod iInvokedMethod, ITestResult iTestResu // Check for JS errors assertion boolean flag. // Skip error throwing in case of negative unit test. if (isAssertJSErrorsEnabled( - iInvokedMethod) && getJSErrorsFromLogEntries(logEntries).anyMatch(e -> true) + iInvokedMethod) && getJSErrorsFromLogEntries(logEntries).count()!=0 && iInvokedMethod .getTestMethod().getTestClass().toString().contains("com.github.automatedowl") && iInvokedMethod @@ -62,9 +62,9 @@ public void afterInvocation(IInvokedMethod iInvokedMethod, ITestResult iTestResu // Don't throw exception on unit test. } else if (isAssertJSErrorsEnabled( - iInvokedMethod) && getJSErrorsFromLogEntries(logEntries).anyMatch(e -> true)) { + iInvokedMethod) && getJSErrorsFromLogEntries(logEntries).count()!=0) { logger.severe(JS_ERRORS_EXCEPTION_STRING); - iTestResult.setStatus(ITestResult.FAILURE); + Assert.fail(getJSErrorsFromLogEntries(logEntries).map(LogEntry::getMessage).collect(Collectors.joining("\n"))); } } }