Calling variable from custom keyword into another custom keyword

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

}

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:

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:

static String generateUserEmail() { ... }

I hope this gets you closer.

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?