title: using casperjs with selenium webdriver and Java
body: <p>Edit:
  I have below casperjs script: </p>
  
  <pre><code>var casper = require('casper').create();
  
  casper.start('http://google.com/', function() {
  print(this.getTitle());
  });
  
  casper.thenOpen('http://phantomjs.org', function() {
  print(this.getTitle());
  });
  
  casper.run();
  </code></pre>
  
  <p>I tried to run this script using below command in Java:  </p>
  
  <pre><code> Process process = Runtime.getRuntime().exec("C:/Program Files (x86)/PhantomJS/phantomjs-2.1.1-windows/bin/phantomjs download.js");
  </code></pre>
  
  <p>The code compiles and run but there is no output.</p>
  
  <p>I tried using Script engine eval function:</p>
  
  <pre><code>    ScriptEngineManager manager = new ScriptEngineManager();
      ScriptEngine engine = manager.getEngineByName("JavaScript");
  engine.eval(new java.io.FileReader(System.getProperty("user.dir")+"/resources/CasperTest.js"));
  </code></pre>
  
  <p>But in this case i get below exception:</p>
  
  <pre><code>javax.script.ScriptException: ReferenceError: "require" is not defined in &lt;eval&gt; at line number 1
      at jdk.nashorn.api.scripting.NashornScriptEngine.throwAsScriptException(NashornScriptEngine.java:455)
      at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:439)
      at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:401)
      at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:397)
      at jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:147)
      at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:249)
      at loginpage.main(loginpage.java:91)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:497)
      at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
  Caused by: &lt;eval&gt;:1 ReferenceError: "require" is not defined
      at jdk.nashorn.internal.runtime.ECMAErrors.error(ECMAErrors.java:57)
      at jdk.nashorn.internal.runtime.ECMAErrors.referenceError(ECMAErrors.java:319)
      at jdk.nashorn.internal.runtime.ECMAErrors.referenceError(ECMAErrors.java:291)
      at jdk.nashorn.internal.objects.Global.__noSuchProperty__(Global.java:914)
      at jdk.nashorn.internal.scripts.Script$\^eval\_.:program(&lt;eval&gt;:1)
      at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:636)
      at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:229)
      at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:387)
      at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:437)
      ... 10 more
  [INFO  - 2017-05-12T07:27:05.869Z] ShutdownReqHand - _handle - About to shutdown
  </code></pre>
  
  <p>How can I execute the my casperjs script?</p>