# Methods in Test Case

**URL:** <https://forum.katalon.com/t/methods-in-test-case/17392>\
**Category:** Web Testing\
**Tags:** web-testing, katalon-studio\
**Created:** [January 9, 2019, 7:12am UTC](https://forum.katalon.com/t/methods-in-test-case/17392 "2019-01-09T07:12:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dsoni](https://avatars.discourse-cdn.com/v4/letter/d/a4c791/32.png) [@dsoni](https://forum.katalon.com/u/dsoni)\
**Post date:** [January 9, 2019, 7:12am UTC](https://forum.katalon.com/t/methods-in-test-case/17392/1 "2019-01-09T07:12:44Z")

</div>

Hii I am new to Katalon and would love if someone could help me out on the below issue,

1. Can I create a test case with multiple methods and invoke these methods as per need in other test cases? The callTestCase method calls the entire test case and not particular methods. I have explored custom keywords but was curious to explore this concept.
2. I tried creating a groovy class with methods only but could not find a way to invoke these methods in test case. It throws an error that method signature is not valid.

---

<div class="post-metadata">

**Author:** ![Marek\_Melocik](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/marek_melocik/32/371_2.png) [@Marek\_Melocik](https://forum.katalon.com/u/Marek_Melocik)\
**Post date:** [January 9, 2019, 7:17am UTC](https://forum.katalon.com/t/methods-in-test-case/17392/2 "2019-01-09T07:17:13Z")

</div>

Hello,

custom keyword is exactly what you need. It behaves as a regular Java class, so you can create methods there, then import the class in your test case and call the method you want.

Very easy example:

Custom keyword:

```
public class KeywordTest {
	public static void sayHello() {
		println "Hello!"
	}
}

```

Test:

```
import com.mypackage.KeywordTest

KeywordTest.sayHello()
```

---

<div class="post-metadata">

**Author:** ![dsoni](https://avatars.discourse-cdn.com/v4/letter/d/a4c791/32.png) [@dsoni](https://forum.katalon.com/u/dsoni)\
**Post date:** [January 9, 2019, 7:30am UTC](https://forum.katalon.com/t/methods-in-test-case/17392/3 "2019-01-09T07:30:23Z")

</div>

Thanks for the response.

But then what is the purpose of creating methods in test case if we can’t reuse them and what is the purpose of creating groovy classes in scripts folder?

---

<div class="post-metadata">

**Author:** ![Marek\_Melocik](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/marek_melocik/32/371_2.png) [@Marek\_Melocik](https://forum.katalon.com/u/Marek_Melocik)\
**Post date:** [January 9, 2019, 7:33am UTC](https://forum.katalon.com/t/methods-in-test-case/17392/4 "2019-01-09T07:33:09Z")

</div>

There is maybe only one such a scenario. If you repeat some test case specific action(s) multiple times, then you can define a method and call it instead of repeating code.

But as soon as you use your method in 2 or more tests, custom keyword approach wins.

---

<div class="post-metadata">

**Author:** ![Ibus](https://avatars.discourse-cdn.com/v4/letter/i/e9a140/32.png) [@Ibus](https://forum.katalon.com/u/Ibus)\
**Post date:** [January 10, 2019, 9:03am UTC](https://forum.katalon.com/t/methods-in-test-case/17392/5 "2019-01-10T09:03:55Z")

</div>

> creating groovy classes in scripts folder?

**Scripts** folder does not contain groovy classes, but groovy **scripts**.

Therefore, as mentioned already, to create re-usable methods **across** testcases, you have to use Keywords (which are groovy/java **classes** )  
To create reusable code **inside** testcase, one can use local methods

The **Test Cases** folder contains just some xml’s ( the **.tc** files) with some metadata. At the runtime, the actual scripts are located (not sure how, by parent folder name I suppose, because I cannot see any other match between the metadata and the script name) and compiled in classes.

some ref about script vs classes here: [The Apache Groovy programming language - Program structure](http://groovy-lang.org/structure.html#_scripts_versus_classes)
