# Calling variable from custom keyword into another custom keyword

**URL:** <https://forum.katalon.com/t/calling-variable-from-custom-keyword-into-another-custom-keyword/11847>\
**Category:** Miscellaneous\
**Created:** [July 3, 2018, 6:09pm UTC](https://forum.katalon.com/t/calling-variable-from-custom-keyword-into-another-custom-keyword/11847 "2018-07-03T18:09:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sam\_Kaplan](https://avatars.discourse-cdn.com/v4/letter/s/e47774/32.png) [@Sam\_Kaplan](https://forum.katalon.com/u/Sam_Kaplan)\
**Post date:** [July 3, 2018, 6:09pm UTC](https://forum.katalon.com/t/calling-variable-from-custom-keyword-into-another-custom-keyword/11847/1 "2018-07-03T18:09:36Z")

</div>

I’m writing a test case that uses multiple keywords from the same class. In one keyword, method calls another keyword to randomly generate the email. Is there a way I can get third keyword to get the value of the generated email string and compare it to something else?

**public**  **class** UserPathReg {

@Keyword //Generate the user email

**public**  **static** generateUserEmail( **int** length){

[Generate random email of desired length from random characters]

**return** sb.toString();

}

@Keyword //Call the function to generate user email

**public**  **static** addItemToCart(){

**def** newEmail = (_generateUserEmail_(8)+“@email.com”)

WebUI._setText_(EmailRegister, newEmail)

}

@Keyword //Get string of generated email, compare it to web element

**public**  **static** fillRegistryForm(){

**def** userEmail = [reference to value of the random email previously generated]

assert [Web element on page] == userEmail

}

---

<div class="post-metadata">

**Author:** ![Russ\_Thomas](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/russ_thomas/32/11884_2.png) [@Russ\_Thomas](https://forum.katalon.com/u/Russ_Thomas)\
**Post date:** [July 3, 2018, 7:13pm UTC](https://forum.katalon.com/t/calling-variable-from-custom-keyword-into-another-custom-keyword/11847/2 "2018-07-03T19:13:07Z")

</div>

Understand that **fillResgistryForm** has no knowledge of “email previously generated”, since:

1 - You are not passing in a reference to the email.

2 - “previous” has no meaning unless you tell us the call sequence you are using to establish the chronology of events.

Start here:

```auto
static void fillRegistryForm(String userEmail) {
  if(something == userEmail) {
    // do fabulous things
  }
}

```

Aside:

The method **generateUserEmail** is returning a String, you should define it as such:

```auto
static String generateUserEmail() { ... }

```

I hope this gets you closer.

---

<div class="post-metadata">

**Author:** ![Sam\_Kaplan](https://avatars.discourse-cdn.com/v4/letter/s/e47774/32.png) [@Sam\_Kaplan](https://forum.katalon.com/u/Sam_Kaplan)\
**Post date:** [July 3, 2018, 7:50pm UTC](https://forum.katalon.com/t/calling-variable-from-custom-keyword-into-another-custom-keyword/11847/3 "2018-07-03T19:50:43Z")

</div>

Unfortunately, I don’t think that helps. The plan for my test case is to call the different keywords, each one fulfilling a different part of the test case:

UserPathReg._addItemToCart_()

UserPathReg._fillRegistryForm_()

UserPathReg.completePurchase()

My best guess is to add a step to generate the email at the beginning of the test, then just pass that string into the other keywords to use for their tests?
