问题
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.
回答1:
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 dcap = new DesiredCapabilities();
File logfile = new File("ABSOLUTE_PATH_TO_YOUR_LOG_FILE");
String[] phantomArgs = [ "--webdriver-loglevel=DEBUG" ]
PhantomJSDriverService pjsds = new PhantomJSDriverService.Builder()
.usingPhantomJSExecutable(f)
.usingAnyFreePort()
.withProxy(proxy)
.usingCommandLineArguments(phantomArgs)
.withLogFile(logfile)
.build();
PhantomJSDriver pdriver = new PhantomJSDriver(pjsds, dcap);
回答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.
来源:https://stackoverflow.com/questions/30805635/change-path-for-the-logfile-of-phantomjs-in-java