我在Selenium WebDriver,C#中为Chrome浏览器编写了以下微测试(它没用,但事实并非如此):
switch( Config::get('config.records_source') ){
case 'db':
App::bind('RecordsService', 'DbRecordsService');
break;
case 'api':
App::bind('RecordsService', 'ApiRecordsService');
break;
}
在VS中的调试控制台中,我希望看到(就像我在Web浏览器实例中看到的WebDriver):
[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);
}
但我得到的只是:
[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)
?
我知道这一点: https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/6832
但也看到了一些'hacks'以不同的方式收集错误日志。它的主要情况 - 我不需要错误,但所有日志。
有什么想法吗?
答案 0 :(得分:5)
问题出在驱动程序声明部分,其中LogLevel
缺失。现在我在SetLoggingPreference
部分设置了[SetUp]
:
ChromeOptions options = new ChromeOptions();
options.SetLoggingPreference(LogType.Browser, LogLevel.All);
driver = new ChromeDriver("path to driver", options);
并且所有日志都在调试控制台中打印: - )