I want to test (using selenium webdriver) if clicking a button causes the right file download dialog to appear. For the automated part of the test I don't have to download the actual file, checking the filename and the window title would be enough.
At a first glance, I see no way to get this OS-specific dialog box. Do you know a way?
The two questions selenium wget download file and How to download a file using Selenium's WebDriver? are the opposite of my question -- I need the dialog, not the file.
Edit/Clarification: The system under test has a button to download a file which gets saved with the native OS dialog, and the default filename in the dialog is set from the header in the server response.
- Automated API test: Call the server, examine the header.
- Manual (full) GUI test: Klick the button, save the file, examine the filename and the contents.
- Automated (limited) GUI test: Klick the button, examine the filename, abort.
The third bullet point is the one I'm asking about.
-
1Just wondering, why do you want to test the OS file dialog? Don't you trust operating system vendors? :)Niels van Reijmersdal– Niels van Reijmersdal2015年06月17日 17:20:15 +00:00Commented Jun 17, 2015 at 17:20
-
Can't you just check the hyperlink itself for the correct filename?FDM– FDM2015年06月18日 05:45:38 +00:00Commented Jun 18, 2015 at 5:45
-
@FDM, all I'm seeing from the DOM is a javascript function. I want to test if it gives the right result.o.m.– o.m.2015年07月17日 05:23:48 +00:00Commented Jul 17, 2015 at 5:23
-
@o.m. In that case, you can also execute javascript with Selenium. It will allow you to call and verify the javascript function.FDM– FDM2015年07月17日 19:37:30 +00:00Commented Jul 17, 2015 at 19:37
2 Answers 2
I had this same problem but our tests were limited for Windows OS, so we designed a simple AutoIT script for it which would return exit code = 0 (if popup was detected) or 1 (if not detected).
This error code was checked within the selenium test script itself.
I managed to achieve this, but it is a bit complicated.
You can't automate the OS specific download dialog, if you could that would be a huge security hole.
What I did was to get the computer running the selenium test to pretend to be the client (I was using a selenium grid) and download the file and then check the contents.
To pretend to be the client I had to :
- on the server, make a copy of the "http only" cookies and send them as part of the page with the download button (pre-pending with 'download-test' to give them a unique name)
- then use selenium to extract these values
- craft a request for the download url, adding the extracted cookies
- check the contents of the downloaded file
So it's not a complete real world test, but it's pretty close.