AutomatedOwl / chromedriver-js-errors-collector

Java library which allows to easily collect JavaScript errors received in Chromedriver session, using annotations on test methods.
Apache License 2.0
8 stars 1 forks source link

JSErrorCollector - NullPointerException: com.github.automatedowl.tools.JSErrorsCollectorListener.getLogEntriesForTest(JSErrorsCollectorListener.java:98) #2

Closed nicholaswkc34 closed 5 years ago

nicholaswkc34 commented 5 years ago

Dear All, I’m encounter NULLPointerException when using the library.

 @BeforeSuite
    public void setupTest(/*String browser*/ ITestContext context) {
        webDriverManager.createDriver("chrome");
 }

@Test(groups= {"Login"}, description="Chrome - Login", priority = 0, dataProvider = "loginCredentials")
@JSErrorsCollectorTestNG(assertJSErrors = false)
public void login(String usernameStr, String passwordStr) {
    loginPages = PageFactory.initElements(driver, LoginPages.class);
    loginPages.login(visualManager, driver, usernameStr, passwordStr);
}

Java.lang.NullPointerException at com.github.automatedowl.tools.JSErrorsCollectorListener.getLogEntriesForTest(JSErrorsCollectorListener.java:98)

Please help on this problem. A billion thanks for your help.

AutomatedOwl commented 5 years ago

@peterwkc85 As described in the documentation of the library: https://github.com/AutomatedOwl/chromedriver-js-errors-collector You should store the driver in the JSErrorsDriverHolder object in order for the listener to interact with the driver object.

Can you please try:

@BeforeMethod
void setDriverForListener(Method method) {

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

@Test(groups= {"Login"}, description="Chrome - Login", priority = 0, dataProvider = "loginCredentials")
@JSErrorsCollectorTestNG(assertJSErrors = false)
public void login(String usernameStr, String passwordStr) {

    loginPages = PageFactory.initElements(driver, LoginPages.class);
    loginPages.login(visualManager, driver, usernameStr, passwordStr);
}

Let me know about the progress. Regards

nicholaswkc34 commented 5 years ago

Yes, I did expose driver object to JSErrorsCollector class but still facing the issue.

@BeforeSuite
public void setupTest(/*String browser*/ ITestContext context) {
        webDriverManager.createDriver("chrome");
        driver = webDriverManager.getDriver();
        // Set your test name to point its ChromeDriver session in HashMap.
        JSErrorsDriverHolder.setDriverForTest(context.getName(), driver);
}

Is there any others solution? Thanks.

AutomatedOwl commented 5 years ago

@peterwkc85 you should add @BeforeMethod and not @BeforeSuite context.getName() is not returning the test name, which required.

please try:


 @BeforeMethod
 void setDriverForListener(Method method) {

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

Yes, it works.

nicholaswkc34 commented 5 years ago

How to get the JS error Report?