serenity-bdd / serenity-core

Serenity BDD is a test automation library designed to make writing automated acceptance tests easier, and more fun.
http://serenity-bdd.info
Other
721 stars 517 forks source link

Setting download preferences not working in version 3.6.7 for Chrome #3051

Open vladdragomir opened 1 year ago

vladdragomir commented 1 year ago

Hello!

After upgrading Serenity from version 3.2.0 to version 3.6.7, setting the Chrome download preferences has stopped working.

Here is how I set the preferences in the serenity.config file:

capabilities {
    "goog:chromeOptions" {
        prefs {
            download.default_directory = "/home/seluser"
            download.prompt_for_download = false
         }
     }
}

capabilities {
    "moz:firefoxOptions" {
         prefs {
             download.folderList=2
             download.dir = "/home/seluser"
             download.useDownloadDir = true
             helperApps.neverAsk.saveToDisk = "application/pdf;text/plain;application/text;text/xml;application/xml"
             pdfjs.disabled = true
          }
     }
}

If I try to launch a Chrome browser with the above config, I receive the following error:

Caused by: net.thucydides.core.webdriver.DriverConfigurationError: WebDriver was unable to create a new instance of type class org.openqa.selenium.chrome.ChromeDriver

WebDriver reported the following message: class java.util.HashMap cannot be cast to class java.util.List (java.util.HashMap and java.util.List are in module java.base of loader 'bootstrap'))

However, launching Firefox works as expected and no error is thrown.

Do you have any thoughts on what might cause this and possible solutions?

Thanks!

wakaleo commented 1 year ago

I think this will be fixed in the next release (something appears to have changed in the Chromedriver drivers in the way they handle the capabilities).

vladdragomir commented 1 year ago

Thanks @wakaleo, I'll keep an eye on the releases and let you know if it's fixed by the next one.

srikanthimmidi commented 1 year ago

@wakaleo Will new release resolve headless download as well

wakaleo commented 1 year ago

I don't see any issues with headless mode in chrom for 3.6.12, either with headless.mode = true or with the W3C property.

srikanthimmidi commented 1 year ago

Serenity version : 3.4.2 Serenity.conf file

web-chrome{ webdriver { capabilities { browserName = "chrome" acceptInsecureCerts = true strictFileInteractability = true "goog:chromeOptions" { args = ["no-sandbox","disable-dev-shm-usage","window-size=1920,1080","version","incognito","headless"] prefs: {
download.default_directory= ${user.dir}"\downloads" } } } } }

Working normal in non headless mode . In headless file not getting downloaded

@wakaleo need your inputs.

Thanks, Srikanth

edudelta commented 1 year ago

I'm facing same issue for Serenity 3.6.7, 3.6.12, 3.7.1 with configuration:

webdriver {
    driver = remote
    remote {
        url="http://localhost:4444/wd/hub"
        driver=chrome
    }
    capabilities {
        browserName = "chrome"
        acceptInsecureCerts = true
        timeouts {
                pageLoad = 20000
                script = 15000
                implicit = 3000
        }
        "goog:chromeOptions" {
                excludeSwitches = [ "enable-automation" ]
                useAutomationExtension = false
                acceptInsecureCerts = true
                args = ["disable-gpu", "test-type", "no-sandbox", "disable-popup-blocking", "disable-default-apps", "disable-extensions", "disable-extensions-file-access-check", "ignore-certificate-errors", "incognito", "remote-allow-origins=*"]
                prefs {
                    download.default_directory = ${user.dir}/Downloads
                    download.prompt_for_download = false
                }
        }
    }
}

the result is:

Error
Could not instantiate class org.openqa.selenium.remote.RemoteWebDriver
Stacktrace
net.thucydides.core.webdriver.DriverConfigurationError: Could not instantiate class org.openqa.selenium.remote.RemoteWebDriver
Caused by: net.thucydides.core.webdriver.DriverConfigurationError: 
WebDriver was unable to create a new instance of type class org.openqa.selenium.remote.RemoteWebDriver
WebDriver reported the following message: Could not start a new session. Response code 500. Message: Could not start a new session. Could not start a new session. Error while creating session with the driver service. Stopping driver service: Could not start a new session. Response code 400. Message: invalid argument: entry 0 of 'firstMatch' is invalid
from invalid argument: cannot parse capability: goog:chromeOptions
from invalid argument: unrecognized chrome option: acceptInsecureCerts

same configuration is working fine with Serenity 3.4.2

shafijamadar commented 5 months ago

@wakaleo - I tried using same for serenity version 3.9+ versions however still not able to download at specific folder in headless mode. chrome version 124 Kindly advise