This is the quickstart with Maven. For a quickstart without Maven, look here
The browser with the probably highest speed and lowest memory consumption in Selenium world: the headless PhantomJS
[Update 26.11.2013]: Ghostdriver is not ripe yet due to lack of enough stable maintainers: https://github.com/detro/ghostdriver/issues/140
[Note]: The development of Selenium and GhostDriver (which is the bridge between PhantomJS and Selenium) isn’t synchronized yet. So maybe the most actual versions of Selenium Server and GhostDriver may not work together. A combination that fits:
* PhantomJS 1.9.2
* GhostDriver 1.0.4
* Selenium 2.34
Setup is really quick
1.) Download phantomjs-1.9.2-windows.zip here and extract it to C:\Program Files (x86)
2.) Add C:\Program Files (x86)\phantomjs-1.9.2-windows to the PATH-variable
3.) Add in pom.xml
<dependency> <groupId>com.github.detro.ghostdriver</groupId> <artifactId>phantomjsdriver</artifactId> <version>1.0.4</version> </dependency>4.) Maybe change the version of selenium in pom.xml
<dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-server</artifactId> <version>2.34.0</version> </dependency>Sample Code
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.phantomjs.PhantomJSDriver; public class Example { public static void main(String[] args) { WebDriver driver = new PhantomJSDriver(); driver.get("http://www.google.com"); WebElement element = driver.findElement(By.name("q")); element.sendKeys("Cheese!"); element.submit(); System.out.println("Page title is: " + driver.getTitle()); driver.quit(); } }Looks so good
… if you’ve done right – your result should look like that:
Speedy Testing!
well pom.xml will only work if i have maven in the project as without maven it will not get the dependencies during runtime.please suggest if i donot have maven in my project then how to introduce ghostdriver in it ?
Hi shaibal,
thanks for comming to my blog. find your answer in my following blogpost: http://itkosmopolit.wordpress.com/2014/02/25/quick-start-of-running-selenium-webdriver-against-phantomjs-in-java-on-windows-plain-java/
Yours Michael
where can i find this pom.xml?
Hi, If possible please cover uploading files using PhantomJSDriver.
Hi Manali….
Yes it is covered in PJSDriver
Hi
I tried the above code , but i get this error.
Exception in thread „main“ java.lang.IllegalStateException: The path to the driv
er executable must be set by the phantomjs.binary.path capability/system propert
y/PATH variable; for more information, see https://github.com/ariya/phantomjs/wi
ki. The latest version can be downloaded from http://phantomjs.org/download.html
at com.google.common.base.Preconditions.checkState(Preconditions.java:17
7)
at org.openqa.selenium.phantomjs.PhantomJSDriverService.findPhantomJS(Ph
antomJSDriverService.java:237)
at org.openqa.selenium.phantomjs.PhantomJSDriverService.createDefaultSer
vice(PhantomJSDriverService.java:182)
at org.openqa.selenium.phantomjs.PhantomJSDriver.(PhantomJSDriver.
java:96)
at org.openqa.selenium.phantomjs.PhantomJSDriver.(PhantomJSDriver.
java:86)
at Example.main(Example.java:7)
Hi sravani,
thanks a lot for your comment. Unfortunately your question exceeda a bit the scope of this blog. Better ask youdr question on http://stackoverflow.com/ and tag it with „selenium“. I hope the best for you.
Yours Michael