Question

I'm creating new user, each and every time I have to create new username. Using below code i can't generate unique username each time when I run the script. Please help me out

int i = 0;

for(int count1=0; count1 <10000; i++){
driver.findElement(By.id("txtUserName")).sendKeys("classroomuser"+i);
i++;
Was it helpful?

Solution

Instead of using counter, use time in milliseconds from epoch, which will create unique user every time.

Date d = new Date(System.currentTimeMillis());
driver.findElement(By.id("txtUserName")).sendKeys("classroomuser" + d);

For more details, go here

OTHER TIPS

If java then you can also use the class RandomUtils. This has the method to create random strings. The more number of letters the lesser the chance of repetition if we take permutations into account. Happy coding.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top