Skip to content

[πŸ› Bug]: [dotnet] BiDi logs potentially missing with race conditionΒ #16574

@bartecargo

Description

@bartecargo

Description

It appears that not all console logs are sent over the BiDi web socket and there is some kind of race condition when closing down the connection.

If I want to make sure that I receive all the log entries before the browser closes, it appears that I need to add a time based delay, which results in flaky and/or slow tests.

I've attached a simple example that demonstrates the logs are not send to OnEntryAddedAsync unless I add a time-based delay.

Am I doing something wrong here?

Reproducible Code

//     <PackageReference Include="Selenium.WebDriver" Version="4.38.0" />

using System.Collections.Concurrent;
using OpenQA.Selenium.BiDi;
using OpenQA.Selenium.Chrome;

var options = new ChromeOptions { UseWebSocketUrl = true };
using var driver = new ChromeDriver(options);
await using var biDi = await driver.AsBiDiAsync();
var logs = new ConcurrentBag<string?>();
await using var logSubscription = await biDi.Log.OnEntryAddedAsync(entry => logs.Add(entry.Text));

driver.Navigate().GoToUrl("about:blank");
driver.ExecuteScript("console.log('Test log.');");

//Uncommenting this line will "fix" the issue.
//await Task.Delay(1000);

if(!logs.SequenceEqual(["Test log."]))
    throw new Exception("Logs missing.");
Console.WriteLine("Logs present.");

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions