Skip to content

[πŸ› Bug]: BiDi BrowserContext fails to open new tabs in ChromeΒ #15860

@whrostre

Description

@whrostre

Description

When attempting to use BiDi BrowserContext to run multiple tests in parallel with a single WebDriver instance, the expected behavior is for each test to run in its own context (tab) within the same browser window. This works correctly when using Firefox β€” multiple tests run concurrently in isolated contexts, all within a single browser instance.

However, switching to Chrome (using the same code) results in each test launching a completely separate browser window.

Steps to Reproduce:
Check added code

Expected Behavior:

All tests should run in separate BrowserContexts within a single Chrome browser window.

Actual Behavior:

Each test launches its own Chrome window instead of sharing a single instance.

Environment:

Browser: Chrome 137.0.7151.55 (Official Build) (64-bit)

Image

Selenium version: 4.33.0

Operating System: Linux Mint 21.3 Cinnamon

Reproducible Code

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WindowType;
import org.openqa.selenium.bidi.browsingcontext.BrowsingContext;
import org.openqa.selenium.bidi.browsingcontext.CreateContextParameters;
import org.openqa.selenium.bidi.browsingcontext.ReadinessState;
import org.openqa.selenium.bidi.module.Browser;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

import static java.lang.Thread.sleep;

@Execution(ExecutionMode.CONCURRENT)
public class ParallelBidiChromeTests {

    private static WebDriver driver;
    BrowsingContext browsingContext;

    @BeforeAll
    public static void beforeAll() {
        ChromeOptions options = new ChromeOptions();
        options.enableBiDi();

        driver = new ChromeDriver(options);
    }

    @BeforeEach
    public void beforeEach() {
        Browser browser = new Browser(driver);
        String userContext = browser.createUserContext();

        CreateContextParameters parameters = new CreateContextParameters(WindowType.TAB);
        parameters.userContext(userContext);

        browsingContext = new BrowsingContext(driver, parameters);
    }

    @Test
    public void testOne() throws InterruptedException {
        browsingContext.navigate("https://www.example.com", ReadinessState.COMPLETE);
        sleep(5000); // Simulating some wait time
        System.out.println(
                Thread.currentThread().getName() + " " + Thread.currentThread().getStackTrace()[1]
                        .getMethodName() + " => executed successfully");
    }

    @Test
    public void testTwo() throws InterruptedException{
        browsingContext.navigate("https://www.example.com", ReadinessState.COMPLETE);
        sleep(5000); // Simulating some wait time
        System.out.println(
                Thread.currentThread().getName() + " " + Thread.currentThread().getStackTrace()[1]
                        .getMethodName() + " => executed successfully");
    }

    @Test
    public void testThree() throws InterruptedException{
        browsingContext.navigate("https://www.example.com", ReadinessState.COMPLETE);
        sleep(5000); // Simulating some wait time
        System.out.println(
                Thread.currentThread().getName() + " " + Thread.currentThread().getStackTrace()[1]
                        .getMethodName() + " => executed successfully");
    }

    @Test
    public void testFour() throws InterruptedException{
        browsingContext.navigate("https://www.example.com", ReadinessState.COMPLETE);
        sleep(5000); // Simulating some wait time
        System.out.println(
                Thread.currentThread().getName() + " " + Thread.currentThread().getStackTrace()[1]
                        .getMethodName() + " => executed successfully");
    }

    @AfterAll
    public static void cleanup() {
        driver.quit();
    }
}

Metadata

Metadata

Assignees

Labels

A-needs-triagingA Selenium member will evaluate this soon!C-javaJava BindingsD-chromeG-chromedriverRequires fixes in ChromeDriverI-defectSomething is not working as intendedOS-linux

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions