Java PhantomJSDriver disable all logs in console

11,814

Solution 1

This one works for me.

DesiredCapabilities dcap = new DesiredCapabilities();
String[] phantomArgs = new  String[] {
    "--webdriver-loglevel=NONE"
};
dcap.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, phantomArgs);
PhantomJSDriver phantomDriver = new PhantomJSDriver(dcap);

Solution 2

Looking at the source files of org.openqa.selenium.phantomjs.PhanomJSDriverService while debugging, I discovered that it's actually ignoring documented log levels for ghostdriver itself. Doing this disables the bulk of ghostdriver output:

Logger.getLogger(PhantomJSDriverService.class.getName()).setLevel(Level.OFF);

Seems that GhostDriver should be be updated to not log when

phantomJSCaps.setCapability(PhantomJSDriverService.PHANTOMJS_GHOSTDRIVER_CLI_ARG‌​S, "--webdriver-loglevel=NONE");  

is used.

Share:
11,814

Related videos on Youtube

Alexey Kulikov
Author by

Alexey Kulikov

Updated on June 04, 2022

Comments

  • Alexey Kulikov
    Alexey Kulikov almost 2 years

    I'm developing a small console app using Selenium and I need to turn off all logs from it.

    I have tried phantomJSDriver.setLogLevel(Level.OFF); but it does not work. I need help.

    How do I disable all logs in console application that is using Selenium and Phantomjs (GhostDriver)?

  • tribbloid
    tribbloid almost 10 years
    I'm using the same config file but it doesn't work, the ghost driver still print all the INFO log on the screen. This is my config lines: phantomJSCaps.setCapability(PhantomJSDriverService.PHANTOMJS‌​_GHOSTDRIVER_CLI_ARG‌​S, "--webdriver-loglevel=NONE"); phantomJSCaps.setCapability(PhantomJSDriverService.PHANTOMJS‌​_EXECUTABLE_PATH_PRO‌​PERTY, "/usr/lib/phantomjs/bin/phantomjs");
  • tribbloid
    tribbloid almost 10 years
    I found this in the source code: * NOTE: This is useful only when used together with PhantomJSDriverService#PHANTOMJS_GHOSTDRIVER_PATH_PROPERTY. * So it is not supposed to be used like this. But is there way to set the PHANTOMJS_GHOSTDRIVER_PATH_PROPERTY?
  • Hery
    Hery almost 10 years
    Somehow it works for me without setting that property. However I see the way to set it here. Maybe you can try it out.
  • javanoob
    javanoob over 9 years
    Excellent..this worked for me atleast and thanks alot
  • stack1
    stack1 over 9 years
    @Hery - How do I do this in Ruby ?
  • Bằng Rikimaru
    Bằng Rikimaru over 6 years
    This one works for me with Phantoms js 1.2 and Selenium 2.53 version.