3

Can we generate unique distinct users for parallel tests in selenium WebDriver and java?

Suppose, in google create an account action I want to pass firstname, Lastname, Username & Password for different browsers.
I was written script & when it was tried to run in parallelly on IE, Safari, FF & Chrome, It successfully runs on the single browser but for the 2nd browser, it shows for email Id -"Email already exists".
This is right because we never create more accounts with the same ID.

Now my question is:

How to pass different inputs (strings) in same field textbox for different browsers to create an account.

Suppose If we set an array with 4 input strings. should we take a random value from this array for different browsers?

an array of multiple inputs  
-Email1  
-Email2  
-Email3  
-Email4  

when we run the script in parallelly- for the first browser it should take Email1 -When the same script will run for the 2nd browser it should take email2 ..same for 3rd & 4th. Is it possible in Selenium with java? If Yes, How?

Your answer is highly appreciated.

4
  • What is your programming skill level? What language do you use? I would assume that for any half-decent programmer in any language, creating a loop which reads a table and calls subroutine which fills fields repeatedly will be really a trivial task. So I wonder ... May 17, 2016 at 13:46
  • 2
    I know we can put a set of email ID's in an arrayList. but problem is how can I call them randomly for different browsers. Suppose What i did in above example, I have stored 4 strings in array & now I want call these one by one for each browser. What can I do? May 17, 2016 at 13:56
  • How you plan to share arrayList between instances of different browsers? May 17, 2016 at 22:35
  • Your claim to be 'good in java' is contradicted by your question. Automated testing is programming. You first need to improve your general programming skills with regard to parameters, reusable functions, re-entrant coding and data driven automated testing. Apr 11, 2017 at 9:37

3 Answers 3

3

So what you are trying to do is have a script run on different browsers and want to register a user with a unique email address.

Well, Google allows you to use single email address for such testing purposes with incremental characters appended to your ID. How this works is,

You have a Gmail account say [email protected]. You can use this same account for testing purpose and register different unique users by appending "+" followed a character, string or number and then rest of the address (@gmail.com). For example, [email protected] [email protected] ... [email protected]

All the email conversations for each of these regisered user will go to [email protected], but the name and email will be the respective test account.

Now, what you need to do is have a array of various email addresses in the format explained above.

OR

Write a loop to generate such email addresses with incremental numbers appended to the ID.

Then, you can pass a different email address for each browser instance using a loop, or a conditional check. You can do something like,

if(browser is FF) { pass [email protected] }

if(browser is IE) { pass [email protected] }

if(browser is Chrome) { pass [email protected] }

You can also have a loop that will rotate the browsers and at the same time generate a unique auto increment email and register a user. Some thing like,

for(i=0;i<n;i++)
{
    for(j=0;j<4;j++)
    {
        if(j==0){Browser = FF}
        if(j==1){Browser = IE}
        if(j==2){Browser = Chrome}
        if(j==3){Browser = Safari}
        email increment
        register user
    }
}
1
  • absolutely right. Thanks TESTasy. I w'll try & let you know. May 18, 2016 at 5:08
2

If you do not mind about random values, for email you can use javascript to generate valid email anytime the TestCase runs including runs in different browsers.

Example (you can modify or change the script):

javascript{
   /*random email*/
   var chars = 'abcdefghijklmnopqrstuvwxyz'; 
   chars[Math.floor(Math.random()*26)]+Math.random().toString(36).substring(2,8)+'.'+chars[Math.floor(Math.random()*26)]+Math.random().toString(36).substring(2,6)+'@'+chars[Math.floor(Math.random()*26)]+Math.random().toString(36).substring(2,7)+"."+chars[Math.floor(Math.random()*26)]+chars[Math.floor(Math.random()*26)]
}

It would be very uncommon, that the same value would be generated.

BEWARE: On the other hand, using random numbers in testing is not a best practice, as different values could lead to different test results. Therefore doublechceck, if the resulted values are always valid for the test case.

1

My recommendation is that you store the state of what has been used within a test.

So the test would initially create a new user with a unique email. You can use some random character generation or a database sequence to make each one unique. Personally I recommend using sequences as they are more deterministic than random characters and less likely to have unexpected side-effects. You then need to store this within that test suite. The next step or test within that suite or master test should then use that variable to know the user in question. The tests that share the info must be grouped to run together to get over the parallelization issue.

Before and after all sets (suites) of tests you should have an empty database. This can be a big transition/hurdle for some individuals/companies who didn't used to do things this way (clearing the db and creating all the test and reference data for each set of tests) in the past. Like me.

8
  • 2
    thanks Michael, but how should we generate an valid Email ID from random character. check in above question that I have edited & added code for random email id generation, now question comes in my mind how we can verify that every time it generates an valid Email ID? Is it possible by using random string generation logic? May 17, 2016 at 12:25
  • 1
    Don't use a random string. Use [email protected], [email protected], [email protected] i.e. use a sequence. You're not trying to actually test emails names, just use unique ones. tests that are validating whether a given name is a valid email are different - and they should use specific good/bad fixed values to test. Make tests deterministic so that when they fail you know why and can reproduce exact same results each time. May 17, 2016 at 12:49
  • 1
    Perhaps I should ask "Are you testing if users can create logins" or "Are you testing if logged-in users can do othert activities. They are quite different. Even in the case of testing whether users can sign-up with certain emails, test the specific cases you want to be good/bad. May 17, 2016 at 12:51
  • 1
    Once we know exactly the intent I'd also recommend changing the question title to something like "How can we generate unique distinct users for parallel tests with selenium" May 17, 2016 at 12:54
  • 1
    Yes definitely after sign up process, I have to do some further activities, like once I sign up from site, I logged out & again tried to login with same created account with username & passwd. after login I have to do some again activities like there is user dashboard points he/she can perform an y activities from dashboard. I have used Page object mode designing & page factory & created separate classes for - 1) Sign up Page 2) Login Page 3) Dashboard Page. & I have to make these all stuffs with Sign up page. May 17, 2016 at 12:57

Your Answer

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

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