Can someone help me How to check if file got downloaded from browser using selenium2library,RobotFramework.In my current test I am able to click the download button and file is getting downloaded but what happens if the file didn't get downloaded eventhough button is clicked. Any sample code is helpful.
1
votes
Selenium2Library handles only things that happen inside browser. You should use OperatingSystem library to check that file exists on disk. Maybe use "File Should Exist" keyword
– Pekka
Thank you @Pekka , Any possibility to give auto-download option in browser to particular directory
– Auto-learner
Can i know File Should Exist keyword is platform independent or not ? My tests need to execute on Linux and windows platforms
– Auto-learner
code that i am trying is as follows,please let me know what is wrong in that ${preferences} = Create Dictionary browser.download.folderList = 2 browser.download.dir = C:/Users/mra001/Downloads/Cambium_Builds open browser ${cnMaestro_URL} ${Browser} desired_capabilities=${preferences}
– Auto-learner
Unfortunately Selenium2Library Open Browser keyword documentation says you can use desired_capabilities only if you are using a remote server. This would explain why your code does not work. I think a workaround is to create a new firefox profile and load it with ff_profile_dir parameter. Check Firefox profiles from here: support.mozilla.org/en-US/kb/…
– Pekka
3 Answers
5
votes
In chrome I open the chrome://downloads
page and then retrieve the downloaded files list from shadow DOM like this:
const docs = document
.querySelector('downloads-manager')
.shadowRoot.querySelector('#downloads-list')
.getElementsByTagName('downloads-item');
This solution is restrained to chrome, the data also contains information like file path and download date.
2
votes
Check out this link - http://ardesco.lazerycode.com/testing/webdriver/2012/07/25/how-to-download-files-with-selenium-and-why-you-shouldnt.html
Also, here's how you can auto-download the file to a particular directory -
FirefoxProfile profile = new FirefoxProfile();
profile.SetPreference("browser.download.folderList",2);
profile.SetPreference("browser.download.dir", @"c:\path\to\downloads \folder");
FirefoxDriver driver = new FirefoxDriver(profile);
0
votes
u can use following python function to download file without showing dialog box.
Also u can set preference for which type of files save file dialog box should not get displayed.
def create_profile():
from selenium import webdriver
fp =webdriver.FirefoxProfile()
fp.set_preference("browser.download.folderList",2)
fp.set_preference("browser.download.manager.showWhenStarting",False)
fp.set_preference("browser.download.dir",'C:/Users/mra001/Downloads/Cambium_Builds')
fp.set_preference("browser.helperApps.neverAsk.saveToDisk",'text/csv/xls')
fp.update_preferences()
return fp.path