Skip to content

Commit

Permalink
Added support for TestNG to use non-annotated tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
AutomatedOwl committed Jun 6, 2018
1 parent 634c82e commit 79044f2
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.github.automatedowl.tools;

import static org.junit.jupiter.api.Assertions.assertTrue;

import com.github.automatedowl.tools.drivers.junitholder.JSErrorsDriverHolder;
import com.github.automatedowl.tools.pages.BlankPage;
import com.github.automatedowl.tools.pages.Site88Page;
Expand Down Expand Up @@ -72,6 +74,14 @@ void noJSErrorsTest(TestInfo testInfo) throws InterruptedException {
waitBeforeClosingBrowser();
}

/** Test method.
* It should not use JSErrorsCollectorJUnit annotation. */
@Test
void noAnnotationTest() {
driver = new ChromeDriver();
assertTrue(true);
}

@AfterEach
void closeDriver() {
driver.quit();
Expand Down
2 changes: 1 addition & 1 deletion testng/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.github.automatedowl</groupId>
<artifactId>chromedriver-js-errors-collector-testng</artifactId>
<version>1.0.2</version>
<version>1.0.3</version>
<name>${project.groupId}:${project.artifactId}</name>
<description>Java library which allows to easily collect JS errors received in Chromedriver session,
using annotations on test methods.</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void beforeInvocation(IInvokedMethod iInvokedMethod, ITestResult iTestRes
public void afterInvocation(IInvokedMethod iInvokedMethod, ITestResult iTestResult) {

// Check if test method had invoked.
if (iInvokedMethod.getTestMethod().isTest()) {
if (iInvokedMethod.getTestMethod().isTest() && isTestAnnotated(iInvokedMethod)) {

// Get log entries from Chromedriver session.
List<LogEntry> logEntries = getLogEntriesForTest(iInvokedMethod);
Expand Down Expand Up @@ -69,6 +69,14 @@ else if (isAssertJSErrorsEnabled(
}
}

private boolean isTestAnnotated(IInvokedMethod method) {
return method
.getTestMethod()
.getConstructorOrMethod()
.getMethod()
.getAnnotation(JSErrorsCollectorTestNG.class) != null;
}

private boolean isJSErrorContained(String message) {
Pattern pattern = Pattern.compile(JS_ERRORS_REGEX);
Matcher matcher = pattern.matcher(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.github.automatedowl.tools.pages.Site88Page;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.annotations.*;

/** Class that contains TestNG unit tests for Chromedriver JS errors collector. */
Expand Down Expand Up @@ -64,6 +65,13 @@ void noJSErrorsTest() throws InterruptedException {
waitBeforeClosingBrowser();
}

/** Test method.
* It should not use JSErrorsCollectorTestNG annotation. */
@Test
void noAnnotationTest() {
Assert.assertTrue(true);
}

@AfterMethod
void closeDriver() {
driver.quit();
Expand Down

0 comments on commit 79044f2

Please sign in to comment.