Java 和 GhostDriver:隐藏控制台和日志

Java And GhostDriver : Hide Console and Logs

我尝试在 java...

中隐藏 GhostDriver 的控制台和日志
- Windows 7.
- JDK is in 1.7.0_75 version.
- PhantomJS 1.9.7 is include with it path.
- GhostDriver 1.1.0 is include in an Eclipse Java SE Project.
- Selenium 2.43.1 is include in an Eclipse Java SE Project.

有办法吗?

我在 cli_args 中尝试了“--webdriver-loglevel=OFF”和“--webdriver-loglevel=NONE”,但它不起作用...

我尝试了 java -jar myJar.jar > myFile.txt 但它不起作用...

是否有其他方法或可能是错误的?

代码示例:

    WebDriver driver;
    DesiredCapabilities dCaps;
    dCaps = new DesiredCapabilities();
    dCaps.setJavascriptEnabled(true);
    dCaps.setCapability("takesScreenshot", true);
    dCaps.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, new String[] {"--ignore-ssl-errors=true", "--ssl-protocol=tlsv1", "--web-security=false", "--webdriver-loglevel=OFF", "--webdriver-loglevel=NONE"});
    dCaps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, phantom);
    driver = new PhantomJSDriver(dCaps);

和日志(带有 VM 参数):

   mai 18, 2015 2:09:48 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
   INFOS: executable: C:\Users2428788\workspace\BigBrowser\phantomjs-1.9.7-windows\phantomjs.exe
   mai 18, 2015 2:09:48 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
   INFOS: port: 48921
   mai 18, 2015 2:09:48 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
   INFOS: arguments: [--ignore-ssl-errors=true, --ssl-protocol=tlsv1, --web-security=false, --webdriver-loglevel=OFF, --webdriver-loglevel=NONE, --webdriver=48921, --webdriver-logfile=C:\Users2428788\workspace\BigBrowser\phantomjsdriver.log]
   mai 18, 2015 2:09:48 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
   INFOS: environment: {}
   PhantomJS is launching GhostDriver...

非常感谢。

查看以下步骤是否适合您(来自 this 主题的回答):

  • 像这样创建一个字符串数组:

    String[] phantomArgs = new  String[] {
            "--webdriver-loglevel=NONE"
    };
    
  • 将以下行添加到您的 DesiredCapabilities:

    capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, phantomArgs);
    
  • 我对 PhantomJSDriver 的配置是这样的:

    //set binary path of phantomJS driver
    DesiredCapabilities capabilities = new DesiredCapabilities();       
    capabilities.setJavascriptEnabled(true);
    capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "drivers/phantomjs.exe");
    capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_PAGE_SETTINGS_PREFIX,"Y");
    capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, phantomArgs);
    capabilities.setCapability("phantomjs.page.settings.userAgent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:16.0) Gecko/20121026 Firefox/16.0");
    
    //intialize driver and set capabilties
    PhantomJSDriver driver = new PhantomJSDriver(capabilities);
    
  • 右键单击您的项目并选择 运行 As->运行 Configurations->Arguments 并添加 VM 参数 -Djava.util.logging.config.file=logging.properties 到 VM 参数:

  • 点击应用然后点击运行

我找到了答案,只需将 jar 安装为 Windows 服务...