Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
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.
✗ Incorrect
The Properties class uses the load() method to read key-value pairs from a file input stream.
2fill in blank
mediumComplete 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'
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.
✗ Incorrect
The getProperty() method retrieves the value associated with a key in Properties.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using shutdown(), dispose(), or exit() causes compilation errors.
Not closing the stream causes resource leaks.
✗ Incorrect
The close() method properly releases the resource held by FileInputStream.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using getEnv() instead of getProperty() to retrieve system properties.
Not using quotes around the browser name string.
✗ Incorrect
System.setProperty sets the property value as a string; getProperty retrieves it by key.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around browser names causes errors.
Using a literal URL string instead of fetching from config.
✗ Incorrect
The blanks require the browser names as strings and the URL from config to open the page.