无法从获得的webdriver正确的控制台日志(铬,C#) [英] Can't get proper console logs from WebDriver (Chrome, C#)
问题描述
我写了下面的微型试验(这是无用的,但在这里不是这种情况),在硒的webdriver,C#中,Chrome浏览器:
I wrote following micro-test (it's useless but it's not the case here) in Selenium WebDriver, C#, for Chrome browser:
[Test]
public void T2_API_001_PrintingAlerts()
{
pgactions.OpenDataset(driver, settings.dataset); // opening page
for (int i = 0; i < 10; i++)
{
((IJavaScriptExecutor)driver).ExecuteScript("TsTable.Admin.log('this is error message', true);");
}
var logs = driver.Manage().Logs.GetLog(LogType.Browser);
foreach (var log in logs)
{
Console.WriteLine(log.ToString());
}
Thread.Sleep(100000);
}
在VS中调试控制台我希望看到(就像我在Chrome浏览器中看到例如,通过启动的webdriver):
In debugging console in VS I expect to see (like I see in Chrome browser instance started by WebDriver):
[14:02:22.816] Settings valid!
randomTable.js:6711 [14:02:22.976] Constructing table...
randomTable.js:6711 [14:02:22.976] Validating 32 rows data set...
( some more irrelevant rows )
randomTable.js:6711 [14:02:23.375] ...DONE (0.399 sec)
randomTable.js:6711 [14:02:24.949] this is error message
randomTable.js:6711 [14:02:25.060] this is error message
randomTable.js:6711 [14:02:25.174] this is error message
randomTable.js:6711 [14:02:25.344] this is error message
randomTable.js:6711 [14:02:25.477] this is error message
randomTable.js:6711 [14:02:25.612] this is error message
randomTable.js:6711 [14:02:25.715] this is error message
randomTable.js:6711 [14:02:25.809] this is error message
randomTable.js:6711 [14:02:25.993] this is error message
randomTable.js:6711 [14:02:26.089] this is error message
但我得到的是:
------ Run test started ------
NUnit VS Adapter 2.0.0.0 executing tests is started
Loading tests from C:\automated_testing\testTable\TableSelenium.dll
Run started: C:\automated_testing\testTable\TableSelenium.dll
Starting test...
[2016-05-04T12:02:16Z] [All] http://tstable.testsite.com/favicon.ico 0:0 Failed to load resource: the server responded with a status of 404 (Not Found)
(最后一行状态回应仅事项,但说实话 - (?)我不能,甚至看到浏览器,行)
(the last line matters only, but to be honest - I can't it even see that line in browser(?))
是在这条线的问题呢?
VAR日志= driver.Manage()Logs.GetLog(LogType.Browser);
Is the problem in this line?
var logs = driver.Manage().Logs.GetLog(LogType.Browser);
?
我知道的:
https://开头github.com/seleniumhq/selenium-google-code-issue-archive/issues/6832
也看到了一些黑客来收集错误日志中不同的方式。主要的情况下,它 - 我需要没有错误,但是所有的日志
but also saw some 'hacks' to gather error logs in different ways. The main case it - I need no errors, but ALL logs.
任何想法
推荐答案
的问题是在驱动程序的声明部分,其中的LogLevel
失踪。现在我设置 SetLoggingPreference
在 [设置]
部分:
The issue was in driver declaration section where LogLevel
was missing. Now I set SetLoggingPreference
in [SetUp]
section:
ChromeOptions options = new ChromeOptions();
options.SetLoggingPreference(LogType.Browser, LogLevel.All);
driver = new ChromeDriver("path to driver", options);
和所有日志都印在调试控制台: - )
and all logs are printed in debug console :-)
这篇关于无法从获得的webdriver正确的控制台日志(铬,C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!