bonigarcia / webdrivermanager

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

Could not start browser #1005

Closed hemanshurana closed 1 year ago

hemanshurana commented 1 year ago

Description of the problem: Start getting the error after i update chrome browser Browser and version: Chrome Version 111.0.5563.65 Operating system: Windows 10 Enterprise

WebDriverManager version: 5.3.1 and 5.3.2

WebDriverManager call:

public static void openBrowser(String browserType) throws MalformedURLException {
WebDriver driver;
        WebDriverManager.chromedriver().setup();
        ChromeOptions options = new ChromeOptions();
        switch (browserType) {
            case "chrome":
                options = new ChromeOptions();
                options.addArguments("window-size=1920,1080");
                options.addArguments("--disable-extensions");
                options.addArguments("--disable-dev-shm-usage");
                HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
                chromePrefs.put("profile.default_content_settings.popups", 0);
                //Following line use to disable notification alerts
                chromePrefs.put("profile.default_content_setting_values.notifications", 2);
                String fileSeparator= System.getProperty("file.separator");
                String downloadFilepath =System.getProperty("user.dir")+fileSeparator+"src"+fileSeparator+"main"+fileSeparator+"resources"+fileSeparator+"Download";
                System.out.println(downloadFilepath);
                chromePrefs.put("download.default_directory", downloadFilepath);
                options.setExperimentalOption("prefs", chromePrefs);
                options.setCapability(ChromeOptions.CAPABILITY, options);

                    driver = new ChromeDriver(options);
                    logger.info("Local Chrome driver has been successfully started");
break;
            }

WebDriverManager traces:

Error log:

io.github.bonigarcia.wdm.config.WebDriverManagerException: org.apache.hc.core5.http.ConnectionClosedException: Premature end of Content-Length delimited message body (expected: 7122131; received: 7109632)
    at io.github.bonigarcia.wdm.WebDriverManager.handleException(WebDriverManager.java:1423)
    at io.github.bonigarcia.wdm.WebDriverManager.manage(WebDriverManager.java:1204)
    at io.github.bonigarcia.wdm.WebDriverManager.fallback(WebDriverManager.java:1439)
    at io.github.bonigarcia.wdm.WebDriverManager.handleException(WebDriverManager.java:1420)
    at io.github.bonigarcia.wdm.WebDriverManager.manage(WebDriverManager.java:1204)
    at io.github.bonigarcia.wdm.WebDriverManager.handleException(WebDriverManager.java:1413)
    at io.github.bonigarcia.wdm.WebDriverManager.manage(WebDriverManager.java:1204)
    at io.github.bonigarcia.wdm.WebDriverManager.setup(WebDriverManager.java:419)
    at com.nationalgrid.uaf.base.BrowserFactory.openBrowser(BrowserFactory.java:44)
    at com.nationalgrid.uaf.base.BrowserFactory.createWebDriver(BrowserFactory.java:164)
    at com.nationalgrid.uaf.steps.TestInitializeHooks.beforeScenario(TestInitializeHooks.java:35)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at io.cucumber.java.Invoker.doInvoke(Invoker.java:66)
    at io.cucumber.java.Invoker.invoke(Invoker.java:24)
    at io.cucumber.java.AbstractGlueDefinition.invokeMethod(AbstractGlueDefinition.java:47)
    at io.cucumber.java.JavaHookDefinition.execute(JavaHookDefinition.java:64)
    at io.cucumber.core.runner.CoreHookDefinition.execute(CoreHookDefinition.java:46)
    at io.cucumber.core.runner.HookDefinitionMatch.runStep(HookDefinitionMatch.java:21)
    at io.cucumber.core.runner.ExecutionMode$1.execute(ExecutionMode.java:10)
    at io.cucumber.core.runner.TestStep.executeStep(TestStep.java:85)
    at io.cucumber.core.runner.TestStep.run(TestStep.java:57)
    at io.cucumber.core.runner.TestCase.run(TestCase.java:78)
    at io.cucumber.core.runner.Runner.runPickle(Runner.java:75)
    at io.cucumber.testng.TestNGCucumberRunner.lambda$runScenario$1(TestNGCucumberRunner.java:132)
    at io.cucumber.core.runtime.CucumberExecutionContext.lambda$runTestCase$5(CucumberExecutionContext.java:129)
    at io.cucumber.core.runtime.RethrowingThrowableCollector.executeAndThrow(RethrowingThrowableCollector.java:23)
    at io.cucumber.core.runtime.CucumberExecutionContext.runTestCase(CucumberExecutionContext.java:129)
    at io.cucumber.testng.TestNGCucumberRunner.runScenario(TestNGCucumberRunner.java:129)
    at io.cucumber.testng.AbstractTestNGCucumberTests.runScenario(AbstractTestNGCucumberTests.java:35)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.testng.internal.invokers.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:135)
    at org.testng.internal.invokers.TestInvoker.invokeMethod(TestInvoker.java:673)
    at org.testng.internal.invokers.TestInvoker.invokeTestMethod(TestInvoker.java:220)
    at org.testng.internal.invokers.MethodRunner.runInSequence(MethodRunner.java:50)
    at org.testng.internal.invokers.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:945)
    at org.testng.internal.invokers.TestInvoker.invokeTestMethods(TestInvoker.java:193)
    at org.testng.internal.invokers.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
    at org.testng.internal.invokers.TestMethodWorker.run(TestMethodWorker.java:128)
    at java.util.ArrayList.forEach(ArrayList.java:1259)
    at org.testng.TestRunner.privateRun(TestRunner.java:808)
    at org.testng.TestRunner.run(TestRunner.java:603)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:429)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:423)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:383)
    at org.testng.SuiteRunner.run(SuiteRunner.java:326)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:95)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1249)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
    at org.testng.TestNG.runSuites(TestNG.java:1092)
    at org.testng.TestNG.run(TestNG.java:1060)
    at com.intellij.rt.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:66)
    at com.intellij.rt.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:109)
Caused by: org.apache.hc.core5.http.ConnectionClosedException: Premature end of Content-Length delimited message body (expected: 7122131; received: 7109632)
    at org.apache.hc.core5.http.impl.io.ContentLengthInputStream.read(ContentLengthInputStream.java:177)
    at org.apache.hc.core5.http.io.EofSensorInputStream.read(EofSensorInputStream.java:135)
    at org.apache.hc.core5.http.io.EofSensorInputStream.read(EofSensorInputStream.java:148)
    at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:1309)
    at org.apache.commons.io.IOUtils.copy(IOUtils.java:978)
    at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:1282)
    at org.apache.commons.io.IOUtils.copy(IOUtils.java:953)
    at org.apache.commons.io.FileUtils.copyToFile(FileUtils.java:1043)
    at org.apache.commons.io.FileUtils.copyInputStreamToFile(FileUtils.java:952)
    at io.github.bonigarcia.wdm.online.Downloader.downloadAndExtract(Downloader.java:135)
    at io.github.bonigarcia.wdm.online.Downloader.download(Downloader.java:90)
    at io.github.bonigarcia.wdm.WebDriverManager.download(WebDriverManager.java:1282)
    at io.github.bonigarcia.wdm.WebDriverManager.manage(WebDriverManager.java:1198)
bonigarcia commented 1 year ago

This problem seems to happen when downloading chromedriver. I did a quick search, and it seems caused on the server-side (e.g., this), but this is the first time I have seen that.

Is this error persistent on your side?

Raspikabek commented 1 year ago

Wonder if this has something to do with the ChromeDriver versions available.

I've had recently issues in MacOS when using 111.0.5563.64 , the mappings in https://github.com/bonigarcia/webdrivermanager/blob/master/src/main/resources/versions.properties don't have the latest versions yet, so I was facing issues with Chrome possiblity due to this file needs a quick update.

The problem for this particular issue might be that ChromeDriver site (https://chromedriver.chromium.org/downloads) does not seems to have the latest version 111.0.5563.65 uploaded there yet? Which might be a problem for you @hemanshurana

Any thoughts @bonigarcia ?

hemanshurana commented 1 year ago

@bonigarcia Yes this error persistent on my side after update chrome browser

ka1979 commented 1 year ago

@bonigarcia @hemanshurana Hey I had a similar issue on mac and I don't think it has to do with this plugin but the new update: here's what I did to fix it based on this video.

ChromeOptions options = new ChromeOptions(); options.addArguments("--remote-allow-origins=*"); DesiredCapabilities cp=new DesiredCapabilities(); cp.setCapability(ChromeOptions.CAPABILITY, options); options.merge(cp); WebDriverManager.chromedriver().setup();

bonigarcia commented 1 year ago

Indeed, this is an issue in Selenium with Chrome 111 (see issue). It seems the workaround so far is to include --remote-allow-origins=* in the ChromeOptions. I'm closing this issue since this it is not due to WebDriverManager.