Вопрос

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++;
Это было полезно?

Решение

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

Другие советы

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top