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
718 stars 515 forks source link

How to change the default download directory path to some other path in serenity? #2564

Open NidhiBawankule24 opened 2 years ago

NidhiBawankule24 commented 2 years ago

I want ,if I am downloading file it should be downloaded in specific folder.

globalworming commented 2 years ago

i assume you mean you are downloading with the web browser. you basically have to set some webdriver properties, like shown here https://stackoverflow.com/a/34530160/1359903

String downloadFilepath = "/path/to/download";
HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
chromePrefs.put("profile.default_content_settings.popups", 0);
chromePrefs.put("download.default_directory", downloadFilepath);
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", chromePrefs);
DesiredCapabilities cap = DesiredCapabilities.chrome();
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
cap.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new ChromeDriver(cap);

in serenity you can set some chrome options in your serenity.properties file, but i unfortunately have no example how that would look like

patrykost commented 1 year ago

hi @globalworming, I'm wondering how to verify if file has been downloaded by click on the button if there is no href attribute present. Any tips?

globalworming commented 1 year ago

when your browser is running locally (so no grid, browser stack, etc) you can just use the java file api to check

see Files.list(Paths.get("/path/to/download")) there is probably a reliable file name to look for?

when your browser is running remotely... then you can maybe use selenium4 network interception features to check if a request to download a file has been sent

patrykost commented 1 year ago

thanks @globalworming , I'm using grid & unfortunately in my situation ONLY file content is returned by some api but file is created and returned by JS script. Any ideas?

globalworming commented 1 year ago

no