To iterate the same as in the other answers - the mist solid approach is to start from a known (clean) state of the system, test the sign up, and wipe all modifications at the end.
Thus you can construct a known dataset, that will cover all the cases to test - normal emails, with dots, apostrophes, long, negative tests, etc.
There should be a way to clean the accounts - sql, API, UI deleted as last resort, and when you have it, just add it at the end of the suite:
Suite Teardown Delete All Test Accounts
After this (uncalled for :) preaching/lecture, to you original question - constructing unique emails; two possible implementations.
The first is with a keyword which returns an email, having as unique part the current timestamp:
Return Unique Email Address
[Documentation] Returns a pseudo-unique email address. Optional arguments - prefix for the username, and domain
[Arguments] ${prefix}=user ${domain}=test.com
${unique}= Get Current Date result_format=epoch
# the current value is a float, where the part after the dot is the milliseconds - multiply by 1000, and cast to int, then - string
${unique}= Convert To Integer ${unique * 1000}
${unique}= Convert To String ${unique}
${result}= Set Variable ${prefix}${unique}@${domain}
[Return] ${result}
The keyword uses Get Current Date
from the DateTime
library, so be sure to import it.
It will return different emails if called in different milliseconds (in my observations, the robotframework overhead for simple keywords like this is at least 3ms, so it's good enough), and can be used like this:
*** Test Cases ***
Sign-up test 1
# will produce something like "[email protected]"
${email}= Return Unique Email
# do your normal sign-up steps
# will produce something like "[email protected]"
${email}= Return Unique Email me gmail.com
The second approach is to use a random string; just change this in the keyword:
${unique}= Generate Random String 12 [LETTERS]
, and it will return a random gibberish, 12 charters long (this comes from the String
library).
There is a (slight) possibly of collision in the 2nd approach, and you could increase the entropy by going with a bigger number - but overall, it will produce much less human-friendly (and nice to look at :) emails.