Challenge - 5 Problems
File Download Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this Selenium Java code snippet for file download?
Consider the following Selenium Java code that sets up a Firefox profile to automatically download PDF files without showing the download dialog. What will be the value of
downloadDir after execution?Selenium Java
FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("browser.download.folderList", 2); profile.setPreference("browser.download.dir", "/tmp/downloads"); profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/pdf"); WebDriver driver = new FirefoxDriver(new FirefoxOptions().setProfile(profile)); String downloadDir = profile.getString("browser.download.dir");
Attempts:
2 left
💡 Hint
Look at the preference set for "browser.download.dir" in the Firefox profile.
✗ Incorrect
The code explicitly sets the download directory to "/tmp/downloads" using the preference "browser.download.dir". Retrieving this preference returns the same path.
❓ assertion
intermediate1:30remaining
Which assertion correctly verifies the downloaded file exists?
You have downloaded a file named "report.pdf" to the directory "/tmp/downloads". Which assertion correctly checks that the file exists using Java's JUnit?
Selenium Java
File downloadedFile = new File("/tmp/downloads/report.pdf");Attempts:
2 left
💡 Hint
Check the method that verifies if a file exists on disk.
✗ Incorrect
The method exists() returns true if the file exists. Using assertTrue(downloadedFile.exists()) correctly asserts the file presence.
🔧 Debug
advanced2:30remaining
Why does this Selenium Java code fail to download the file automatically?
Review the code below. The test expects to download a CSV file automatically, but the browser shows a download dialog instead. What is the main reason?
Selenium Java
FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("browser.download.folderList", 2); profile.setPreference("browser.download.dir", "/tmp/downloads"); // Missing setting for MIME type WebDriver driver = new FirefoxDriver(new FirefoxOptions().setProfile(profile)); driver.get("http://example.com/download.csv");
Attempts:
2 left
💡 Hint
Check if the browser knows which file types to download automatically.
✗ Incorrect
Without setting the MIME type for CSV files in "browser.helperApps.neverAsk.saveToDisk", Firefox will prompt the user with a download dialog instead of saving automatically.
❓ framework
advanced2:00remaining
Which Selenium Java framework feature helps verify file download completion?
In automated tests, which approach best ensures that a file has finished downloading before assertions run?
Attempts:
2 left
💡 Hint
Think about waiting for a condition rather than a fixed delay.
✗ Incorrect
Explicit waits that check the file exists and that its size does not change over a short period confirm the download is complete reliably.
🧠 Conceptual
expert3:00remaining
What is the best practice for handling file downloads in Selenium tests to avoid flaky tests?
Choose the best practice to handle file downloads in Selenium automated tests to ensure reliability and maintainability.
Attempts:
2 left
💡 Hint
Think about automation stability and avoiding UI dialogs.
✗ Incorrect
Configuring the browser to auto-download files to a known folder and verifying file presence programmatically avoids flaky UI interactions and improves test reliability.