0
0
Selenium Javatesting~20 mins

Properties file for configuration in Selenium Java - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Properties File Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
1: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"));
Anull,null
Burl,timeout
Chttps://example.com,30
DError loading properties
Attempts:
2 left
💡 Hint
Check how Properties.getProperty() returns values from the loaded file.
assertion
intermediate
1: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");
AassertNull(prop.getProperty("browser"));
BassertEquals("chrome", prop.getProperty("browser"));
CassertFalse(prop.getProperty("browser").equals("chrome"));
DassertTrue(prop.getProperty("browser") == "chrome");
Attempts:
2 left
💡 Hint
Use assertEquals to compare string values in JUnit.
locator
advanced
1: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");
APlace config.properties inside src/test/resources folder
BPlace config.properties inside src/main/java folder
CPlace config.properties inside src/test/java folder
DPlace config.properties inside the project root folder
Attempts:
2 left
💡 Hint
The path in FileInputStream is relative to the project root.
🔧 Debug
advanced
2:00remaining
Why does this code throw FileNotFoundException when loading properties?
Consider this code snippet:
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?
AFileInputStream requires absolute path, relative paths are invalid
BProperties.load() cannot read files from resources folder
CThe properties file must have .txt extension to be loaded
DThe relative path "config.properties" does not point to src/test/resources, so file is not found
Attempts:
2 left
💡 Hint
Check the working directory and relative path used in FileInputStream.
framework
expert
2: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?
A
Properties prop = new Properties();
try (InputStream input = getClass().getClassLoader().getResourceAsStream("config.properties")) {
    prop.load(input);
}
B
Properties prop = new Properties();
FileInputStream fis = new FileInputStream("src/test/resources/config.properties");
prop.load(fis);
C
Properties prop = new Properties();
InputStream input = new FileInputStream("config.properties");
prop.load(input);
D
Properties prop = new Properties();
prop.load("config.properties");
Attempts:
2 left
💡 Hint
Use getResourceAsStream to load files from classpath safely.