bonigarcia / webdrivermanager

Automated driver management and other helper features for Selenium WebDriver in Java
https://bonigarcia.dev/webdrivermanager/
Apache License 2.0
2.58k stars 676 forks source link

Calling wdm.getDownloadedDriverPath() after wdm.setup() may produce a 'null' as a result #889

Closed vklonin closed 2 years ago

vklonin commented 2 years ago

Description of the problem: calling wdm.getDownloadedDriverPath() after wdm.setup() may produce a 'null' as a result

Browser and version: Chrome 103

Operating system: macOS Monterey

WebDriverManager version: 5.3.0

WebDriverManager call:

public static String downloadDriver(DriverTypes driverType, Platform platform, String version) {
        try {
            String driverName = driverType.toString();
            switch (driverType) {
                case CHROME:
                    wdm = chromedriver(); break;
                case FIREFOX:
                    wdm = firefoxdriver(); break;
                case IE:
                    wdm = iedriver(); break;
                case EDGE:
                    wdm = edgedriver(); break;
                case OPERA:
                    wdm = operadriver(); break;
                case SAFARI:
                    return isBlank(DRIVER.path)
                        ? SAFARI_INFO.path.execute()
                        : DRIVER.path;
                default:
                    throw runtimeException("%s driver not supported for download");
            }
            switch (platform) {
                case X32:
                    wdm = wdm.arch32();
                    break;
                case X64:
                    wdm = wdm.arch64();
                    break;
            }
            driverName += " " + platform;
            if (hasVersion(version)) {
                wdm = wdm.browserVersion(version);
                driverName += " " + version;
            }
            if (version.equalsIgnoreCase(PENULT.value)) {
                wdm.setup();
                wdm.browserVersion(getBelowVersion());
            }
            if (isNotBlank(DRIVER.gitHubToken)) {
                wdm.gitHubToken(DRIVER.gitHubToken);
            }
            wdm.setup();
            logger.info("Download driver: '" +  driverName + "' successfully");
            driverDownloaded = true;
            downloadedDriverInfo = format("%s:%s:%s", driverType, platform, version);
            driverPath = wdm.getDownloadedDriverPath();
            return driverPath;
        } catch (Exception ex) {
            throw exception(ex, "Can't download latest driver for " + driverType);
        }
    }
}

WebDriverManager traces:

56:52.135 [io.github.bonigarcia.wdm.online.Downloader:INFO]: Extracting driver from compressed file chromedriver_linux64.zip 198 56:52.446 [io.github.bonigarcia.wdm.WebDriverManager:INFO]: Exporting webdriver.chrome.driver as /home/runner/.cache/selenium/chromedriver/linux64/103.0.5060.134/chromedriver 199 56:52.453 [JDI:INFO]: [23] Download driver: 'CHROME X64' successfully 200 56:52.454 [JDI:INFO]: [23] Download driver path : 'null' successfully

AlexeyGirin commented 2 years ago

In other words - calling wdm.setup() and having it done successfully we would expect to have driver downloaded and ready for use. But in current webdrivermanager implementation - it is not since it continue its setup (i.e. unzipping chrome driver asynchronously). This is why it returns NULL as driver path. Can we make .setup() method wait everything done before method end?

bonigarcia commented 2 years ago

I am unable to reproduce this issue. In fact, there are several tests in WebDriverManager using getDownloadedDriverPath(), and all of them are working correctly (e.g., this one and others).

I tried the code you provided, but it seems incomplete (the imports are missing, and I think there are errors, like runtimeException). If you provide a complete self-contained Java class that reproduces the issue, I can test it on my side.

AlexeyGirin commented 2 years ago

We will try to provide problem demo, but that will be hard since it is flaky problem that appears in very specific circumstances. But sometimes - it affects up to 30% of tests ( https://github.com/jdi-testing/jdi-light/issues/2971 )

pnatashap commented 2 years ago

There is a PR https://github.com/bonigarcia/webdrivermanager/pull/895 which enables parallel test execution. They are always failed. The last run: Error: Errors: Error: CacheTest.testCache:68 » NoSuchElement No value present Error: ChromeCreateTest.setupTest:35 » WebDriverManager There was an error creating WebDriver object for Chrome Error: ChromeListCreateTest.setupTest:38 » WebDriverManager There was an error creating WebDriver object for Chrome Error: ChromeRemoteTest.setupClass:41 » Config java.lang.reflect.InvocationTargetException

AlexeyGirin commented 2 years ago

@bonigarcia please have a look on Natasha's PR: https://github.com/bonigarcia/webdrivermanager/pull/895 that demonstrates the problem

bonigarcia commented 2 years ago

Indeed, there are failed tests running the WebDriverManager tests in parallel. I just checked it once again, and the cause for failed tests in parallel is related to frozen browsers or irresponsive drivers. But I don't see any test that fails due to getDownloadedDriverPath(), sorry.

bonigarcia commented 2 years ago

Any update on this?