Random e-mail generation

hi,sadly, im not familiar with coding, looking for registration auto test. How can i generate random variable for email field? (@ included)

You can create a custom keyword as follow

public class RandomEmail {
    @Keyword
    public String getEmail(String suffix,String prefix){
        int randomNo = (int)(Math.random() * 1000);
        return suffix + randomNo + "@" + prefix; 
    }

}

And then use in the test as follow

1Capture.PNG

2 Likes

Rahul said:

You can create a custom keyword as follow

public class RandomEmail {
    @Keyword
    public String getEmail(String suffix,String prefix){
        int randomNo = (int)(Math.random() * 1000);
        return suffix + randomNo + "@" + prefix; 
    }

}


And then use in the test as follow  
  
![](https://s3.amazonaws.com/katalon-forum/editor/cx/2eygakhjs9c0.png "Image: https://s3.amazonaws.com/katalon-forum/editor/cx/2eygakhjs9c0.png")  
  

  

Tnx. Sadly im just started to learn coding. I created custom keyword, can i somehow input it in my registration test?

'Focus on email input'WebUI.focus(findTestObject('Page_Login/input_email_create'))'Generate random email using custom keyword'String Mail = CustomKeywords.'randomEmail.getEmail'('testing', 'testing.test')'Type random email generated in to email input'WebUI.sendKeys(findTestObject('Page_Login/input_email_create'), Mail)
1 Like

Hi this not works for me, reason “multiplecompilationerrorsexception: startup failed” what is the reason?

hi @Rahul,
I have this error

Reason: groovy.lang.MissingPropertyException: No such property: CustomKeywords for class

can you help me?


@Then(“Invito un utente”)
def Invito_un_utente() {
Mobile.setText(findTestObject(‘Carrier/28-invita utente/android.widget.EditText0 - Inserisci la ragione sociale dellazienda’),
‘pittigghiu’, 0)
String Mail = CustomKeywords.‘com.question.RandomEmail.getEmail’(‘testing’, ‘testing.test’)
WebUI.setText(findTestObject(‘Object Repository/Carrier/28-invita utente/android.widget.EditText0 - Inserisci le-mail dell’), Mail)
Mobile.tap(findTestObject(‘Carrier/28-invita utente/android.widget.Button0 - CONFERMA’), 0)
Mobile.tap(findTestObject(‘Carrier/28-invita utente/android.widget.TextView0 - OK’), 0)
Mobile.closeApplication()
}


custom k.

public class RandomEmail {
@Keyword
public String getEmail(String suffix,String prefix){
int randomNo = (int)(Math.random() * 1000);
return suffix + randomNo + “@” + prefix;
}