4

I cannot figure out how I can change path for logfile for PhantomJS. I try with:

DesiredCapabilities caps = new DesiredCapabilities();
caps.setJavascriptEnabled(true);
caps.setCapability("takesScreenshot", false);
caps.setCapability(
        PhantomJSDriverService.PHANTOMJS_GHOSTDRIVER_CLI_ARGS,
            new String[] { "--logfile=/home/ant/Document/phantomjsdriver.log" });
caps.setCapability(
        PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
        path);

And also with:

ArrayList<String> cliArgsCap = new ArrayList<String>();
cliArgsCap.add("--logfile=/home/ant/Document/phantomjsdriver.log");

DesiredCapabilities caps = new DesiredCapabilities();
caps.setJavascriptEnabled(true);
caps.setCapability("takesScreenshot", false);
caps.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS,cliArgsCap);

But for now it doesn't work.

Mike Laren
  • 8,028
  • 17
  • 51
  • 70
DevOps85
  • 6,473
  • 6
  • 23
  • 42

2 Answers2

4

I struggled a lot to get this working after looking at the code in PhantomJSDriverService.createDefaultService(...) I was able to figure it out.

So here is how I did it, is a little bit hacky but it worked for me...hope this helps:

DesiredCapabilities capabilities = new DesiredCapabilities();
File logfile = new File("ABSOLUTE_PATH_TO_YOUR_LOG_FILE");
String[] phantomArgs = { "--webdriver-loglevel=DEBUG" };
PhantomJSDriverService driverService = new PhantomJSDriverService.Builder()
              .usingPhantomJSExecutable(f)
              .usingAnyFreePort()
              .withProxy(proxy)
              .usingCommandLineArguments(phantomArgs)
              .withLogFile(logfile)
              .build();
PhantomJSDriver driver = new PhantomJSDriver(driverService, capabilities);
JakeRobb
  • 1,711
  • 1
  • 17
  • 32
Siul
  • 109
  • 1
  • 7
  • Here `usingPhantomJSExecutable(f) `, `f` should be same value with `PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY` value. – coderz Nov 15 '16 at 06:49
2

I have been looking for same for some time.

According to this issue on GitHub, it is difficult, effectively not possible. There is a workaround mentioned, but you need to provide some of the Ghostdriver source: the main.js and all files it imports.

According to this pull on GitHub, there is a command line argument --webdriver-logfile, and you can see this in the actual log. However, looking through the PhatomJSDriver source, accessing the CLI arguments has the same problem: you need the Ghostdriver source.

There is a comment on the PhantomJS main page from the maintainer, that he unfortunately no longer has time to work on this.

SiKing
  • 10,003
  • 10
  • 39
  • 90