Skip to main content

Quality Assurance

Choosing Between callTestCase and Custom Keywords in Katalon Studio

Business Man Staring At Screens of Code

Understanding the differences between using callTestCase and custom keywords in Katalon Studio is crucial for effective test automation. Both methods serve the purpose of code reuse, but they have distinct applications, advantages, and limitations. This blog will explore these differences, helping you decide when to use each approach and which one might be better suited for your needs.

What is callTestCase?

The callTestCase method allows one test case to invoke another test case within Katalon Studio. This is particularly useful for organizing tests into modular components, where a test case can serve as a helper for multiple other test cases.

// Main Test Case

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

// Call another test case

WebUI.callTestCase(findTestCase('Login Tests/Valid Login'),

                    [('username') : 'testUser', ('password') : 'testPass'],

                    FailureHandling.STOP_ON_FAILURE)

Advantages of Using callTestCase:

  1. Modularity: By breaking down complex test scenarios into simpler, reusable test cases, you can improve the maintainability of your test suite.
  2. Ease of Use: Test cases called with callTestCase can be easily managed and viewed in the Test Explorer, making it straightforward for testers to understand the test flow.
  3. Parameter Passing: You can pass parameters to the called test case, allowing for dynamic behavior based on different inputs.
  4. Logging: Each test case execution is logged separately, providing detailed insights into the execution flow.

Limitations of Using callTestCase:

  1. Performance: Calling multiple test cases can lead to slower execution times due to the overhead of managing separate test case logs and execution contexts.
  2. Verbosity: The execution logs can become verbose, which may complicate debugging and make it harder to identify issues.

What are Custom Keywords?

Custom keywords are reusable functions that you can define in Katalon Studio. They are typically created to encapsulate common actions that can be reused across multiple test cases. Custom keywords are defined in the Keywords folder and can be annotated with @Keyword to make them available in both manual and script modes.

// Custom Keyword Definition

import com.kms.katalon.core.annotation.Keyword

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

class LoginKeywords {

    @Keyword

    def login(String username, String password) {

        WebUI.setText(findTestObject('Page_Login/input_Username'), username)

        WebUI.setText(findTestObject('Page_Login/input_Password'), password)

        WebUI.click(findTestObject('Page_Login/button_Login'))

    }

}

// Using the Custom Keyword in a Test Case

import myKeywords.LoginKeywords as Login

Login.login('testUser', 'testPass')

Advantages of Using Custom Keywords:

  1. Performance: Custom keywords run faster than calling test cases because they do not generate extensive execution logs for each step. This can lead to improved performance, especially for frequently used actions.
  2. Simplicity: Custom keywords can simplify complex test logic by encapsulating it in a single function, making your test cases cleaner and easier to read.
  3. Flexibility: Keywords can be designed to accept parameters and return values, allowing for dynamic and reusable code.
  4. Less Verbose Logging: Since custom keywords do not log every step like test cases do, they help keep logs concise and focused on critical information.

Limitations of Using Custom Keywords:

  1. Limited Context: Custom keywords do not have their own execution context like test cases do. This means they cannot manage their own setup and teardown processes.
  2. Manual Mode Limitations: If you want to use custom keywords in manual mode, they must be annotated with @Keyword, which may not be necessary if you primarily use script mode.

When to Use Each Approach

Use callTestCase When:

  • You need to execute a complete test case that includes setup and teardown logic.
  • You want to maintain detailed logs for each test case execution to facilitate debugging.
  • You are working on a modular test design where each test case represents a distinct functional area.

Use Custom Keywords When:

  • You have repetitive code that needs to be reused across multiple test cases without the overhead of separate execution logs.
  • Performance is a concern, and you want to minimize execution time.
  • You need to encapsulate complex logic that can be reused in a straightforward manner.

Conclusion

The choice between callTestCase and custom keywords largely depends on your specific testing needs and the structure of your test suite. If you prioritize modularity and detailed logging, callTestCase is the way to go. However, if you are focused on performance and code reuse without the verbosity of test case logs, custom keywords are the better option.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Sanket Dudhe

Sanket Dudhe is a Technical Consultant at Perficient. He has an experience of 4+ years as SDET. He loves technology and hence is curious to learn about new emerging technologies #lovefortechnology.

More from this Author

Categories
Follow Us