Wednesday 5 February 2014

Parameterizing Web Driver test with Random value

Generating Random String :

    As a automation tester,we can come across the various steps to automate,I have come across the following situation:

Requirements :
  1. Open our application URL (http://www.someurl.com)
  2. Click on Register -> It open Registration Page
  3. Fill all the details such as  First Name,Last Name,User Name, Email.....etc
  4. Click on Submit the details
  5. Verify user created successfully
 NOTE : I want to create 100 users 

Partial Solution 1 :


  1. Create a Register method and parameter it as shown in below pic
     2.   Parameter the test  using the external data sheet (TestData.xls),This execl should have all the 100
            user's First Name,Last Name,User Name Details


Limitation of Solution 1:

     This approach will work pretty good at first iteration,But when i execute the same script multiple times ,I will get the error message as : 
  This error occurs,because we have used the excel data for previous iteration


Best Solution : 

     After trying all the possibilities,we have decided to go with the Random Generator,It gives you one unique random string each time it is executed

   Steps to use : 

  1.        Download the TestUtils.jar from     https://drive.google.com/file/d/0B9ZTXXKTZAYVUGZ5d0loWUNhMlk/edit?usp=sharing
  2.    Add it to your Class path
   3.    Import the following class in your Test.java
                Import com.webdriver.framework.*;
   4.    Use any one of the code shown below :

5.  Finally my code is looks like below : 







Appreciate your comments and suggestions :

NOTE:Thanks to the author of this method and my mentor  :Mr.Pankaj Kumar,

















   

3 comments: