How to handle failure of Custom Keywords

Suppose we have a custom Keyword and we are using it and we want to continue on Failure, How we can proceed??
In Builtin keyword we have options for FailureHandling.

Hello, your description is too general. What does you keyword do? Basically, there are few approaches how to “fail” custom keywords.

a. Return boolean value and handle it in your test case (or at any place where you call the method)

public static boolean isNumberGreaterThanFive(int number) {
	if(number > 5) {
		return true
	} else {
		return false
	}
}

b. Use built-in keyword utils and throw only a warning, not a failure

public static void isNumberGreaterThanFive(int number) {
	if(number <= 5) {
		KeywordUtil.markWarning("The number is not greater than 5. Your input: " + number)
	}
}

c. throw an exception and catch it in your test case

public static void provideNumberGreaterThanFive(int number) {
	if(number <= 5) {
		throw new IllegalArgumentException("A number " + number + " is not greater than 5")
	}
}

An in your test case:

try {
	provideNumberGreaterThanFive(int number)
} catch (IllegalArgumentException ex) {
	KeywordUtil.logInfo("Exception caught: " + ex)
	// do whatever you want in case of failure
}

Just choose the one which suits you the best.

Disclaimer: May contain syntax errors.

4 Likes

Thanks @Marek_Melocik :slight_smile: