Question

I used Selenium IDE on Mozilla to test a website. After that, I created a java project in Eclipse and I imported my tests done with Selenium IDE. then I run it directly in Eclipse.

How can I run the tests with PhantomJS instead of Mozilla Firefox?

Was it helpful?

Solution

You have two ways to run your tests in phantomjs, but first you have to install/unzip phantomjs somewhere and extend your PATH variable to it.

First: You can use the Ghostdriver java bindings through Maven pom.xml (you need to include the library in your Eclipse project) like in here

<dependency>
    <groupId>com.github.detro.ghostdriver</groupId>
    <artifactId>phantomjsdriver</artifactId>
    <version>LATEST_VERSION_HERE</version>
</dependency>

and then instantiate your WebDriver this way:

WebDriver driver = new PhantomJSDriver();

Second: Run phantomjs in WebDriver mode (in separate console window or as a shortcut) through

phantomjs --webdriver=4444

like in here and then instantiate the WebDriver in java through:

WebDriver driver = new RemoteWebDriver(
    new Uri("http://127.0.0.1:4444/wd/hub"),
    DesiredCapabilities.phantomjs()
);

See also another question for use as a hub.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top