Issue 7055 in selenium: RemoteWebDriver throwing NPE at @FindBy annotations

11 views
Skip to first unread message

sele...@googlecode.com

unread,
Mar 3, 2014, 6:26:15 PM3/3/14
to selenium-develope...@googlegroups.com
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium Status-Untriaged

New issue 7055 by harishks...@gmail.com: RemoteWebDriver throwing NPE at
@FindBy annotations
http://code.google.com/p/selenium/issues/detail?id=7055

1. I am Using RemoteWebDriver(Grid in configuration) + TestNG with Page
Object Factory Patterns,I am using @FindBy annotations to find the
WebElement.When I am running test cases,Remote WebDriver is throwing NPE
for each call of @FindBy.

2.These test cases working fine with Safari Driver and not throwing
exception.

3.These test cases working fine when using RemoteWebDriver and "By" methods
to locate the elements.

4.Hub and Nodes are running on local machine .

Below is the code :

SetUP Class :

public class PageSetup
{
public WebDriver driver; // = new SafariDriver();

/* This method will run before every class which contains tests */

@BeforeClass
public CreateOneTimeTaskPage launchSite()
{
try
{
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setBrowserName("safari");
desiredCapabilities.setVersion("6.0.5");
desiredCapabilities.setPlatform(org.openqa.selenium.Platform.MAC);
driver = new RemoteWebDriver(new
URL("http://localhost:4444/wd/hub"),desiredCapabilities) ;
driver.get(props.getProperty("URL"));
}

catch(Exception e)
{
e.printStackTrace();
}
return new CreateOneTimeTaskPage(driver);
}

@AfterClass
public void tearDown()
{
driver.quit();
}

Page Object Class:

public class TaskPageObjects {

private WebDriver driver;

public TaskPageObjects(WebDriver driver) {
this.driver = driver;
}

@FindBy(id = "pdata")
private WebElement pDataElement; //Throwing NPE here

public TaskPageObjects checkBoxData(WebDriver driver)
{
try
{
pDataElement.click(); // Throwing NPE here
//driver.findElement(pDataElementLocator).click(); WORKING FINE
driver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);
}

catch(Exception e)
{
e.printStackTrace();
}
return this;
}


TEST CLASS :
public class TasksTests extends PageSetup{

TasksPage taskPage = PageFactory.initElements(driver,TasksPage.class);

@Test(enabled=true, groups="Tasks")
public void test_DescriptionOfTask()
{
taskPage.checkBoxData(driver); //Throwing NPE here
}
}

Exception :

java.lang.NullPointerException
at
org.openqa.selenium.support.pagefactory.DefaultElementLocator.findElement(DefaultElementLocator.java:59)
at
org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:34)
at com.sun.proxy.$Proxy8.sendKeys(Unknown Source)
at com.apple.mqm.pfa.PO.TaskPage.selectProduct(TaskPage.java:833)
at
com.apple.mqm.pfa.Tests.TasksTests.test_DuplicateFunctionality(TasksTests.java:95)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
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:335)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:330)
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)


Selenium version:selenium-server-standalone-2.40.0 (running on hub)
OS:Mac(10.8.4)
Browser:Safari
Browser version:6.0.5



--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

sele...@googlecode.com

unread,
Mar 4, 2014, 5:01:21 PM3/4/14
to selenium-develope...@googlegroups.com
Updates:
Status: Invalid

Comment #1 on issue 7055 by barancev: RemoteWebDriver throwing NPE at
@FindBy annotations
http://code.google.com/p/selenium/issues/detail?id=7055

This exception means that when you called
PageFactory.initElements(driver,TasksPage.class);
the value of the 'driver' variable was null.

Please reimplement your setup code to ensure the driver is initialized
before its use.

sele...@googlecode.com

unread,
Mar 4, 2014, 8:44:25 PM3/4/14
to selenium-develope...@googlegroups.com

Comment #2 on issue 7055 by harishks...@gmail.com: RemoteWebDriver throwing
FYI , I am not getting NPE when i am running tests without RemoteWebDriver
set up.But as you suggested ,I tried assigning driver = null before using
it,still i got the exception.Please suggest the way i can run my tests
using RemoteWebdriver.Thanks

sele...@googlecode.com

unread,
Mar 5, 2014, 2:58:49 AM3/5/14
to selenium-develope...@googlegroups.com
Updates:
Labels: -Status-Untriaged

Comment #3 on issue 7055 by barancev: RemoteWebDriver throwing NPE at
@FindBy annotations
http://code.google.com/p/selenium/issues/detail?id=7055

I told you what's the reason of NPE -- the value of the 'driver' variable
was null at the moment PageFactory.initElements was called.

For advices how to rewrite the code please send a question to the selenium
user group [1]

[1] https://groups.google.com/forum/#!forum/selenium-users
Reply all
Reply to author
Forward
0 new messages