Not able to use EventFiringWebDriver object in child class

I am try to set up EventFiringWebDriver in my poject, I am stuck up at some point where EventFiringWebDriver object is working fine in the same class & not working in the child class.

Parent class:

package utility;

import java.util.List;

import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.events.EventFiringWebDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;

import eventListeners.WebDriverEventHandler;

public class common {
public static WebDriver driver = null;
protected static EventFiringWebDriver eDriver;
WebDriverEventHandler handler;
protected NavigatetoOverviews nav;

@BeforeClass
public void beforeClass() throws InterruptedException {

handler = new WebDriverEventHandler();
System.setProperty(“webdriver.firefox.profile”, “default”);
driver = new FirefoxDriver();
eDriver = new EventFiringWebDriver(driver);
eDriver.register(handler);

nav = new NavigatetoOverviews();
eDriver.get(“http://google.com”);
}
}
My child class:

package eventListeners;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.testng.annotations.Test;

import bsh.commands.dir;
import utility.common;

public class TestExtendsCommon extends common{

@Test
public void sample() {

eDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
eDriver.findElement(By.id(“gbqfq”)).sendKeys(“Selenium”);
eDriver.findElement(By.id(“gbqfba”)).click();

}
}
My Test Results:

[TestNG] Running:
C:\Users\Hema\AppData\Local\Temp\testng-eclipse–492139263\testng-customsuite.xml

Just before beforeNavigateTo http://google.com
Inside the afterNavigateTo to http://google.com
FAILED: sample
java.lang.NullPointerException
at eventListeners.WebDriverEventHandler.beforeFindBy(WebDriverEventHandler.java:35)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.openqa.selenium.support.events.EventFiringWebDriver$1.invoke(EventFiringWebDriver.java:78)
at com.sun.proxy.$Proxy5.beforeFindBy(Unknown Source)
at org.openqa.selenium.support.events.EventFiringWebDriver.findElement(EventFiringWebDriver.java:183)
at eventListeners.TestExtendsCommon.sample(TestExtendsCommon.java:17)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)

===============================================
Default test
Tests run: 1, Failures: 1, Skips: 0
===============================================

===============================================
Default suite
Total tests run: 1, Failures: 1, Skips: 0
===============================================

[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 7 ms
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@77afea7d: 23 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter2@6d86b085: 8 ms
[TestNG] Time taken by org.testng.reporters.jq.Main@299a06ac: 34 ms
[TestNG] Time taken by org.testng.reporters.XMLReporter@4ac68d3e: 9 ms
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@1f89ab83: 40 ms

Thanks in Advance

hemasundarp Default Asked on November 27, 2014 in Selenium WebDriver.

I even tried to return the eDriver from class1 & tried to use that in Class2. In this scenario also getting the same error.

on November 27, 2014.
Add Comment
2 Answer(s)

Hi
I Guess This is The problem
you are initializing your Webdriver in @beforeClass they got initialized before Class
But When Class Code is Running It is Setting There Values to Null

You Just Try Doing Same Thing With @before

i Hope It will work

Regards
Ankit Ramola

ankit ramola Vice Professor Answered on November 27, 2014.
Add Comment

Thanks for everyone who spent some time on the question. Finally i found the answer.

As the error says, bug is in beforeFindBy method in WebDriverEventListener class.

In the above program, arg1 parameter will be null when you are finding element by WebDriver object. So i have modified the code like below:

hemasundarp Default Answered on November 27, 2014.

Please close this question now.

on December 2, 2014.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.