Krazy Dev
Krazy Dev

Reputation: 182

Firefox driver returning null

So I am using Selenium with JUnit. The issue I'm having is that when I configure my firefox driver using the following method, the driver returns null.

This is the function that configures it-

public WebDriver ConfigureFirefox(WebDriver Driver){

    System.setProperty("webdriver.firefox.marionette","/Users/wshaikh/Downloads/geckodriver");
    DesiredCapabilities capabilities = DesiredCapabilities.firefox();
    capabilities.setCapability("marionette", true);
    Driver = new FirefoxDriver();

    return Driver;
}

Here is how it is being used in the Test Setup-

@Before
public void SetupTest()
{
    Driver = testHelper.ConfigureFirefox(Driver);
    checkPointPage = new CheckPointPage(Driver);

    Driver.get(URL);
}

I keep getting a NullPointer exception. After stepping through the code, I figured out the Driver keeps returning null and do not know why.

I am using a Mac.

Any ideas?

Thanks!

Upvotes: 0

Views: 647

Answers (1)

Guy
Guy

Reputation: 50854

You need to initialize the driver with the capabilities. You also don't need to send the driver to ConfigureFirefox

public WebDriver ConfigureFirefox() {  
    System.setProperty("webdriver.firefox.marionette","/Users/wshaikh/Downloads/geckodriver");
    DesiredCapabilities capabilities = DesiredCapabilities.firefox();
    capabilities.setCapability("marionette", true);
    WebDriver driver = new FirefoxDriver(capabilities);

    return driver;
}

@Before
public void SetupTest() {
    Driver = testHelper.ConfigureFirefox();
    checkPointPage = new CheckPointPage(Driver);

    Driver.get(URL);
}

Upvotes: 1

Related Questions