When KeywordUtil.markPassed() is used in a custom keyword, then the message is not displayed while executing the test case

Basically I have created a Custom Keyword

So while using this in the test case I expect to see the “Expected : expected + and Actual : + actual + are exact match“ in the logs but I’m not seeing them.

The reason I’m doing this is the screenshot is not captured when I use the WebUI.verifyEqual(actual, expected) keyword

Can someone help me here.

If I’m I doing something wrong here, can I get some other implementation.

1 Like

Hi there, and thanks for posting in the Katalon community! :hugs:

To help you faster, please review our guide on Custom Keyword here: Introduction to custom keywords in Katalon Studio | Katalon Docs. Double-checking the steps and configurations might resolve the issue.

If the doc doesn’t help, feel free to provide more details, and a community member will assist you soon. Thanks for being a part of our community!

Best,
Elly Tran

Solution: Recommended Implementation

Here are two approaches:

Approach 1: Proper Custom Keyword (Recommended)

Separate your keyword logic from assertions. Create a custom keyword that performs the comparison and returns the result:

import com.kms.katalon.core.keyword.BuiltinKeywords as BuiltinKeywords
import com.kms.katalon.core.keyword.KeywordUtil

@Keyword
def verifyEqualsWithLogging(String expected, String actual) {
    KeywordUtil.logInfo("Expected: " + expected)
    KeywordUtil.logInfo("Actual: " + actual)
    
    if (expected.equals(actual)) {
        KeywordUtil.logInfo("Expected and Actual values are exact match")
        KeywordUtil.markPassed("Values match: " + expected)
        return true
    } else {
        KeywordUtil.logInfo("Expected and Actual values do NOT match")
        KeywordUtil.markFailed("Expected: " + expected + " | Actual: " + actual)
        WebUI.takeScreenshot()
        return false
    }
}

Usage in Test Case:

String expected = "expectedValue"
String actual = "actualValue"

if (CustomKeywords.'com.example.CustomVerification.verifyEqualsWithLogging'(expected, actual)) {
    BuiltinKeywords.comment("Verification passed")
} else {
    BuiltinKeywords.comment("Verification failed")
}

Approach 2: Exception-Based Verification with Screenshot

If you want to keep assertion logic in the keyword, properly handle exceptions:

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

@Keyword
def verifyEqualsWithScreenshot(String expected, String actual) {
    try {
        KeywordUtil.logInfo("Verifying - Expected: " + expected + " | Actual: " + actual)
        WebUI.verifyEqual(actual, expected)
        KeywordUtil.logInfo("Verification passed: Expected and Actual are exact match")
    } 
    catch (Exception e) {
        KeywordUtil.logInfo("Verification failed: Expected: " + expected + " | Actual: " + actual)
        WebUI.takeScreenshot()  // Capture screenshot on failure
        KeywordUtil.markFailed("Expected: " + expected + " | Actual: " + actual)
    }
}

Why No Screenshot with verifyEqual

Built-in WebUI.verifyEqual only screenshots on failure by default; markPassed alone skips it too. Custom keywords need explicit WebUI.takeScreenshot() for images on pass, visible in Log Viewer > Test Case Details > Screenshots.

I tried to reproduce your case on my side.

I did not see the message Expected : x and Actual : x are exact match in the Log Viewer tab.

But I saw the message in the Console tab.

This proves that the LogViewer does not show the output from KeywordUtil.markFailed(msg) while the Console tab shows the message.

@akshay_sartabe

Do you want to see the message displayed in the LogViewer?

If so, you should check how the Log Viewer GUI component deals with the output from the KeywordUtil class. The class implements several methods. You should check each of them.

  • logInfo
  • markError
  • markErrorAndStop
  • markFailed
  • markFailedAndStop
  • markPassed
  • markWarning

The Log Viewer seems to have its own way (which may be inconsistent) how to deal with the custom messages. Just examine it and use it appropriately.

1 Like

hi @akshay_sartabe

if you want to print it on the Log Viewer section, you need to add this KeywordUtil.logInfo

for example:

KeywordUtil.logInfo("Expected: ${expected} and Actual: ${actual} are exact match")
KeywordUtil.markPassed("Verification passed")

this one is for the failed one:

KeywordUtil.logInfo("Expected: ${expected} and Actual: ${actual} does not match")
KeywordUtil.markFailed("Verification failed")

@akshay_sartabe

Please check “Project Settings>Test Design>Test Case”, Default Failure Handling for Test Step.

If you specify “OPTIONAL” here as this:

Then

WebUI.verifyEqual(actual, expected)

will throw no StepFailedException even when the actual and the expected differ.

1 Like