Challenge - 5 Problems
Properties File Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate1:30remaining
What is the output of this Java code reading a properties file?
Given the following Java code snippet that reads a properties file, what will be printed if the properties file contains
url=https://example.com?
timeout=30
Selenium Java
Properties prop = new Properties(); try (FileInputStream fis = new FileInputStream("config.properties")) { prop.load(fis); } catch (IOException e) { System.out.println("Error loading properties"); } System.out.println(prop.getProperty("url") + "," + prop.getProperty("timeout"));
Attempts:
2 left
💡 Hint
Check how Properties.getProperty() returns values from the loaded file.
✗ Incorrect
The Properties object loads key-value pairs from the file. getProperty("url") returns "https://example.com" and getProperty("timeout") returns "30" as strings.
❓ assertion
intermediate1:30remaining
Which assertion correctly verifies the loaded property value?
You have loaded a properties file with a key "browser" set to "chrome". Which assertion correctly checks this in a JUnit test?
Selenium Java
Properties prop = new Properties(); prop.setProperty("browser", "chrome");
Attempts:
2 left
💡 Hint
Use assertEquals to compare string values in JUnit.
✗ Incorrect
assertEquals compares the expected string "chrome" with the actual property value correctly. Using == compares references, which is incorrect for strings.
❓ locator
advanced1:30remaining
Identify the best locator to find the properties file in a Selenium Java project
In a Selenium Java project, where should the properties file be placed to be loaded with this code snippet?
FileInputStream fis = new FileInputStream("src/test/resources/config.properties");Attempts:
2 left
💡 Hint
The path in FileInputStream is relative to the project root.
✗ Incorrect
The code uses the relative path src/test/resources/config.properties, so the file must be inside src/test/resources folder to be found.
🔧 Debug
advanced2:00remaining
Why does this code throw FileNotFoundException when loading properties?
Consider this code snippet:
The file config.properties exists in src/test/resources but the code throws FileNotFoundException. Why?
Properties prop = new Properties();
FileInputStream fis = new FileInputStream("config.properties");
prop.load(fis);The file config.properties exists in src/test/resources but the code throws FileNotFoundException. Why?
Attempts:
2 left
💡 Hint
Check the working directory and relative path used in FileInputStream.
✗ Incorrect
FileInputStream with "config.properties" looks in the project root folder, not in src/test/resources. The file must be referenced with the correct relative path or loaded as a resource stream.
❓ framework
expert2:30remaining
How to load properties file using class loader in Selenium Java framework?
Which code snippet correctly loads a properties file named "config.properties" placed in src/test/resources using the class loader in a Selenium Java framework?
Attempts:
2 left
💡 Hint
Use getResourceAsStream to load files from classpath safely.
✗ Incorrect
Option A uses the class loader to load the properties file as a stream from the classpath, which is the recommended way in frameworks. Others either use incorrect paths or invalid methods.