DevOps85
DevOps85

Reputation: 6523

Change path for the logfile of PhantomJS in java

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.

Upvotes: 4

Views: 3436

Answers (2)

Siul
Siul

Reputation: 109

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);

Upvotes: 4

SiKing
SiKing

Reputation: 10329

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.

Upvotes: 2

Related Questions