Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a logger instance named 'logger'.
Selenium Java
Logger logger = Logger.getLogger([1].class.getName());
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Logger' or 'System' instead of the class name.
Using 'WebDriver' which is unrelated to logging.
✗ Incorrect
The logger is usually named after the class where it is used. Here, 'TestSteps' is the class name.
2fill in blank
mediumComplete the code to log an info message 'Test started'.
Selenium Java
logger.[1]("Test started");
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using debug or error instead of info for normal messages.
Using warn which is for caution messages.
✗ Incorrect
Use the info method to log informational messages like test start.
3fill in blank
hardFix the error in the code to log a warning message 'Low disk space'.
Selenium Java
logger.[1]("Low disk space");
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'warning' which is not a method in Logger.
Using 'alert' or 'notice' which do not exist in Logger.
✗ Incorrect
The correct method to log a warning in Java's Logger is warn.
4fill in blank
hardFill both blanks to log an error with an exception message.
Selenium Java
try { // test code } catch (Exception e) { logger.[1]("Error occurred: " + e.[2]()); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'toString' which returns full exception info, not just message.
Using 'printStackTrace' which prints to console, not returns a string.
✗ Incorrect
Use error to log errors and getMessage() to get the exception message.
5fill in blank
hardFill all three blanks to log a debug message with the current test step number.
Selenium Java
int step = 3; logger.[1]("Executing step " + [2] + ": " + [3]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using info instead of debug for detailed steps.
Using a number literal instead of the variable for step number.
✗ Incorrect
Use debug for detailed messages, the variable step for step number, and a string describing the step.