# Is it possible to call one custom keyword function from another Custom keywords?

**URL:** <https://forum.katalon.com/t/is-it-possible-to-call-one-custom-keyword-function-from-another-custom-keywords/11242>\
**Category:** Web Testing\
**Tags:** katalon-studio\
**Created:** [May 30, 2018, 9:31am UTC](https://forum.katalon.com/t/is-it-possible-to-call-one-custom-keyword-function-from-another-custom-keywords/11242 "2018-05-30T09:31:50Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Divya4](https://avatars.discourse-cdn.com/v4/letter/d/7bcc69/32.png) [@Divya4](https://forum.katalon.com/u/Divya4)\
**Post date:** [May 30, 2018, 9:31am UTC](https://forum.katalon.com/t/is-it-possible-to-call-one-custom-keyword-function-from-another-custom-keywords/11242/1 "2018-05-30T09:31:50Z")

</div>

Hi ,

I am trying to call method from one custom keywords to another Custom keywords functions

But i am getting below error,

05-30-2018 02:59:02 PM - [START] - Start action : mandatoryfield\_Validation.Mandatoryfieldvalidation.textfieldvalidation

05-30-2018 02:59:02 PM - [INFO] - Finding Test Object with id ‘Object Repository/HelpDeskModule/Master/Team/Page\_eFACiLiTY/input\_Txt\_Code’

05-30-2018 02:59:02 PM - [ERROR] - No such property: CustomKeywords for class: mandatoryfield\_Validation.Mandatoryfieldvalidation

05-30-2018 02:59:02 PM - [END] - End action : mandatoryfield\_Validation.Mandatoryfieldvalidation.textfieldvalidation

05-30-2018 02:59:02 PM - [ERROR] - Test Cases/HelpDeskModule/Master/Team\_/Team FAILED because (of) Variable ‘CustomKeywords’ is not defined for test case.

Here is my snippet:

public class Mandatoryfieldvalidation {

//

private static Connection connection = null;

private static String columntype;

private static int num;

private static int datatypevalue

def driver = DF.getWebDriver()

KeywordLogger logger = new KeywordLogger()

JavascriptExecutor js = ((driver) as JavascriptExecutor)

//Method for validating textfield

@Keyword

def void textfieldvalidation()

{

CustomKeywords.‘alerthandling.verifyalertpresent.verifyalert’()

}

---

<div class="post-metadata">

**Author:** ![Shadhi\_Morrow](https://avatars.discourse-cdn.com/v4/letter/s/a87d85/32.png) [@Shadhi\_Morrow](https://forum.katalon.com/u/Shadhi_Morrow)\
**Post date:** [June 4, 2018, 10:04pm UTC](https://forum.katalon.com/t/is-it-possible-to-call-one-custom-keyword-function-from-another-custom-keywords/11242/2 "2018-06-04T22:04:25Z")

</div>

Hello @7481-Divya ,

The first issue I noticed with your code snippet is the single-quotes after CustomKeywords. The documentation [here](https://docs.katalon.com/display/KD/Define+custom+keywords#Definecustomkeywords-CustomkeywordsinScriptingview) shows they are not needed and would probably cause your keyword reference to be treated as a string. CustomKeywords is not a function, so it would not take parameters.

Second, you might need to reference the “alerthandling” package within the new package. Check the import section of a Test Case that uses one of your custom keywords to see if it has a line for CustomKeywords.

Another idea would be to combine the two packages. That should guaranty that you can reference “verifyalertpresent.verifyalert” within Mandatoryfieldvalidation…

I’m no expert in Katalon Studio, but since you had no other replies yet, I though I would offer some ideas. Best of luck!

---

<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:** [June 5, 2018, 8:45am UTC](https://forum.katalon.com/t/is-it-possible-to-call-one-custom-keyword-function-from-another-custom-keywords/11242/3 "2018-06-05T08:45:10Z")

</div>

Divya,

Try to call directly \_alerthandling.verifyalertpresent.verifyalert() \_method. CustomKeywords is not a class, it is just a kind of Groovy wrapper for custom keywords.

---

<div class="post-metadata">

**Author:** ![Chris\_Trevarthen](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/chris_trevarthen/32/358_2.png) [@Chris\_Trevarthen](https://forum.katalon.com/u/Chris_Trevarthen)\
**Post date:** [June 18, 2018, 6:43pm UTC](https://forum.katalon.com/t/is-it-possible-to-call-one-custom-keyword-function-from-another-custom-keywords/11242/4 "2018-06-18T18:43:04Z")

</div>

As Marek mentions, CustomKeywords are not really a class - they are a set of auto-generated functions (from your custom classes) that live in a CustomKeywords.groovy file. That file is loaded by Katalon test files at run time.

It appears that you only need to access CustomKeywords using the quotes when using them in **test files**.

From other CustomKeyword files, you can access the classes/functions **directly** , just like you would if you were programming any other groovy library or application.

---

<div class="post-metadata">

**Author:** ![benjamin\_Hougland](https://avatars.discourse-cdn.com/v4/letter/b/76d3ee/32.png) [@benjamin\_Hougland](https://forum.katalon.com/u/benjamin_Hougland)\
**Post date:** [July 12, 2018, 7:51pm UTC](https://forum.katalon.com/t/is-it-possible-to-call-one-custom-keyword-function-from-another-custom-keywords/11242/5 "2018-07-12T19:51:21Z")

</div>

I was hoping i could get more clarification on this issue. I read the following thread, and the documentation here; [https://docs.katalon.com/display/KD/Import+Custom+Keywords+classes+recursively](https://docs.katalon.com/display/KD/Import+Custom+Keywords+classes+recursively)

However, I am getting an error when i try this example:

I have a package ‘utilities’ that has a keyword file ‘core’, with the following keyword definition:

_package utilities_

_public class core {_

\_ @Keyword //also doesn’t work without the keyword\_  
\_ static def takeScreenShot(String pref = ‘YES’) {\_  
\_ if (pref.toUpperCase() == ‘YES’){\_  
\_ WebUI.takeScreenshot()\_  
\_ }\_  
\_ }\_  
_}_

However, it doesn’t work when I try to use the keyword in another keyword file, information below:

_package mainS3_

_public class portal {_

_@Keyword_

_def navigateBookmarks(List menu\_path, takeScreenShot = YES)_

_. code_

_. code_

_. code, etc_

_utilities.core.takeScreenShot(takeScreenShot)_

_}_

I receive the following error on a test case using the keyword

**Test Cases/playground/RQC\_navigate FAILED because (of) Variable ‘utilities’ is not defined for test case.**

Any help? Sorry, i am new to the Java world. I have had a lot of success using keywords, but this is my first time trying to call one from a different package.

Thanks!

---

<div class="post-metadata">

**Author:** ![Andrej\_Podhajsky](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/andrej_podhajsky/32/1055_2.png) [@Andrej\_Podhajsky](https://forum.katalon.com/u/Andrej_Podhajsky)\
**Post date:** [July 13, 2018, 6:07am UTC](https://forum.katalon.com/t/is-it-possible-to-call-one-custom-keyword-function-from-another-custom-keywords/11242/6 "2018-07-13T06:07:50Z")

</div>

hello,  
i find solution for calling Custom keywords from each other in your case:

```auto
(new alerthandling.verifyalertpresent()).verifyalert()

```

@benjamin

```auto
(new utilities.core()).takeScreenShot(takeScreenShot)

```

will do the magic

---

<div class="post-metadata">

**Author:** ![benjamin\_Hougland](https://avatars.discourse-cdn.com/v4/letter/b/76d3ee/32.png) [@benjamin\_Hougland](https://forum.katalon.com/u/benjamin_Hougland)\
**Post date:** [July 13, 2018, 1:09pm UTC](https://forum.katalon.com/t/is-it-possible-to-call-one-custom-keyword-function-from-another-custom-keywords/11242/7 "2018-07-13T13:09:56Z")

</div>

@Andrej Podhajský

Your solution worked perfectly, I can’t thank you enough!!! This should be placed into the official documentation.

---

<div class="post-metadata">

**Author:** ![Andrej\_Podhajsky](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/andrej_podhajsky/32/1055_2.png) [@Andrej\_Podhajsky](https://forum.katalon.com/u/Andrej_Podhajsky)\
**Post date:** [July 13, 2018, 1:56pm UTC](https://forum.katalon.com/t/is-it-possible-to-call-one-custom-keyword-function-from-another-custom-keywords/11242/8 "2018-07-13T13:56:06Z")

</div>

you are welcome

---

<div class="post-metadata">

**Author:** ![Yooluti\_Phalyngki](https://avatars.discourse-cdn.com/v4/letter/y/22d042/32.png) [@Yooluti\_Phalyngki](https://forum.katalon.com/u/Yooluti_Phalyngki)\
**Post date:** [September 20, 2018, 8:02am UTC](https://forum.katalon.com/t/is-it-possible-to-call-one-custom-keyword-function-from-another-custom-keywords/11242/9 "2018-09-20T08:02:05Z")

</div>

> Andrej Podhajský said:
> 
> hello,  
> i find solution for calling Custom keywords from each other in your case:
> 
> ```auto
> (new alerthandling.verifyalertpresent()).verifyalert()
> 
> ```
> 
> @benjamin
> 
> ```auto
> (new utilities.core()).takeScreenShot(takeScreenShot)
> 
> ```
> 
> will do the magic

It works like magic, Thanks [@"Andrej](http://forum.katalon.com/profile/2584/%22Andrej "Link: http://forum.katalon.com/profile/2584/%22Andrej") Podhajský"

---

<div class="post-metadata">

**Author:** ![Rustam\_Ismayilov](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/rustam_ismayilov/32/3153_2.png) [@Rustam\_Ismayilov](https://forum.katalon.com/u/Rustam_Ismayilov)\
**Post date:** [September 21, 2018, 4:07pm UTC](https://forum.katalon.com/t/is-it-possible-to-call-one-custom-keyword-function-from-another-custom-keywords/11242/10 "2018-09-21T16:07:55Z")

</div>

Or you can use

```auto
UserInfoGeneraror ug = new UserInfoGeneraror();ug.name_gen(findTestObject('OKAL/BO/AddNewSender_Page/id_DateOfBirth'))

```

---

<div class="post-metadata">

**Author:** ![Andrej\_Podhajsky](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/andrej_podhajsky/32/1055_2.png) [@Andrej\_Podhajsky](https://forum.katalon.com/u/Andrej_Podhajsky)\
**Post date:** [September 21, 2018, 6:30pm UTC](https://forum.katalon.com/t/is-it-possible-to-call-one-custom-keyword-function-from-another-custom-keywords/11242/11 "2018-09-21T18:30:17Z")

</div>

> [Rustam Ismayilov](https://forum.katalon.com/profile/8086/Rustam%20Ismayilov) said:
> 
> Or you can use

```auto
UserInfoGeneraror ug = new UserInfoGeneraror();
ug.name_gen(findTestObject('OKAL/BO/AddNewSender_Page/id_DateOfBirth'))

```

> 

errr… what?

---

<div class="post-metadata">

**Author:** ![Marianna\_Takacova](https://avatars.discourse-cdn.com/v4/letter/m/e19adc/32.png) [@Marianna\_Takacova](https://forum.katalon.com/u/Marianna_Takacova)\
**Post date:** [November 23, 2018, 8:57am UTC](https://forum.katalon.com/t/is-it-possible-to-call-one-custom-keyword-function-from-another-custom-keywords/11242/12 "2018-11-23T08:57:31Z")

</div>

@Andrej Podhajský your solution worked like magic for me too! thank you 🙂

---

<div class="post-metadata">

**Author:** ![mgrandillo](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/mgrandillo/32/16104_2.png) [@mgrandillo](https://forum.katalon.com/u/mgrandillo)\
**Post date:** [January 27, 2021, 5:57pm UTC](https://forum.katalon.com/t/is-it-possible-to-call-one-custom-keyword-function-from-another-custom-keywords/11242/13 "2021-01-27T17:57:59Z")

</div>

> [@benjamin\_Hougland](#):
>
> package utilities

HI, I ran into the same issue, but when i apply the magic solution below, it seems that the function/method is not ran and the test case passes. It ignores this line it seems  
new clientAccount.ClientAccount().getRowColumnTable(GlobalVariable.switchToClientAccount)

@Keyword  
def verifySuccessfulLogin(String username){  
//if(WebUI.verifyOptionPresentByLabel(findTestObject(adminIdentityProvider), ‘Yahoo!’, false, 10, FailureHandling.OPTIONAL)){  
if (WebUI.verifyElementPresent(findTestObject(cloudAdmin), 0,FailureHandling.OPTIONAL) && (WebUI.verifyElementPresent(findTestObject(username), 0,FailureHandling.OPTIONAL))) {  
KeywordUtil.markPassed(‘SUCCESS: Login to the web portal was successful’)  
} else {  
println(‘ERROR: Login to the web portal was unsuccessful’)  
//switch to Cloud admin account in case another account type is logged in using the same email address  
new clientAccount.ClientAccount().getRowColumnTable(GlobalVariable.switchToClientAccount)  
}  
}

---

<div class="post-metadata">

**Author:** ![mgrandillo](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/mgrandillo/32/16104_2.png) [@mgrandillo](https://forum.katalon.com/u/mgrandillo)\
**Post date:** [January 28, 2021, 12:40pm UTC](https://forum.katalon.com/t/is-it-possible-to-call-one-custom-keyword-function-from-another-custom-keywords/11242/14 "2021-01-28T12:40:40Z")

</div>

Solved my problem. It was referencing the wrong table and the block of code never got executed.
