0
0
Selenium Javatesting~10 mins

Configuration management in Selenium Java - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to load the configuration file using Properties class.

Selenium Java
Properties config = new Properties();
FileInputStream input = new FileInputStream("config.properties");
config.[1](input);
Drag options to blanks, or click blank then click option'
Aget
Bread
Copen
Dload
Attempts:
3 left
💡 Hint
Common Mistakes
Using read() instead of load() causes a compilation error.
Using get() or open() methods which do not exist in Properties.
2fill in blank
medium

Complete the code to retrieve the URL value from the configuration.

Selenium Java
String url = config.[1]("url");
Drag options to blanks, or click blank then click option'
AgetProperty
Bget
Cfetch
DreadProperty
Attempts:
3 left
💡 Hint
Common Mistakes
Using get() causes a compilation error because Properties does not have get().
Using fetch() or readProperty() which are not valid methods.
3fill in blank
hard

Fix the error in the code to properly close the FileInputStream after loading properties.

Selenium Java
FileInputStream input = new FileInputStream("config.properties");
Properties config = new Properties();
config.load(input);
input.[1]();
Drag options to blanks, or click blank then click option'
Aclose
Bshutdown
Cdispose
Dexit
Attempts:
3 left
💡 Hint
Common Mistakes
Using shutdown(), dispose(), or exit() causes compilation errors.
Not closing the stream causes resource leaks.
4fill in blank
hard

Fill both blanks to set a system property and retrieve it.

Selenium Java
System.setProperty("browser", [1]);
String browserName = System.[2]("browser");
Drag options to blanks, or click blank then click option'
A"chrome"
BgetProperty
CgetEnv
D"firefox"
Attempts:
3 left
💡 Hint
Common Mistakes
Using getEnv() instead of getProperty() to retrieve system properties.
Not using quotes around the browser name string.
5fill in blank
hard

Fill all three blanks to create a WebDriver instance based on configuration and open the URL.

Selenium Java
String browser = config.getProperty("browser");
WebDriver driver;
if (browser.equalsIgnoreCase([1])) {
    driver = new ChromeDriver();
} else if (browser.equalsIgnoreCase([2])) {
    driver = new FirefoxDriver();
} else {
    driver = new EdgeDriver();
}
driver.get([3]);
Drag options to blanks, or click blank then click option'
A"chrome"
B"firefox"
Cconfig.getProperty("url")
D"edge"
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around browser names causes errors.
Using a literal URL string instead of fetching from config.