Lecture Notes: Logging in Test Automation Framework
Overview of Logging
- Logging: Recording events in text format during test execution.
- Purpose: Helps in tracking application behavior and debugging.
Types of Logs
- Application Logs: Generated when users perform actions on the application. Useful for tracking unauthorized activities.
- Automation Logs: Generated during automated test execution. Helps developers understand failures.
Advantages of Logging
- Tracking: Helps to track user actions and system behavior.
- Security: Logs can track unauthorized access and allow for immediate action.
- Debugging: Enables developers to analyze issues based on detailed logs.
Types of Log Levels
- Trace: Most detailed logs, including all events.
- Debug: Detailed logs useful for debugging issues.
- Info: General information about application flow.
- Warning: Indicates potential issues.
- Error: Logs errors encountered during execution.
- Fatal: Critical errors leading to application failure.
Logging Framework: Log4j
- Log4j allows configuration of logging behavior via a
log4j2.xml
file.
- Appenders determine where logs are written (file, console, etc.).
- Loggers determine what level of logs to capture.
Implementing Logging in Automation Framework
- Add log4j2 Dependency: Update
pom.xml
with the required log4j dependencies.
- Create Configuration File:
log4j2.xml
should be placed in the src/test/resources
folder.
- Modify Base Class: Update setup method to initialize logging using Log4j.
- Add Logging Statements: Use logger in test cases to log various actions.
Logger Usage in Test Cases
- Use
logger.info()
, logger.debug()
, logger.error()
etc., to log messages.
- Log messages should be meaningful and help in understanding test flow.
Parallel and Cross-Browser Testing
- Create separate testng XML files to configure tests for different browsers and to enable parallel execution.
- Use parameters in testng XML to pass browser and OS details to the tests.
Sample XML Structure
<suite name="Suite">
<test name="Chrome Test">
<parameter name="browser" value="chrome" />
<classes>
<class name="TestClassName" />
</classes>
</test>
<test name="Firefox Test">
<parameter name="browser" value="firefox" />
<classes>
<class name="TestClassName" />
</classes>
</test>
</suite>
Configuring Properties File
- Purpose: Store common values used across multiple test cases (e.g., URLs, credentials).
- Create a
config.properties
file in the resources folder.
- Load properties using Java's
Properties
class in the base class setup method.
Accessing Properties
- Use
properties.getProperty("key")
to retrieve values from the properties file.
Summary
- Steps to follow in implementing the framework:
- Setup logging with Log4j.
- Configure cross-browser and parallel testing.
- Read common values from a properties file.
- Continuously add logging in new test cases.
Next Steps
- Begin implementing the next test case and integrate logging.
- Follow the structured approach provided in the lecture.
- Complete the assigned steps before moving on to the next.