我在Selenium WebDriver和C#中编写了以下微型测试(虽然这没什么用,但这不是本文的重点),用于Chrome浏览器:
[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的调试控制台中,我希望看到(就像在WebDriver启动的Chrome浏览器实例中看到的那样):
[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)
问题出在这行代码吗?
var logs = driver.Manage().Logs.GetLog(LogType.Browser);
?
我知道这个问题:https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/6832
但我也看到了一些“hack”的方法来以不同的方式收集错误日志。主要情况是- 我需要的不是错误,而是所有日志。
有什么想法吗?
(只有最后一行有意义,但说实话- 我甚至在浏览器中都看不到那行?)
chrome
选项,而不是ie
或ff
? :D - Vlad