Here is the code I used to create randome email addresses

5 posts, 1 answers
  1. Wade
    Wade avatar
    25 posts
    Member since:
    Oct 2014

    Posted 17 Mar 2015 Link to this post

    This code will create a random email address.

    There are two extracted values, myRandomEmail and ConfirmEmail. The first can be used if you just need a single email address, the second can be used if you have to enter the same email as a confirmation email, like and account setup page.

    You just pop this puppy in a coded step.

    StringBuilder sb = new StringBuilder();<br>Random rnd = new Random();<br>char ch;<br>for (int ctr = 0; ctr < 9; ctr++)
    {
    ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * rnd.NextDouble() + 65)));
    sb.Append(ch);
    }
    sb.Append(
    "@GMAIL.COM");
    this
    .SetExtractedValue("myRandomEmail",sb.ToString());
    this.SetExtractedValue("ConfirmEmail",sb.ToString());
  2. Wade
    Wade avatar
    25 posts
    Member since:
    Oct 2014

    Posted 18 Mar 2015 in reply to Wade Link to this post

    StringBuilder sb = new StringBuilder();
    Random rnd = new Random();
    char ch;
    for (int ctr = 0; ctr < 9; ctr++)
     
    {
     
    ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * rnd.NextDouble() + 65)));
     
    sb.Append(ch);
     
    }
     
    sb.Append("@GMAIL.COM");
     
    this.SetExtractedValue("myRandomEmail",sb.ToString());
     
    this.SetExtractedValue("ConfirmEmail",sb.ToString());
  3. Answer
    Boyan Boev
    Admin
    Boyan Boev avatar
    1043 posts

    Posted 20 Mar 2015 Link to this post

    Hello Wade,

    Thank you for sharing the code. 

    We really appreciate it.

    Regards,
    Boyan Boev
    Telerik
     
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
     
  4. George
    George avatar
    1 posts
    Member since:
    Mar 2016

    Posted 06 Apr in reply to Wade Link to this post

    Hi Wade, thanks for your code, but how can I use this in my coded steps in the Test Studio, also how can I generate a random number to create random users etc. I followed example on Test Studio documentation that didn't work. pls can you help

  5. Boyan Boev
    Admin
    Boyan Boev avatar
    1043 posts

    Posted 11 Apr Link to this post

    Hello George,

    Here is how to create a coded step.

    What does't not work in our example for creating a random number. Please give us more detailed information so we can give a solution.

    Hope to hear from you soon.

    Regards,
    Boyan Boev
    Telerik
     
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
     
Back to Top
  Cast Your Vote at DevPro Connections! Cast Your Vote at  Win IT Pro Connections!