I am beginner in writing automated tests with robotframework(Python and Selenium2Libraries) and I've faced to the issue related to user registration flow.

Challenge is:

The application under test makes sure users cannot sign up more than once with an email address. Because we want to be able to run the sign up test many times, we need to sign up with a unique email address in each test run.

I would like to have solution that will enter in "email address field" +n like:

1st execution: email address: [email protected]
2nd execution: email address: [email protected]

How to handle this in robotframework?

3 Answers 3


Test should run in isolation.

In the ideal world:

  • Setup a clean environment with scripts. (new servers, clean database, etc)
  • Run your tests
  • Destroy the test environment

Today with cloud infrastructure and containers (e.g. docker) this becomes easier and easier.

Other solutions are hackish:

  • Store the last number/ID in a file and retrieve it before the test
  • Generate a guid like username for the email-address
  • Use a timestamp as username
  • Remove the email address from the database before and after the test

Things like this will probably lead to manual cleaning as test sometimes fail half way. Prevent you from running the tests in parallel to speed up the test feedback cycle.


I see two major aspects to the situation:

  1. Whether you have the ability to reset your environment at the beginning of each test
  2. Whether you need to be able to test multiple signups in a single run.

If you can reset your environment, Niels' first solution is the way to go. If that isn't practical, or if you have to test multiple signups in one test run (e.g. as part of a load test, or your test run includes verifying that a unique email address will be accepted and a duplicate one will not), you can use your planned solution - which you can do as a simple method (pseudocode, since I'm not a Python expert)

def generate_email(test_number):
    return 'name' + str(test_number) + '@gmail.com'

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.