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);
}
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
but all I get is:
------ 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(?))
Is the problem in this line?
var logs = driver.Manage().Logs.GetLog(LogType.Browser);
?
I am aware of that: 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.
Any ideas?
Through WebDriver, Selenium supports all major browsers on the market such as Chrome/Chromium, Firefox, Internet Explorer, Edge, Opera, and Safari.
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 :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With