# Logging the steps of a custom keyword method

**URL:** <https://forum.katalon.com/t/logging-the-steps-of-a-custom-keyword-method/60005>\
**Category:** Web Testing\
**Tags:** katalon-studio\
**Created:** [November 12, 2021, 9:58pm UTC](https://forum.katalon.com/t/logging-the-steps-of-a-custom-keyword-method/60005 "2021-11-12T21:58:10Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![mwarren04011990](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/mwarren04011990/32/26024_2.png) [@mwarren04011990](https://forum.katalon.com/u/mwarren04011990)\
**Post date:** [November 12, 2021, 9:58pm UTC](https://forum.katalon.com/t/logging-the-steps-of-a-custom-keyword-method/60005/1 "2021-11-12T21:58:10Z")

</div>

This question originally posted [on StackOverflow](https://stackoverflow.com/questions/69949296/logging-the-steps-of-a-custom-keyword-method-in-katalon-studio).

# Context

We run across the same widgets on multiple pages, and oftentimes cover multiple scenarios for a given page on the site under test. This and other concerns has motivated me to move the page action concerns to `GeneralWebUIUtils` and page objects, respectively, in the Keywords.

# Example

For example, we have this class `GeneralWebUIUtils`, defined to be:

```auto
package com.xxx.utils

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

public final class GeneralWebUIUtils {
	//...

	public static void HandleAutoComplete(TestObject textField, String input, TestObject loader, TestObject firstDropdownOption) {
		WebUI.click(textField)

		WebUI.setText(textField, input)

		WebUI.waitForElementVisible(loader, 3)

		WebUI.waitForElementNotVisible(loader, 3)

		WebUI.waitForElementNotPresent(firstDropdownOption, 3)

		WebUI.waitForElementVisible(firstDropdownOption, 3)

		WebUI.click(firstDropdownOption)
	}
}

```

In one test case in particular, I have to handle autocomplete, for which I’ll use `GeneralWebUIUtils.HandleAutoComplete` from this class.

# OK, now what’s the issue?

I am now facing performance issue from that method, and before that, a stale element exception. Typical test case issues, just moved to a package. Whenever I check out the log viewer, it doesn’t show the steps of that method like it would if that method existed on the test case itself:

This is problematic because it means you can’t check out the logs to find out what is going on, let alone what is creating the bottleneck. You are therefore forced to use the debug mode, which is prone to problems of its own (think forced waiting, and b/c of that, flaky debug sessions).

**How can we tell Katalon to log the different `WebUI` keywords like it does in the local-to-test-case version of this method?**

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [November 13, 2021, 1:02am UTC](https://forum.katalon.com/t/logging-the-steps-of-a-custom-keyword-method/60005/2 "2021-11-13T01:02:35Z")

</div>

> [@mwarren04011990](#):
>
> Whenever I check out the log viewer, it doesn’t show the steps of that method like it would if that method existed on the test case itself:

Do you want to see in the LogViewer the step execution of the lines inside the `HandleAutoComplete`?

Then, you should not make it a Custom Keyword; because, by design, a Custom Keyword is out of the scope of LogViewer.

You should make `HandleAutoComplete` a Test Case. And test case calls it using the following:

[https://docs.katalon.com/katalon-studio/docs/common-call-test-case.html](https://docs.katalon.com/katalon-studio/docs/common-call-test-case.html)

---

<div class="post-metadata">

**Author:** ![mwarren04011990](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/mwarren04011990/32/26024_2.png) [@mwarren04011990](https://forum.katalon.com/u/mwarren04011990)\
**Post date:** [November 13, 2021, 1:11am UTC](https://forum.katalon.com/t/logging-the-steps-of-a-custom-keyword-method/60005/3 "2021-11-13T01:11:05Z")

</div>

Yea that’s a code smell.

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [November 13, 2021, 1:14am UTC](https://forum.katalon.com/t/logging-the-steps-of-a-custom-keyword-method/60005/4 "2021-11-13T01:14:09Z")

</div>

> [@mwarren04011990](#):
>
> How can we tell Katalon to log the different `WebUI` keywords like it does in the local-to-test-case version of this method?

No, it is not possible.

Katalon Studio assumes that all keywords are already well-tested somewhere outside KS. Therefore Katalon’s LogViewer is not designed to monitor the step execution of keywords.

> [@mwarren04011990](#):
>
> and before that, a stale element exception.

I am afraid, you code is still to be debugged, not ready to form a Keyword.

In other words, if you want to develop your own Custom Keywords, you have to make sure your Custom Keywords are somehow well-tested and bug-free. But I am afraid that Katalon Studio does not help unit-testing your Custom Keywords at all. There is no documentation titled “How to unit-test your Custom Keywords in Katalon Studio” in the Katalon’s official docs. This proves, I think, that Katalon Team is not concerned about the quality assurance of user’s custom keywords.

> I guess, the Katalon Team develops the built-in Keywords outside Katalon Studio product (possibly in Eclipse), and does enough unit-tests there. So they are contented. They do not imagine how much users would struggle to debug their own Custom Keywords. ==\> @Jass any comment?

So, @mwarren04011990, I would advise you, it is a difficult task to develop well-tested Custom Keywords. You had better start “modularizing test cases” with `callTestCase()`, rather than jumping into Custom Keywords.

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [November 13, 2021, 2:30am UTC](https://forum.katalon.com/t/logging-the-steps-of-a-custom-keyword-method/60005/5 "2021-11-13T02:30:03Z")

</div>

With `callTestCase()` you would see in the Log Viewer display every step execution log of your common routines as a Test Case.

Please be warned, however, executing common routines as Test Case will be slower than executing common routines as Keyword, because step execution logging slows down Test Cases(Groovy scripts) significantly. Keywords (Groovy class) runs far faster, as no step execution log is taken. In future, when you get worried about the speed, you may consider migrating the common routine from a Test Case to a Keyword.

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [November 13, 2021, 2:58am UTC](https://forum.katalon.com/t/logging-the-steps-of-a-custom-keyword-method/60005/6 "2021-11-13T02:58:55Z")

</div>

There could be 2 types of modules in Katalon project:

- one type is dependent on Katalon Studio’s API like `WebUI.openBrowser()`,
- another type is independent on Katalon Studio’s API.

When I write my test codes I always try to distinguish these 2 types.

I would try to implement the first type of module (Katalon API dependent) as Test Cases to be called by `WebUI.callTestCase()`, not as Keywords. I can not develop this type of module outside Katalon Studio, as the Katalon API is not distributed as importable jar files outside the Katalon Studio product.

I would implement the second type of modules(Katalon-independent one) as Groovy/Java classes OUTSIDE Katalon Studio. I prefer IntelliJ IDEA, as IDEA is far easier than Katalon Studio to develop Groovy/Java classes. I will code, test, and build a jar file which I will import into the `Drivers` folder of a Katalon project. An example is [here](http://forum.katalon.com/t/visual-inspection-in-katalon-studio-reborn/57440).

* * *

However, sometimes, I need to develop 3rd type of module in a Katalon Studio project. That is, a Custom Keyword that depends on Katalon Studio’s API. In order to perform unit-tests for the 3rd type Custom Keywords inside Katalon Studio, I invented a way [using JUnit in KS](http://forum.katalon.com/t/running-junit4-in-katalon-studio/12270).

---

<div class="post-metadata">

**Author:** ![mwarren04011990](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/mwarren04011990/32/26024_2.png) [@mwarren04011990](https://forum.katalon.com/u/mwarren04011990)\
**Post date:** [November 14, 2021, 2:41am UTC](https://forum.katalon.com/t/logging-the-steps-of-a-custom-keyword-method/60005/7 "2021-11-14T02:41:15Z")

</div>

Thank you for your detailed response. I’m sorry, but I cannot accept this “solution” of turning it into test cases.

Making a _general Web UI custom utils class_, whose job includes handling an auto-complete widget, and may have custom methods that work properly and solve other generic concerns (e.g. handling a date widget), _its own set of test cases_, is a bullshit design. They are general actions to be performed on the pages, NOT assertions.

This is especially unacceptable given that I am working on page objects. The whole point of those is to separate general page action details from the tests themselves, and thus from the verifications.

The bugs I was facing, are the bugs that pop up in general with developing any test case. Stuff like a step executing on a test object before it’s ready in the DOM, causing a StaleElementException, as well as the performance issue, which ended up being waiting for something to de-spawn, at the wrong time.

I’m sorry, maybe I don’t know as much about unit-testing as I thought I did, but how is unit-testing going to find and fix these sort of test-case-and-AUT race conditions?

---

<div class="post-metadata">

**Author:** ![mwarren04011990](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/mwarren04011990/32/26024_2.png) [@mwarren04011990](https://forum.katalon.com/u/mwarren04011990)\
**Post date:** [November 14, 2021, 3:11am UTC](https://forum.katalon.com/t/logging-the-steps-of-a-custom-keyword-method/60005/8 "2021-11-14T03:11:21Z")

</div>

**UPDATE:** I see that I can use `KeywordUtils.logInfo()` to log the info, in a custom keyword. This can help me find the bottleneck.

I found it and fixed it btw.

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [November 15, 2021, 2:51am UTC](https://forum.katalon.com/t/logging-the-steps-of-a-custom-keyword-method/60005/9 "2021-11-15T02:51:56Z")

</div>

Closed on November 15, 2021, 2:51am UTC


