๐ŸŒด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