2

I'm trying to run a phantomjs program on Openshift server.

But I'm getting this error from one month :(

Error:

java.lang.IllegalStateException: The driver executable does not exist: /var/lib/openshift/54eb79134382ecc76d00002b/app-root/data/Phantomjs-1.9.8-linux-x86_64/bin/phantomjs
    com.google.common.base.Preconditions.checkState(Preconditions.java:197)
    org.openqa.selenium.remote.service.DriverService.checkExecutable(DriverService.java:117)
    org.openqa.selenium.phantomjs.PhantomJSDriverService.findPhantomJS(PhantomJSDriverService.java:246)
    org.openqa.selenium.phantomjs.PhantomJSDriverService.createDefaultService(PhantomJSDriverService.java:182)
    org.openqa.selenium.phantomjs.PhantomJSDriver.<init>(PhantomJSDriver.java:99)
    org.apache.jsp.doThatTask_jsp._jspService(doThatTask_jsp.java:87)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

Here is my simple program:

package com.mySimpleProgram;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriverService;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

public class MainProgram {
    public static void main(String[] args) throws MalformedURLException, InterruptedException{
        DesiredCapabilities caps = new DesiredCapabilities();
        caps.setCapability(
        PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
        System.getenv("OPENSHIFT_DATA_DIR")+"/Phantomjs-1.9.8-linux-x86_64/bin/phantomjs");                  
        WebDriver driver = new PhantomJSDriver(caps);

        driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
        driver.get("https://www.google.com/");

        Thread.sleep(5000);

        out.println(driver.getPageSource());
    }
}

Why do I get this error everytime on server?

Alex K
  • 8,269
  • 9
  • 39
  • 57
Raj kumar
  • 117
  • 2
  • 7

3 Answers3

0

Sounds like your driver isn't being found when passed the parameters in System.getenv(). Double check that location and ensure that the driver executable is there.

John Fisher
  • 182
  • 3
  • 12
0

Check whether you have permission to read /var/lib/openshift/54eb79134382ecc76d00002b/app-root/data/Phantomjs-1.9.8-linux-x86_64/bin/phantomjs directory

Mrinal Bhattacharjee
  • 1,326
  • 4
  • 10
  • 15
0

Try this code its Working for me:

DesiredCapabilities caps = new DesiredCapabilities();
    caps.setJavascriptEnabled(true);

    caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "D:\\phantomjs-2.0.0-windows\\bin\\phantomjs.exe");

    WebDriver driver = new PhantomJSDriver(caps);
    driver.manage().timeouts().pageLoadTimeout(2000, TimeUnit.SECONDS);


    driver.get("https://github.com/detro/ghostdriver");

    System.out.println(driver.getTitle());