3

I'm running tests for a Java/Maven project using Selenium 3.4 and the FirefoxDriver (not the Marionette/Geckodriver). I have Firefox 45.9.0 installed. Our test code uses Log4j2 and I can set the logging level to whatever I like, but no matter what I set it to I get log messages like this in the console:

1501873908911   addons.manager  DEBUG   Application has been upgraded
1501873909216   addons.manager  DEBUG   Loaded provider scope for resource://gre/modules/addons/XPIProvider.jsm: ["XPIProvider"]
1501873909218   addons.manager  DEBUG   Loaded provider scope for resource://gre/modules/LightweightThemeManager.jsm: ["LightweightThemeManager"]
1501873909220   addons.manager  DEBUG   Loaded provider scope for resource://gre/modules/addons/GMPProvider.jsm
1501873909221   addons.manager  DEBUG   Loaded provider scope for resource://gre/modules/addons/PluginProvider.jsm
1501873909221   addons.manager  DEBUG   Starting provider: XPIProvider
1501873909221   addons.xpi  DEBUG   startup
1501873909222   addons.xpi  INFO    Mapping fxdriver@googlecode.com to C:\TMP\anonymous3169069284131523935webdriver-profile\extensions\fxdriver@googlecode.com
1501873909222   addons.xpi  DEBUG   Ignoring file entry whose name is not a valid add-on ID: C:\TMP\anonymous3169069284131523935webdriver-profile\extensions\webdriver-staging
1501873909223   addons.xpi  INFO    SystemAddonInstallLocation directory is missing
1501873909224   addons.xpi  INFO    Mapping loop@mozilla.org to C:\Program Files (x86)\Mozilla Firefox\browser\features\loop@mozilla.org.xpi
1501873909226   addons.xpi  INFO    Mapping {972ce4c6-7e08-4474-a285-3208198ce6fd} to C:\Program Files (x86)\Mozilla Firefox\browser\extensions\{972ce4c6-7e08-4474-a285-3208198ce6fd}.xpi
1501873909226   addons.xpi  DEBUG   Skipping unavailable install location app-system-share
1501873909226   addons.xpi  DEBUG   Skipping unavailable install location app-system-local

It looks like something inside the FirefoxDriver, or inside Firefox itself, is logging at a DEBUG level no matter what I set our logging level to.

I looked at this question but I can't figure out how to translate the Python answer to our Java code:

Example Python:

import logging
from selenium.webdriver.remote.remote_connection import LOGGER
LOGGER.setLevel(logging.WARNING)

Our Java code:

DesiredCapabilities capability = DesiredCapabilities.firefox();
FirefoxProfile profile=new FirefoxProfile();
capability.setCapability(FirefoxDriver.PROFILE, profile);
mDriver = new FirefoxDriver(capability);

I've tried several permutations but nothing seems to affect this logging - these messages appear in the console no matter what. Anyone have any way to control this logging?

user1071914
  • 3,295
  • 11
  • 50
  • 76

2 Answers2

4

These log are from selenium library, if you don't want to see it => turn it off by declare the scope of logging to only in your package or simply turn it off.

For example you just want to get log message from your code, the root package of your code is: com.example.mycode then open the log4j config file and add this: log4j.logger.com.example.mycode = DEBUG|INFO.

Or you can turn off only the logging from selenium: java.util.logging.Logger.getLogger("org.openqa.selenium").setLevel(Level.OFF);

TuyenNTA
  • 1,194
  • 1
  • 11
  • 19
  • I have already used the first option, the second I have not tried yet – TuyenNTA Sep 20 '17 at 02:26
  • I tried the second method, I haven't seen that before but it didn't work for me. Where would you put it in a test? I use log4j.properties and added log4j.logger.org.openqa.selenium.firefox=ERROR,CONSOLE. Maybe I shouldn't have added the ".firefox". Also, my understanding of the driver and selenium 3.4 is this: Prior to 3.0 Selenium, firefoxdriver was packaged with Selenium, after 3.0 you MUST use geckodriver regardless off Firefox version. – mancocapac Sep 21 '17 at 03:36
3

Sorry to dig up an old thread but just wanted to give an updated solution (latest driver version is 0.23.0 as of writing).

Official Docs: https://firefox-source-docs.mozilla.org/testing/geckodriver/geckodriver/TraceLogs.html

Here's the Java example in the documentation above. You can specifiy the logging level by including it in the .setLogLevel method of FirefoxOptions class.

FirefoxOptions options = new FirefoxOptions();
options.setLogLevel(FirefoxDriverLogLevel.TRACE);
WebDriver driver = new FirefoxDriver(options);

You can refer to the documentation for the different levels of logging.

Timothy T.
  • 1,031
  • 1
  • 12
  • 25