SeleniumHQ / selenium

A browser automation framework and ecosystem.
https://selenium.dev
Apache License 2.0
30.71k stars 8.19k forks source link

[🐛 Bug]: TimeoutException always occuring when disconnecting DevTools session #12319

Closed roxana-agache closed 1 year ago

roxana-agache commented 1 year ago

What happened?

This Warn in console always appears after a test run:

org.openqa.selenium.devtools.DevTools disconnectSession
WARNING: Exception while detaching from target: java.util.concurrent.TimeoutException

I'm using Selenium version 4.8.1 and I'm trying to intercept some requests in my tests. The tests are working fine and passing, Selenium intercepts the requests and so on but the thing that I'm concerned about is the fact that the driver for which I'm creating the DevTools session is not the same driver I'm using when e.g. interacting with DOM elements. I presume this because there's always a timeout of 10s between test/scenario runs and the time when the logging was done for DevTools session disconnection.

What am I doing wrong ?

How can we reproduce the issue?

Background:
I have set up a framework that relies on DI (Spring). I have several Java classes where I set up different kind of browsers based on a user-defined interface, and one DriverFactory class, where I create a RemoteWebDriver, bean that's managed by Spring, based on browser type. 

My ChromeDriverFactory looks like this: 

@Component
@Scope("singleton")
@Lazy
public class ChromeDriverFactory implements DriverFactory {
private ChromeOptions chromeOptions;
    private ChromeDriverService chromeDriverService;

    @PostConstruct
    @Override
    public void setupDriver() {
        WebDriverManager.chromedriver().setup();
        createAndStartService();
        chromeOptions = setChromeOptions();
    }

    @Override
    public RemoteWebDriver getDriver() {
        return new RemoteWebDriver(chromeDriverService.getUrl(), chromeOptions);
    }

    public void createAndStartService() {
        chromeDriverService = new ChromeDriverService.Builder().usingAnyFreePort().build();
        try {
            chromeDriverService.start();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    private ChromeOptions setChromeOptions() {
        ChromeOptions options = new ChromeOptions();
        options.addArguments("--lang=en-GB");
        options.addArguments("--disable-notifications");
        options.addArguments("--window-size=1920,1080");
        options.addArguments("--ignore-certificate-errors");
        options.addArguments("--remote-allow-origins=*");
        return options;
    }
}

My DriverService class contains the following:

 private DriverFactory getFactory() {
        Browsers b = Browsers.getBrowserType(browser);
        return switch (b) {
            case CHROME -> context.getBean(ChromeDriverFactory.class);
            case FIREFOX -> context.getBean(FirefoxDriverFactory.class);
            default -> context.getBean(GenericDriverFactory.class);
        };
    }

    @Bean(name = "RemoteWebDriver", destroyMethod = "quit")
    @ScenarioScope
    public RemoteWebDriver getDriver() {
        return getFactory().getDriver();
    }

    @Bean(name = "DevTools")
    @ScenarioScope
    public DevTools getDevTools(@Autowired RemoteWebDriver remoteWebDriver) {
        WebDriver driver1 = new Augmenter().augment(remoteWebDriver);
        DevTools devTools = ((HasDevTools) driver1).getDevTools();
        devTools.createSession();
        devTools.send(Network.enable(Optional.empty(), Optional.empty(), Optional.empty()));
        return devTools;
    }

I'm injecting the DevTools bean in a helper class:

@Autowired
private DevTools devTools;

public void mapRequestsAndResponsesByPathParam(List requestsList, List responsesList) { devTools.addListener(Network.requestWillBeSent(), request -> { //listener code }); devTools.addListener(Network.responseReceived(), //listener code }); }


### Relevant log output

```shell
Starting ChromeDriver 114.0.5735.90 (386bc09e8f4f2e025eddae123f36f6263096ae49-refs/branch-heads/5735@{#1052}) on port 14468
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
Jul 06, 2023 5:25:33 PM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
WARNING: Unable to find an exact match for CDP version 114, so returning the closest version found: 110
Jul 06, 2023 5:25:33 PM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
WARNING: Unable to find an exact match for CDP version 114, so returning the closest version found: 110
.
.
//logs from test run
.
.
Jul 06, 2023 5:25:52 PM org.openqa.selenium.devtools.DevTools disconnectSession
WARNING: Exception while detaching from target: java.util.concurrent.TimeoutException
Build info: version: '4.8.1', revision: '8ebccac989'
System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '13.3.1', java.version: '17.0.2'
Driver info: driver.version: unknown

Operating System

MacOS Ventura 13.3.1 (a)

Selenium version

4.8.1

What are the browser(s) and version(s) where you see this issue?

Chrome 114 (WebDriverManager from io.github.bonigarcia v5.3.2)

What are the browser driver(s) and version(s) where you see this issue?

ChromeDriver 114.0.5735.90

Are you using Selenium Grid?

No

github-actions[bot] commented 1 year ago

@roxana-agache, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

github-actions[bot] commented 1 year ago

💬 Please ask questions at:

github-actions[bot] commented 11 months ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.