Skip to content

Instantly share code, notes, and snippets.

@scrooby
Last active November 18, 2016 15:52
Show Gist options
  • Save scrooby/99cc24b58bba78c79f2471d59738fa7d to your computer and use it in GitHub Desktop.
Save scrooby/99cc24b58bba78c79f2471d59738fa7d to your computer and use it in GitHub Desktop.
Retrieve the browser logs using Selenium and write them out to the console after each scenario
[AfterScenario(Order = 0)]
public void ErrorHandling()
{
WriteBrowserLogs();
}
private void WriteBrowserLogs()
{
var driverType = SeleniumController.Instance.DriverType;
if (driverType != SeleniumDriverType.Chrome)
{
return;
}
var browserLogs = seleniumContext.Selenium.Manage().Logs.GetLog(LogType.Browser);
if (browserLogs.Any())
{
Console.WriteLine();
Console.WriteLine("Browser logs:");
foreach (var log in browserLogs)
{
Console.WriteLine(log.ToString());
}
}
else
{
Console.WriteLine();
Console.WriteLine("No browser logs found");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment