Selenium: Empty logs for Selenium 4 alpha 5 when using RemoteWebdriver

Created on 27 Mar 2020  路  9Comments  路  Source: SeleniumHQ/selenium

馃悰 Bug Report

A clear and concise description of what the bug is.

When using latest Selenium 4 image with RemoteWebdriver and chrome standalone 4.0.0-alpha-5-20200326 docker image all kind of logs are empty. Problem does not exists in case of using local chrome browser (ver 80.0.3987.149 ).

To Reproduce

  1. Run standalone chrome docker image from docker hub with selenium 4
  2. Run tests against image using RemoteWebdriver
  3. Get logs
    AvailableLogTypes count returns 0

Detailed steps to reproduce the behavior:

Expected behavior

There should be 5 types of logs, and at least 2 of them shouldn't be empty (Browser and Driver) - like in case of running this against regular Chrome browser.

Test script or set of commands reproducing this issue

public class RemoteWebriverTests : IDisposable
{
    private readonly IWebDriver _driver;

    public RemoteWebriverTests()
    {
        var chromeOptions = new ChromeOptions();
        _driver = new RemoteWebDriver(new Uri("http://localhost:4444/"), chromeOptions);
    }

    [Fact]
    public void GetLogsFromChrome()
    {
        _driver.Navigate().GoToUrl("http://www.youtube.com");
        Thread.Sleep(5000);
        Assert.True(_driver.Manage().Logs.AvailableLogTypes.Count > 0);
    }

    public void Dispose()
    {
        _driver.Quit();
    }
}

Environment

OS: Windows 10
Browser: Chrome
Browser version: 80.0.3987.149
Docker image version: 4.0.0-alpha-5-20200326
Browser Driver version: 80.0.3987.10600
Language Bindings version: .net core 3.1
Selenium Grid version : 4.0.0-alpha-5

C-dotnet C-remote

Most helpful comment

What seems like a simpler workaround to me is the following. Subclass RemoteWebDriver with your own class that implements the ISupportsLogs interface, and then use that instead of new RemoteWebDriver(...). For example:

private class RemoteWebDriverWithLogs : RemoteWebDriver, ISupportsLogs
{
    // Also pass through any constructors you want to use
}

It makes our tests work again.

All 9 comments

Issue reproducible also on standalone-chrome:4.0.0-alpha-5-20200409

Issue reproducible also on version 4.0.0-alpha6-20200609. Are there any plans to look at this?

Works for me with docker image selenium/standalone-chrome:4.0.0-alpha6-20200609 and java binding 4.0.0-alpha6, so it must be something .Net specific.

Yes, reproduced with .Net binding 4.0.0-alpha05 and the abovementioned docker image

Hey @barancev we are running into this problem as well in our test environment. In fact, with Chrome 85, we had to update to a newer version of Selenium and ended up running into this bug. Is there any plans on addressing this soon?

this is also affecting us - would just like to chime in

Problem is that RemoteWebDriver does not implement marker interface ISupportsLogs, and without it it doesn't even try to get those logs (https://github.com/SeleniumHQ/selenium/blob/trunk/dotnet/src/webdriver/Remote/RemoteLogs.cs#L50).

Currently we use the following workaround:

        private static ConcurrentDictionary<IWebDriver, ICommandExecutor> _commandExecutors = new ConcurrentDictionary<IWebDriver, ICommandExecutor>();

        private static List<LogEntry> GetLogs(IWebDriver webDriver)
        {
            // Workaround for bug https://github.com/SeleniumHQ/selenium/issues/8229 .
                if (!_commandExecutors.TryGetValue(webDriver, out var commandExecutor))
                {
                    commandExecutor = (ICommandExecutor)typeof(RemoteWebDriver)
                        .GetProperty("CommandExecutor", BindingFlags.NonPublic | BindingFlags.Instance)
                        .GetValue(webDriver);

                    commandExecutor.CommandInfoRepository.TryAddCommand(DriverCommand.GetAvailableLogTypes, new CommandInfo(CommandInfo.GetCommand, "/session/{sessionId}/se/log/types"));
                    commandExecutor.CommandInfoRepository.TryAddCommand(DriverCommand.GetLog, new CommandInfo(CommandInfo.PostCommand, "/session/{sessionId}/se/log"));

                    _commandExecutors[webDriver] = commandExecutor;
                }

                var response = commandExecutor.Execute(new Command(((IHasSessionId)webDriver).SessionId, DriverCommand.GetLog, new Dictionary<string, object> { ["type"] = "browser" }));

                var fromDictionaryMethod = typeof(LogEntry).GetMethod("FromDictionary", BindingFlags.Static | BindingFlags.NonPublic);
                var logEntries = ((IEnumerable<object>)response.Value)
                    .Select(v => fromDictionaryMethod.Invoke(null, new[] { v }))
                    .OfType<LogEntry>()
                    .ToList();

                return logEntries;
        }

Thanks @Dreamescaper your workaround works perfectly

What seems like a simpler workaround to me is the following. Subclass RemoteWebDriver with your own class that implements the ISupportsLogs interface, and then use that instead of new RemoteWebDriver(...). For example:

private class RemoteWebDriverWithLogs : RemoteWebDriver, ISupportsLogs
{
    // Also pass through any constructors you want to use
}

It makes our tests work again.

Was this page helpful?
0 / 5 - 0 ratings