Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Sunshine And March Vibes (2025 Wallpapers Edition)

      May 15, 2025

      The Case For Minimal WordPress Setups: A Contrarian View On Theme Frameworks

      May 15, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      May 15, 2025

      How To Prevent WordPress SQL Injection Attacks

      May 15, 2025

      Intel’s latest Arc graphics driver is ready for DOOM: The Dark Ages, launching for Premium Edition owners on PC today

      May 15, 2025

      NVIDIA’s drivers are causing big problems for DOOM: The Dark Ages, but some fixes are available

      May 15, 2025

      Capcom breaks all-time profit records with 10% income growth after Monster Hunter Wilds sold over 10 million copies in a month

      May 15, 2025

      Microsoft plans to lay off 3% of its workforce, reportedly targeting management cuts as it changes to fit a “dynamic marketplace”

      May 15, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      A cross-platform Markdown note-taking application

      May 15, 2025
      Recent

      A cross-platform Markdown note-taking application

      May 15, 2025

      AI Assistant Demo & Tips for Enterprise Projects

      May 15, 2025

      Celebrating Global Accessibility Awareness Day (GAAD)

      May 15, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      Intel’s latest Arc graphics driver is ready for DOOM: The Dark Ages, launching for Premium Edition owners on PC today

      May 15, 2025
      Recent

      Intel’s latest Arc graphics driver is ready for DOOM: The Dark Ages, launching for Premium Edition owners on PC today

      May 15, 2025

      NVIDIA’s drivers are causing big problems for DOOM: The Dark Ages, but some fixes are available

      May 15, 2025

      Capcom breaks all-time profit records with 10% income growth after Monster Hunter Wilds sold over 10 million copies in a month

      May 15, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»Integrating KeywordLogger with Test Listeners in Katalon Studio

    Integrating KeywordLogger with Test Listeners in Katalon Studio

    June 10, 2024

    Effective logging is crucial in test automation. It helps testers track test execution, identify issues, and understand skipped steps. Katalon Studio’s KeywordLogger provides a versatile logging mechanism, which can be enhanced further by integrating with Test Listeners. This blog will guide you through the integration process, offering practical examples to illustrate the concepts.

     

    What is KeywordLogger?

    KeywordLogger is a logging utility in Katalon Studio that allows you to log different types of messages, such as informational messages, errors, and skipped steps. These logs provide a detailed account of the test execution flow, aiding in debugging and reporting.

    Setting Up Test Listeners

    To set up Test Listeners in Katalon Studio, you need to create a new Groovy script in the Test Listeners folder of your Katalon project. This script will define methods annotated with listener annotations like @BeforeTestCase, @AfterTestCase, @BeforeTestSuite, and @AfterTestSuite.

    Creating a Test Listener

    Create the Test Listeners folder in your Katalon project.
    Create a new Groovy script. For instance, name it LoggingListener.

    Integrating KeywordLogger with Test Listeners

    Let’s create a comprehensive Test Listener that logs messages at different stages of the test lifecycle.

     

    Step-by-Step Guide

    Import necessary classes:

    import com.kms.katalon.core.logging.KeywordLogger

    import com.kms.katalon.core.annotation.BeforeTestCase

    import com.kms.katalon.core.annotation.AfterTestCase

    import com.kms.katalon.core.annotation.BeforeTestSuite

    import com.kms.katalon.core.annotation.AfterTestSuite

    import com.kms.katalon.core.context.TestCaseContext

    import com.kms.katalon.core.context.TestSuiteContext

     

    Initialize the KeywordLogger:

    KeywordLogger logger = new KeywordLogger()

     

    Define the methods with appropriate annotations:

    @BeforeTestCase

    def beforeTestCase(TestCaseContext testCaseContext) {

        logger.logInfo(“Starting test case: ” + testCaseContext.getTestCaseId())

    }

    @AfterTestCase

    def afterTestCase(TestCaseContext testCaseContext) {

        if (testCaseContext.getTestCaseStatus() == ‘FAILED’) {

            logger.logError(“Test case failed: ” + testCaseContext.getTestCaseId())

        } else {

            logger.logInfo(“Completed test case: ” + testCaseContext.getTestCaseId())

        }

    }

    @BeforeTestSuite

    def beforeTestSuite(TestSuiteContext testSuiteContext) {

        logger.logInfo(“Starting test suite: ” + testSuiteContext.getTestSuiteId())

    }

    @AfterTestSuite

    def afterTestSuite(TestSuiteContext testSuiteContext) {

        logger.logInfo(“Completed test suite: ” + testSuiteContext.getTestSuiteId())

    }

     

    Full Example

    Here’s the complete code for a Test Listener that integrates KeywordLogger:

    import com.kms.katalon.core.logging.KeywordLogger

    import com.kms.katalon.core.annotation.BeforeTestCase

    import com.kms.katalon.core.annotation.AfterTestCase

    import com.kms.katalon.core.annotation.BeforeTestSuite

    import com.kms.katalon.core.annotation.AfterTestSuite

    import com.kms.katalon.core.context.TestCaseContext

    import com.kms.katalon.core.context.TestSuiteContext

    KeywordLogger logger = new KeywordLogger()

    @BeforeTestCase

    def beforeTestCase(TestCaseContext testCaseContext) {

        logger.logInfo(“Starting test case: ” + testCaseContext.getTestCaseId())

    }

    @AfterTestCase

    def afterTestCase(TestCaseContext testCaseContext) {

        if (testCaseContext.getTestCaseStatus() == ‘FAILED’) {

            logger.logError(“Test case failed: ” + testCaseContext.getTestCaseId())

        } else {

            logger.logInfo(“Completed test case: ” + testCaseContext.getTestCaseId())

        }

    }

    @BeforeTestSuite

    def beforeTestSuite(TestSuiteContext testSuiteContext) {

        logger.logInfo(“Starting test suite: ” + testSuiteContext.getTestSuiteId())

    }

    @AfterTestSuite

    def afterTestSuite(TestSuiteContext testSuiteContext) {

        logger.logInfo(“Completed test suite: ” + testSuiteContext.getTestSuiteId())

    }

     

    Practical Examples

    Let’s look at some practical examples to understand how this integration works in real-world scenarios.

    Example 1: Logging Test Case Execution

    Imagine you have a test case for verifying user login functionality. By using the integrated Test Listener, you automatically log the start and end of the test case execution.

    Test Case Script:

    import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase

    import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

    WebUI.openBrowser(”)

    WebUI.navigateToUrl(‘https://example.com/login’)

    WebUI.setText(findTestObject(‘Page_Login/txt_Username’), ‘username’)

    WebUI.setText(findTestObject(‘Page_Login/txt_Password’), ‘password’)

    WebUI.click(findTestObject(‘Page_Login/btn_Login’))

    WebUI.verifyElementPresent(findTestObject(‘Page_Home/lbl_LoggedIn’), 10)

    WebUI.closeBrowser()

     

    Logged Output:

    INFO: Starting test case: Test Cases/Verify User Login

    INFO: Completed test case: Test Cases/Verify User Login

     

    If the login fails, the output will include an error log:

    INFO: Starting test case: Test Cases/Verify User Login

    ERROR: Test case failed: Test Cases/Verify User Login

     

    Example 2: Logging Test Suite Execution

    Consider a test suite that runs multiple test cases related to user registration. The integrated Test Listener logs the start and end of the test suite.

    Test Suite Script:

    Verify User Registration
    Verify User Registration with Invalid Data
    Verify User Registration without Mandatory Fields

     

    Logged Output:

    INFO: Starting test suite: Test Suites/User Registration Tests

    INFO: Starting test case: Test Cases/Verify User Registration

    INFO: Completed test case: Test Cases/Verify User Registration

    INFO: Starting test case: Test Cases/Verify User Registration with Invalid Data

    ERROR: Test case failed: Test Cases/Verify User Registration with Invalid Data

    INFO: Starting test case: Test Cases/Verify User Registration without Mandatory Fields

    INFO: Completed test case: Test Cases/Verify User Registration without Mandatory Fields

    INFO: Completed test suite: Test Suites/User Registration Tests

     

    Best Practices for Effective Logging

    Combine Logs for Clarity

    By combining logInfo, logError, and logSkipped messages, you create a detailed and clear log that covers all aspects of your test case execution. This practice ensures you have comprehensive logs for easy debugging and reporting.

    Use Test Listeners for Consistency

    Integrating KeywordLogger with Test Listeners ensures that logs are consistently recorded at key points in your test lifecycle without manual intervention. This approach helps maintain a standardized logging format across all test cases and suites.

    Monitor and Review Logs Regularly

    Regularly monitoring and reviewing your logs helps identify patterns, recurring issues, and opportunities for improving your test scripts and overall testing process. Consistent log review ensures that any issues are quickly identified and addressed, enhancing the reliability of your tests.

    Conclusion

    Integrating KeywordLogger with Test Listeners in Katalon Studio provides comprehensive and consistent logs, automatically capturing key events throughout your test lifecycle.

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleUnleashing the Power AI: A Guide to Supercharge Your Salesforce Experience Cloud
    Next Article Guide to Using KeywordLogger in Katalon Studio

    Related Posts

    Development

    February 2025 Baseline monthly digest

    May 15, 2025
    Artificial Intelligence

    Markus Buehler receives 2025 Washington Award

    May 15, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    “The first 2-in-1 Copilot+ PC to challenge Microsoft’s Surface Pro 11” is $300 off for a limited time

    News & Updates

    Optics11 raises €17M to enhance power infrastructure resilience in Europe

    News & Updates

    Faster distributed graph neural network training with GraphStorm v0.4

    Machine Learning

    CSS Hover Effects: 40 Engaging Animations To Try

    Development

    Highlights

    CVE-2025-3710 – “KVM Over IP Switch CL5708IM Stack-based Buffer Overflow Vulnerability”

    May 9, 2025

    CVE ID : CVE-2025-3710

    Published : May 9, 2025, 4:16 a.m. | 2 hours, 25 minutes ago

    Description : The LCD KVM over IP Switch CL5708IM has a Stack-based Buffer Overflow vulnerability, allowing unauthenticated remote attackers to exploit this vulnerability to execute arbitrary code on the device.

    Severity: 9.8 | CRITICAL

    Visit the link for more details, such as CVSS details, affected products, timeline, and more…

    Enhancing Diffusion Models: The Role of Sparsity and Regularization in Efficient Generative AI

    February 18, 2025

    Iranian Hackers Deploy WezRat Malware in Attacks Targeting Israeli Organizations

    November 15, 2024

    How to use feature flags

    June 5, 2024
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.