com.github.automatedowl:chromedriver-js-errors-collector-testng

Java library which allows to easily collect JS errors received in Chromedriver session, using annotations on test methods.

License

License

Categories

Categories

JavaScript Languages TestNG Unit Testing Auto Application Layer Libs Code Generators
GroupId

GroupId

com.github.automatedowl
ArtifactId

ArtifactId

chromedriver-js-errors-collector-testng
Last Version

Last Version

1.0.4
Release Date

Release Date

Type

Type

jar
Description

Description

com.github.automatedowl:chromedriver-js-errors-collector-testng
Java library which allows to easily collect JS errors received in Chromedriver session, using annotations on test methods.
Project URL

Project URL

https://github.com/AutomatedOwl
Source Code Management

Source Code Management

https://github.com/AutomatedOwl/chromedriver-js-errors-collector

Download chromedriver-js-errors-collector-testng

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.automatedowl/chromedriver-js-errors-collector-testng/ -->
<dependency>
    <groupId>com.github.automatedowl</groupId>
    <artifactId>chromedriver-js-errors-collector-testng</artifactId>
    <version>1.0.4</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.automatedowl/chromedriver-js-errors-collector-testng/
implementation 'com.github.automatedowl:chromedriver-js-errors-collector-testng:1.0.4'
// https://jarcasting.com/artifacts/com.github.automatedowl/chromedriver-js-errors-collector-testng/
implementation ("com.github.automatedowl:chromedriver-js-errors-collector-testng:1.0.4")
'com.github.automatedowl:chromedriver-js-errors-collector-testng:jar:1.0.4'
<dependency org="com.github.automatedowl" name="chromedriver-js-errors-collector-testng" rev="1.0.4">
  <artifact name="chromedriver-js-errors-collector-testng" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.automatedowl', module='chromedriver-js-errors-collector-testng', version='1.0.4')
)
libraryDependencies += "com.github.automatedowl" % "chromedriver-js-errors-collector-testng" % "1.0.4"
[com.github.automatedowl/chromedriver-js-errors-collector-testng "1.0.4"]

Dependencies

compile (4)

Group / Artifact Type Version
org.seleniumhq.selenium : selenium-chrome-driver jar 3.12.0
org.seleniumhq.selenium : selenium-api jar 3.12.0
org.testng : testng jar 6.14.3
org.seleniumhq.selenium : selenium-support jar 3.5.3

Project Modules

There are no modules declared in this project.

chromedriver-js-errors-collector

Java library which allows to easily collect JavaScript errors received in Chromedriver session, using annotations on test methods. Currently, the library supports JUnit5 and TestNG testing framework.

Example of JUnit5 usage:

    @Test
    @JSErrorsCollectorJUnit
    void referenceErrorTest(TestInfo testInfo) throws InterruptedException {

        // Create a new instance of ChromeDriver.
        driver = new ChromeDriver();

        // Set your test name to point its ChromeDriver session in HashMap.
        JSErrorsDriverHolder.setDriverForTest(testInfo.getDisplayName(), driver);

        // Navigate to URL.
        site88Page.navigateToPage(driver);

        // The click on the button in the test site should cause JS reference error.
        site88Page.getTestButton().click();
        waitBeforeClosingBrowser();
    }
    
    @AfterEach
    void closeDriver() {
        driver.quit();
    }

Example of TestNG usage:

@Listeners(JSErrorsCollectorListener.class)
public class JSCollectorTestNGTest {

    private WebDriver driver;

    @BeforeMethod
    void setDriverForListener(Method method) {

        // Create a new instance of ChromeDriver.
        driver = new ChromeDriver();

        // Set your test name to point its ChromeDriver session in HashMap.
        JSErrorsDriverHolder.setDriverForTest(method.getName(), driver);
    }

    /** Test method.
     * It should receive JS reference error and expect related exception. */
    @Test
    @JSErrorsCollectorTestNG
    void referenceErrorTest() throws InterruptedException {

        // Navigate to URL.
        site88Page.navigateToPage(driver);

        // The click on the button in the test site should cause JS reference error.
        site88Page.getTestButton().click();
        waitBeforeClosingBrowser();
    }
    
    @AfterMethod
    void closeDriver() {
        driver.quit();
    }

Closing your browser session

In order for the errors comparison to work properly, you should use 'AfterMethod' in TestNG and 'AfterEach' in JUnit in order to call driver.quit(). This would allow the listeners to interact with your WebDriver object after test execution.

Annotation values

By default, using the annotation will cause your test to fail on JS errors received during Chromedriver session, and it would also use java.util.logging.Logger object to log JS errors after test execution.

To disable asserting JS errors after test execution, use:

@JSErrorsCollectorTestNG(assertJSErrors = false)

To disable logging JS errors after test execution, use:

@JSErrorsCollectorTestNG(logJSErrors = false)

To disable both, use:

@JSErrorsCollectorTestNG(logJSErrors = false, assertJSErrors = false)

Maven dependencies

JUnit5:

    <dependency>
        <groupId>com.github.automatedowl</groupId>
        <artifactId>chromedriver-js-errors-collector-junit</artifactId>
        <version>1.0.4</version>
    </dependency>

TestNG:

    <dependency>
        <groupId>com.github.automatedowl</groupId>
        <artifactId>chromedriver-js-errors-collector-testng</artifactId>
        <version>1.0.4</version>
    </dependency>

Versions

Version
1.0.4
1.0.3
1.0.2
1.0.1