-2

Let me tell you, I'm completely new by using GhostDriver

I successfully download PhantomJSand i've set my path into environment variable, now i'm trying to run this simple program:

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import java.net.MalformedURLException;
import java.net.URL;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

public class PhantomJSTest {

   private WebDriver driver;

   private static final By ABOUT_TAB = By.linkText("About");
   private static final By ROADMAP_LINK = By.xpath("//a[text() = 'Roadmap']");
   private static final By HELP_LINK = By.xpath("//a[text() = 'Help']");

   @BeforeClass
   private void initialize() {
      driver = new PhantomJSDriver();
      driver.navigate().to("http://www.seleniumhq.org/");
   }

   @Test
   public void verifySomething() {
      driver.findElement(ABOUT_TAB).click();
      assertThat(driver.findElement(ROADMAP_LINK).isDisplayed(), is(true));
      assertThat(driver.findElements(HELP_LINK).isEmpty(), is(true));
   }

   @AfterClass
   private void quit() {
      driver.quit();
   }
}

I tried to run it, But it's saying:

Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/browserlaunchers/Proxies
    at org.openqa.selenium.phantomjs.PhantomJSDriverService.createDefaultService(PhantomJSDriverService.java:178)
    at org.openqa.selenium.phantomjs.PhantomJSDriver.<init>(PhantomJSDriver.java:99)
    at org.openqa.selenium.phantomjs.PhantomJSDriver.<init>(PhantomJSDriver.java:89)
    at smsRobot.MyProgram.main(MyProgram.java:24)
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.browserlaunchers.Proxies
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 4 more

Please help :(

HELP WOULD BE APPRECIATED!!

UPDATED


After downloading selenium-common.jar, I'm getting this error:

Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the phantomjs.binary.path capability/system property/PATH variable; for more information, see https://github.com/ariya/phantomjs/wiki. The latest version can be downloaded from http://phantomjs.org/download.html
    at com.google.common.base.Preconditions.checkState(Preconditions.java:197)
    at org.openqa.selenium.phantomjs.PhantomJSDriverService.findPhantomJS(PhantomJSDriverService.java:237)
    at org.openqa.selenium.phantomjs.PhantomJSDriverService.createDefaultService(PhantomJSDriverService.java:182)
    at org.openqa.selenium.phantomjs.PhantomJSDriver.<init>(PhantomJSDriver.java:99)
    at org.openqa.selenium.phantomjs.PhantomJSDriver.<init>(PhantomJSDriver.java:89)
    at smsRobot.MyProgram.main(MyProgram.java:24)
Robot
  • 101
  • 4
  • 11

1 Answers1

2

You need to set the path to your phantomDriver executable like so:

DesiredCapabilities caps = new DesiredCapabilities();
caps.setJavascriptEnabled(true); // enabled by default
caps.setCapability(
    PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
    "path/to/your/phantomjs.exe"
);

driver = new PhantomJSDriver(caps);
driver.navigate().to("http://www.seleniumhq.org/");
Entreco
  • 12,738
  • 8
  • 75
  • 95