Forum Discussion

hicks's avatar
hicks
New Contributor
10 years ago

How to auto increment the email address after each test execution?

Hey guys,
I have a test case that in the very first step creates a new user. I need help on incrementing the email address after each test execution and store it as a property in the test case level.

For example:
qateseter+1@test.com,
qateseter+2@test.com,
qateseter+3@test.com,
etc.

 

Is there any way to perform this action?
I'd appreciate any ideas.

2 Replies

  • hicks's avatar
    hicks
    New Contributor

    Now I'm adding a time stamp, but this is not exactly what we need.

    String generateUsername(String user)
    {
    date = new Date().format('MMddyy-HHmmss')
    user = user + "+" + date + "@test.com"
    }
    user = generateUsername("qatester")
    
    testRunner.testCase.setPropertyValue( "email", user )
    log.info user
    • nmrao's avatar
      nmrao
      Community Hero

      Here you go:

       

      1. Set initial value to a variable at test case level, say counter  = 0.

      2. Read variable test case variable count using getPropertyValue or context.expand('${#TestCase#counter}'), parset it as int, increment by one in the script you have.

      3. Do stuff what you wanted to do here // say, concatenate to another variable..

      4. Now set the updated counter back to property as string.

      You are done.