
26 February 2025 Leave a comment Katalon Issues
When working with Katalon Studio, you might find it necessary to capture screenshots of each Test Case and save them with an identifiable name. However, a common challenge arises when the methods used only return the Test Suite name rather than the specific Test Case name. This guide provides a straightforward solution to help you overcome this issue.
Understanding the Challenge
The initial approach often involves using:
testName = RunConfiguration.getExecutionSourceName().toString()
However, this method only retrieves the Test Suite name, not the individual Test Case name. To correctly reference the Test Case name, adjustments in the approach are necessary, especially when the screenshot code is located in the “TearDownTestCase” method within Test Suites.
Solution: Using Test Listeners
The most effective solution involves creating a Test Listener to capture the Test Case name. Here’s a step-by-step guide:
Step 1: Create a Test Listener
Start by creating a Test Listener and adding the following code in the @BeforeTestCase
method:
class TestCaseName {
@BeforeTestCase
def sampleBeforeTestCase(TestCaseContext testCaseContext) {
String testCaseId = testCaseContext.getTestCaseId()
}
}
This setup will provide you with the path of the Test Case, typically in the format:
../Katalon Studio/Test Cases/Test Case Name
Step 2: Extract the Test Case Name
To isolate the Test Case name from the path, use the .substring()
method as follows:
class TestCaseName {
@BeforeTestCase
def sampleBeforeTestCase(TestCaseContext testCaseContext) {
String testCaseId = testCaseContext.getTestCaseId()
GlobalVariable.testCaseName = testCaseId.substring((testCaseId.lastIndexOf("/").toInteger()) + 1)
}
}
This approach effectively extracts the Test Case name, allowing for straightforward integration into your screenshot naming convention.
Alternative Methods
Another approach involves directly using the RunConfiguration.getExecutionSource()
method to derive the Test Case name:
RunConfiguration.getExecutionSource().toString().substring(RunConfiguration.getExecutionSource().toString().lastIndexOf("\\")+1)
This method retrieves the full path and trims it to isolate the Test Case name using Groovy’s .substring()
method for string manipulation.
Enhancing Test Automation with Repeato
While Katalon Studio provides robust testing capabilities, integrating tools like Repeato can further enhance your testing efficiency. Repeato, a no-code test automation tool, offers a quick and flexible approach to creating, running, and maintaining automated tests for iOS, Android, and web applications. With its support for data-driven testing and seamless integration of command line scripts or JavaScript, Repeato ensures that your testing processes remain agile and adaptable. Moreover, its text and JSON-based data storage simplifies version control, making it a practical alternative to other tools like Katalon that may have more rigid scripting requirements.
For more insights on how Repeato can transform your testing workflow, explore our documentation and blog.
Like this article? there’s more where that came from!
- Resolving the “xcrun: error: invalid active developer path” Error on macOS
- Adding Existing Frameworks in Xcode 4: A Comprehensive Guide
- Disabling ARC for a Single File in Xcode: A Step-by-Step Guide
- Resolving the Xcode-Select Active Developer Directory Error
- Resolving the “Multiple Commands Produce” Error in Xcode 10