更改java中PhantomJS的日志文件路径[英] Change path for the logfile of PhantomJS in java

问题描述

我无法弄清楚如何更改 PhantomJS 的日志文件路径.我尝试:

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

还有:

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

但现在它不起作用.

推荐答案

看了 PhantomJSDriverService.createDefaultService(...) 我想通了出去.

这就是我的做法,虽然有点笨拙,但对我有用...希望这会有所帮助:

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

本文地址:https://www.itbaoku.cn/post/1740051.html