I have a scenario where I need to add new username everytime is run the script. For instance, if the last time I had added a name as test1, then next time when I add another name I should not add test1 since it is already added instead I should add test2.

Incrementing the text is fine I have used the below script

String user_id = AppXPathsConstants.user_id;

But my question is how to find that test1 already exists then add test 2 then after adding test2 I need to add test3 since test2 already exists.

  • How are you retrieving the user names ? – PDHide Feb 3 at 15:17
  • Add your element that displays usernames in UI – PDHide Feb 3 at 15:24
  • hi jon, I would need help to increment the property - Key with a unique name and not sure how to do can you pls help – sandy Feb 4 at 9:45

You have several ways to go:

If your app is pure black-box

  • Store what you already created in memory of your test. Example - parameterization that cucumber supplies. The downside is that when your tests are done and re-run they will start from scratch so you will have to reset your application database

  • If you have any interface that your application exposes that can list already created users, you can use that interface. The downside is that it will be likely working slowly.

  • You can attempt to create users and rely on your application that would be reporting that such user exists. Then you will be handling such response and roll the number of your user and try again and again. The downside is that it will be very slow and will rely on your app that might have defects, etc..

  • You can make your user have UUID in their account names. Like UUID.randomUUID().toString(). This will ensure they are unique.

If you own application infrastructure

  • Your tests can take the list of created users directly from the application database. Downside is that you will need to maintain some code to query the database

  • Ask your devs (or try yourself) to expose some additional interface (e.g. REST) that can list created users or take the latest created one. Then you will be able to use that interface to generate new user that yet does not exist.

  • this testing is done in java seleniumn and hence I need to read the values from the screen. is there any other inputs kindly guide – sandy Feb 3 at 9:44
  • Use UUID.randomUUID().toString() – Alexey R. Feb 3 at 9:46
  • what will this do? and where should I add this code...this is a user screen where any new user needs access to the application we enter the information of that user over here.that being the case there are existing usernames and I need to read the userid column in the screen and then need to add a new user everytime... – sandy Feb 3 at 9:46
  • This will generate the unique String that will not ever repeat in future so that you can add that part to your user name that will also become unique. – Alexey R. Feb 3 at 9:48
  • int j=0; for(int count1=0; count1 <10000; j++){ DriverUtil.waitTime(4000); Date d = new Date(System.currentTimeMillis()); driver.findElement(By.xpath("//input[contains(@name,'userIdInputInTxtWoPnlGrid')]")).sendKeys("test"+j); j++; – sandy Feb 3 at 9:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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