๐ดLog4j
๐ Log4j in Selenium
Log4j is a popular logging framework used in Selenium.
๐ Logging in Selenium
Logs provide visibility into test execution.
Help debug failures and issues.
Log4j is integrated with Selenium binding.
๐ชต Log4j Architecture
๐ Loggers - Capture log statements from code
๐๏ธ Appenders - Publish logs to destinations like file, console etc.
๐ง Layouts - Formats logging output
๐ Levels - Specify logging granularity like INFO, DEBUG etc.
๐ Benefits
๐ก Debugging capabilities
๐ Granular control of logging
๐ Asynchronous logging
๐ Log to multiple destinations
๐ Log4j Example for CNBC
//Set up logger
private static final Logger log = LogManager.getLogger(CNBCLoginTest.class);
public void testValidLogin() {
log.info("Navigating to CNBC login page"); //Simple log statement
//Log variable data
log.debug("Input username: " + username);
//Log exceptions
try {
login(username,password);
} catch(Exception e) {
log.error("Login failed!", e);
}
//Check if logged in
log.info("Login successful.");
}
This shows how Log4j can be used for logging in Selenium tests for CNBC.
Last updated
Was this helpful?