2017-08-04 94 views
0

我正在使用Selenium 3.4和FirefoxDriver(而不是木偶/ Geckodriver)運行Java/Maven項目的測試。我安裝了Firefox 45.9.0。我們的測試代碼使用Log4j2,我可以將日誌級別設置到任何我喜歡的,但不管如何我將它設置爲我在控制檯中日誌消息是這樣的:修改Selenium Firefox驅動程序的日誌級別?

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 [email protected] to C:\TMP\anonymous3169069284131523935webdriver-profile\extensions\[email protected] 
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 [email protected] to C:\Program Files (x86)\Mozilla Firefox\browser\features\[email protected] 
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 

它看起來像FirefoxDriver裏面的東西,或者在Firefox本身內部,無論我將日誌記錄級別設置爲何,都將記錄在DEBUG級別。

我看了看this question,但我無法弄清楚如何Python的答案翻譯成我們的Java代碼:

例的Python:

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

我們的Java代碼:

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

我已經嘗試了幾種排列方式,但似乎沒有任何影響這種日誌記錄 - 這些消息出現在控制檯中,無論如何。任何人有任何方法來控制這種日誌記錄?

回答

2

這些日誌來自硒庫,如果你不想看到它=>通過將日誌記錄的範圍聲明爲只在你的包中或者關閉它,關閉它。

例如,您只想從代碼中獲取日誌消息,則代碼的根包是:com.example.mycode然後打開log4j配置文件並添加:log4j.logger.com.example.mycode = DEBUG|INFO

或者你也可以從硒僅關閉記錄:java.util.logging.Logger.getLogger("org.openqa.selenium").setLevel(Level.OFF);

+0

你真的嘗試呢?它不適用於我: – mancocapac

+0

我已經使用第一個選項,第二個我還沒有嘗試 –

+0

我試過第二種方法,我沒有看到過,但它不適用於我。你會把它放在一個測試中?我使用log4j.properties並添加了log4j.logger.org.openqa.selenium.firefox =錯誤,CONSOLE。也許我不應該添加「.firefox」。此外,我對驅動程序和硒3.4的理解是這樣的:在3.0 Selenium之前,firefoxdriver與Selenium一起打包,3.0之後,您必須使用geckodriver而不管Firefox版本。 – mancocapac