Possibly you do not have any idea what KeywordUtil class does. That should be the first problem you need to tuckle. The best way for understanding the class is to read the source code. I can tell you how to find the source code of the class.
You can find the source code of com.kms.katalon.core.util.KeywordUtil in the jar file: <Your Katalon_Studio installation folder>\configuration\resources\source\com.kms.katalon.core\com.kms.katalon.core-sources.jar
I would quote the source of v10.3.1 as follows:
package com.kms.katalon.core.util;
import com.kms.katalon.core.exception.StepErrorException;
import com.kms.katalon.core.exception.StepFailedException;
import com.kms.katalon.core.logging.ErrorCollector;
import com.kms.katalon.core.logging.KeywordLogger;
public class KeywordUtil {
private static final KeywordLogger logger = KeywordLogger.getInstance(KeywordUtil.class);
/**
* Mark a keyword to be failed and continue execution
*
* @param message fail message
*/
public static void markFailed(String message) {
logger.logFailed(message);
ErrorCollector.getCollector().addError(new StepFailedException(message));
ErrorCollector.getCollector().setIsNextStepSkipped(true);
}
/**
* Mark a keyword to be failed and stop execution
*
* @param message fail message
*/
public static void markFailedAndStop(String message) {
ErrorCollector.getCollector().setStopLauncher(true);
throw new StepFailedException(message);
}
/**
* Log message as info
*
* @param message log info message
*/
public static void logInfo(String message) {
logger.logInfo(message);
}
/**
* Mark a keyword to be warning
*
* @param message warning message
*/
public static void markWarning(String message) {
logger.logWarning(message);
}
/**
* Mark a keyword to be passed
*
* @param message passed message
*/
public static void markPassed(String message) {
logger.logPassed(message);
ErrorCollector.getCollector().setKeywordPassed(true);
}
/**
* Mark a keyword to be error
*
* @param message error message
*/
public static void markError(String message) {
ErrorCollector.getCollector().addError(new StepErrorException(message));
ErrorCollector.getCollector().setIsNextStepSkipped(true);
}
/**
* Mark a keyword to be error and stop execution
*
* @param message error message
*/
public static void markErrorAndStop(String message) {
ErrorCollector.getCollector().setStopLauncher(true);
throw new StepErrorException(message);
}
}
Yeah, beacause KeywordUtil doesn’t take screenshoot if it fail or error. So i write a function to do it both in one step in test case.
But when running, 2 captureErrorAndStop and captureFailAndContinue will run to the KeywordUtil that send log to report. 2 functions captureErrorAndContine and captureFailAndStop only run and giving log at the takeScreenshot.
So I would guess … It seems that you want KeywordUtil.markFailedAndStop to display the message “Test fail and stop” in the Log Viewer tab, am I right?
I tried to reproduce what you saw. Yes, you are right. I saw the KeywordUtil.markFailedAndStop displayed no message in the Log Viewer tab. You don’t like it, do you?
In a preceding post in this topic, I showed you the source of com.kms.katalon.core.util.KeywordUtil class. You can find the implementation of the markFailedAndStop method:
public static void markFailedAndStop(String message) {
ErrorCollector.getCollector().setStopLauncher(true);
throw new StepFailedException(message);
}
As far as I see, the markFailedAndStop works as coded; it will display no message in the Log Viewer tab, it will display the message Line 4 in the Stacktrace in the Console tab.
By the way, you can also see the source of markFailed method:
The markFailedAndStop and markFailed — these 2 methods have the similar names but are coded quite differently. I have no idea what is the design intention of KeywordUtil class. I don’t know the reason why these methods are implemented as such. Perhaps Katalon has some good reasons.
The KeywordUtil class is given to you. Why not you embrace the given KeywordUtil class as is? or should you invent your own alternative? It is up to you.