How to add +1 to an e-mailadress every time you run the test

How can I add +1 to an e-mailadres every time when I run the test and let it be unique.
I don’t have enough experience with programming to solve it myself.

The e-mailadress is like ‘suzanne+test5@(companyname).com’

So the test has to add +1 every time and needs to be unique.

Thank you for your kind help.

Hello,

the most secure way is to get UNIX timestamp and use it as username. You get unique number every millisecond.

long ts = System.currentTimeMillis()
String email = ts + "@yourcompany.com"

Thank you.
But I need to put my own company e-mailadress inside to receive e-mails, also to login in the system.

So do you need specifically

suzanne+testX@(companyname).com

where X is positive number increased every time? How many such addresses you have?

Hi Marek,

Yes that is true. I asked the developer :slight_smile:)
There is no limit of the address. Because it will come to my mailbox anyway

@suzanne.vandeneinden it has to be incremented, or just unique?
If just unique, the easiest way is to use a timestamp, as suggested,or a random sequence, or an UUID.

If has to be incremented, we may need some additional info on how the test is intended to run, e.g plenty times in a suite, or in a loop, or is a data-driven test.
Please describe better the scenario you intend to achieve.

Timestamp is not a solution for this case. But I will remember it for other projects.

It has to be incremented.
here some more information.
I need to login to create this mailadress (+1) (login as company), then I need to login with created details (as customer) to create a file.
We can only use the file once

def String getEmailAddress() {
	String pattern = "suzanne+test%d@(companyname).com"
	File counterFile = new File(RunConfiguration.getProjectDir() + "\\Data Files\\mailCounter.json")
	if(!counterFile.exists()) {
		KeywordUtil.markError("Not able to find config file for email generator.")
	}
	
	// get current number from JSON file
	JsonSlurper slurper = new JsonSlurper()
	Map parsedJson = slurper.parse(counterFile)
	int getNumber = parsedJson.get("count")
	String result = String.format(pattern, getNumber)
	
	// update JSON file
	parsedJson.replace("count", ++getNumber)
	FileWriter fw = new FileWriter(counterFile)
	fw.write(JsonOutput.toJson(parsedJson))
	fw.close()

	return result
}

Just create a new file called mailCounter.json in Data Files folder and put following JSON structure there:
{ "count" : 1 }

Or use any other location and update file path accordingly.

1 Like

Going to try it later today after the meeting.
Thank you very much!

Maybe stupid but when I go to data files in Katalon I can’t make a new file.
Or do I need to go to the harddisk and create it there ?

Yes, open file explorer and navigate to Katalon project’s directory and create a new file as usual.
But as I said, you can use any other directory, just change File constructor’s parameter in the code.

1 Like

I will ask here when I don’t know exactly.
Thank you very much. Feeling blond now :stuck_out_tongue: