Click here to Skip to main content
15,890,336 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
public class IbiboTest {

static WebDriver driver;

@BeforeClass
public void setUp() throws InterruptedException{
    System.setProperty("webdriver.chrome.driver","C:\\Program Files (x86)\\Google\\Chrome\\Application\\chromedriver.exe");
    WebDriver driver = new ChromeDriver();

    //driver= new FirefoxDriver();
    driver.get("https://www.goibibo.com/");
    Thread.sleep(5000);
    driver.manage().window().maximize();

}


@Test
public void testIbiboHomePage(){
    IbiboHomePage home = PageFactory.initElements(driver, com.Nalini.Ibibo.IbiboHomePage.class);
    home.clickRoundTripRadioButton();

}

public class IbiboHomePage {

WebDriver driver;
@FindBy(css = "input[id='gi_roundtrip_label']")
WebElement iRoundTrip;


public IbiboHomePage(WebDriver driver){
    this.driver = driver;
    PageFactory.initElements(driver, this);

}

public void clickRoundTripRadioButton(){
iRoundTrip.click();
}


What I have tried:

I am just trying to automate ibibo website.I am getting nullpointer exception for the above code.I am not able to understand where it is passing a null value.Pls help.Thank you
Posted
Updated 28-Apr-17 1:34am
Comments
Patrice T 28-Apr-17 7:22am    
Error message also tells you where is the error.
Member 13158473 28-Apr-17 7:34am    
Pls help with the below error msg ,what changes shd be done
Member 13158473 28-Apr-17 7:33am    
This is the error I am getting
FAILED: testIbiboHomePage
java.lang.NullPointerException
at org.openqa.selenium.support.pagefactory.DefaultElementLocator.findElement(DefaultElementLocator.java:69)
at org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:38)
at com.sun.proxy.$Proxy8.click(Unknown Source)
at com.Nalini.Ibibo.IbiboHomePage.clickRoundTripRadioButton(IbiboHomePage.java:22)
at com.Nalini.Ibibo.IbiboTest.testIbiboHomePage(IbiboTest.java:33)
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:108)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:661)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:869)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1193)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:126)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:744)
at org.testng.TestRunner.run(TestRunner.java:602)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:380)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:375)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)
at org.testng.SuiteRunner.run(SuiteRunner.java:289)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1301)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1226)
at org.testng.TestNG.runSuites(TestNG.java:1144)
at org.testng.TestNG.run(TestNG.java:1115)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:230)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:76)


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


===============================================
Default suite
Total tests run: 1, Failures: 1, Skips: 0
===============================================
Patrice T 28-Apr-17 9:06am    
This should be the interesting line
"at com.Nalini.Ibibo.IbiboHomePage.clickRoundTripRadioButton(IbiboHomePage.java:22)"

1 solution

You are declaring a static IbiboTest class member:
static WebDriver driver;
In your setUp() function you are declaring another local instance:
WebDriver driver = new ChromeDriver();
As a result, the static class member is still uninitialised and you get a null pointer exception in your testIbiboHomePage() function.

Solution:
Remove the type when creating the driver in setUp():
driver = new ChromeDriver();
 
Share this answer
 
v3
Comments
Member 13158473 28-Apr-17 7:36am    
Thank u soooo much.I got it now:)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900