MSyed
MSyed

Reputation: 21

PhantomJSDriver- How to initialize the driver?

Can someone tell me how I begin to test with PhantomJS? I have downloaded the PhantomJS exe file and also set my "path" variable.

And I do something similar for chrome like

if(config.getProperty("browser").equals("chrome")) { System.setProperty("webdriver.chrome.driver", "C:drivers\\chromedriver.exe"); driver= new ChromeDriver(); }

which is

if(config.getProperty("browser").equals("phantom"))
    {
        System.setProperty("webdriver.chrome.driver", "C:\\drivers\\chromedriver.exe");
        driver= new PhantomJSDriver();
    }

But, this does not work. Please help. I do not want to use RemoteWebDriver or GhostDriver

Upvotes: 0

Views: 5343

Answers (3)

Mohan krishna Sridhar
Mohan krishna Sridhar

Reputation: 43

Find the phantomjs code below and set the property key and value:

//System.setProperty("phantomjs.binary.path","phantomjs.exe path");


System.setProperty("phantomjs.binary.path", System.getProperty("user.dir")+"/ExternalLibraryFiles/phantomjs-2.1.1-windows/phantomjs-2.1.1-windows/bin/phantomjs.exe");

driver =new PhantomJSDriver();

Upvotes: 0

Leos Pol
Leos Pol

Reputation: 1

PhantomJSDriver accepts path to executable as a constructor argument:

if (config.getProperty("browser").equals("phantom"))
    driver= new PhantomJSDriver("C:\\drivers\\chromedriver.exe");

Upvotes: 0

MSyed
MSyed

Reputation: 21

I figured it out:

if(config.getProperty("browser").equals("phantom"))
{
    System.setProperty("phantomjs.binary.path", "C:\\drivers\\chromedriver.exe");
    driver= new PhantomJSDriver();
}

Upvotes: 2

Related Questions