問(wèn)題描述
我正在嘗試禁用 Chrome 控制臺(tái)的輸出.如果我通過(guò) --start-maximized 選項(xiàng)它工作正常.我可能有錯(cuò)誤的命令?
I am trying to disable the output to the console for chrome. If I pass the --start-maximized option it works fine. I may have the wrong command?
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.switches", Arrays.asList("--silent"));
chrome = new ChromeDriver(_chromeservice,capabilities);
我也試過(guò)了
ChromeOptions options = new ChromeOptions();
options.addArguments("silent");
chrome = new ChromeDriver(options);
輸出
啟動(dòng) ChromeDriver 端口=26703 版本=23.0.1240.0日志=/Brett/workspace/TestNG/chromedriver.log[1214/161331:ERROR:ipc_sync_channel.cc(378)] 取消掛起的發(fā)送[1214/161331:ERROR:ipc_sync_channel.cc(378)] 取消掛起的發(fā)送[1214/161331:ERROR:ipc_sync_channel.cc(378)] 取消掛起發(fā)送塊引用
Started ChromeDriver port=26703 version=23.0.1240.0 log=/Brett/workspace/TestNG/chromedriver.log [1214/161331:ERROR:ipc_sync_channel.cc(378)] Canceling pending sends [1214/161331:ERROR:ipc_sync_channel.cc(378)] Canceling pending sends [1214/161331:ERROR:ipc_sync_channel.cc(378)] Canceling pending sendsBlockquote
推薦答案
提示 Chromedriver ticket(關(guān)于 silent
選項(xiàng)),我查看了 ChromeDriverService.java
,找到了的引用"webdriver.chrome.logfile"
.
Hinted by this Chromedriver ticket (about the silent
option), I looked in the source of ChromeDriverService.java
, and found a reference to "webdriver.chrome.logfile"
.
將 -Dwebdriver.chrome.logfile="/dev/null"
添加到我的 java
命令后,日志再次變得可讀:無(wú)用的 ChromeDriver 日志不見(jiàn)了,而 System.out.println
調(diào)用和異常仍然顯示在控制臺(tái)中.
After adding -Dwebdriver.chrome.logfile="/dev/null"
to my java
command, the logs became readable again: The usless ChromeDriver logs were gone, while theSystem.out.println
calls and exceptions are still shown in the console.
我用以下參數(shù)啟動(dòng)java
(Linux/Mac):
I start java
with the following parameters (Linux / Mac):
DIR=path/to/dir/containing/selenium/and/stuff
cd "$DIR" && java -cp "$DIR
:$DIR/output
:$DIR/bin/selenium-server-standalone-2.33.0.jar"
-Dwebdriver.chrome.driver="$DIR/bin/chromedriver"
-Dwebdriver.chrome.args="--disable-logging"
-Dwebdriver.chrome.logfile="/dev/null"
AllTests
如果您使用的是 Windows:
If you're on Windows:
set DIR=path odircontainingseleniumandstuff
cd "%DIR%" && java -cp "%DIR%;%DIR%output;%DIR%inselenium-server-standalone-2.33.0.jar" ^
-Dwebdriver.chrome.driver="%DIR%inchromedriver.exe" ^
-Dwebdriver.chrome.args="--disable-logging" ^
-Dwebdriver.chrome.logfile=NUL ^
AllTests
<小時(shí)>
我的類路徑(-cp
)的組成說(shuō)明:我的測(cè)試位于$DIR/output"的目錄中.Selenium jar 文件放在$DIR/bin/selenium-server-standalone-2.33.0.jar"中.AllTests"是包含 public static void main(String[] args)
的類的名稱 - 這會(huì)啟動(dòng)我的測(cè)試.
Explanation for the composition of my classpath (-cp
): My tests are located in a directory at "$DIR/output". The Selenium jar file is placed in "$DIR/bin/selenium-server-standalone-2.33.0.jar". "AllTests" is the name of my class containing public static void main(String[] args)
- this launches my tests.
其他參數(shù)不言自明,請(qǐng)根據(jù)需要進(jìn)行調(diào)整.為方便起見(jiàn)(在 shell/批處理腳本中使用),我在變量 DIR
中聲明了公共目錄.
The other parameters are self-explanatory, adjust it to your needs. For convenience (used in a shell/batch script), I've declared the common directory in a variable DIR
.
這篇關(guān)于將選項(xiàng)傳遞給 chrome 驅(qū)動(dòng)程序 selenium的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!