Data Driven Testing with Selenium Webdriver(testNG - Java)

I will first classify the types of data that the tester deals with during the implementation of automation framework into two categories:

  • Dynamic Data: which is the data you you need to change in each automation run to avoid data duplication and validation message such "The user already exist!!!"
  • Static Data: which is the data that you need to change based on the environment dependencies such as the application URL and other types of configuration data.

1) How to generate a dynamic data without any duplication:

There is a built in function in Java that generate the current time in milliseconds which is a thirteen digits number that could never be duplicated:

System.currentTimeMillis() 

The output from this function is from type Long to convert the output to String you can put inside ToString function as the below:

Long.toString(System.currentTimeMillis())

After we have converted the data to String now you can take just a small part of the number to avoid data limitation on some text field and it is preferably to always to take the last 5 digits as they keeps changing every seconds:

Long.toString(System.currentTimeMillis()).substring(8, 13)

2) How to change static data without doing any changes on the internal code:

Under your xml test run file, usually it's called "testing.xml" you have to add a global parameters:

<parameter name="Your_Parameter_Name" value="The_Parameter_Value"/>

Under your testing code you have to add same the parameters that you have defined in the XML file before each test-case or method your going to use:

@Parameters({"Your_Parameter_Name"}

Now if any configuration data have been changed like the app URL in our example, you have to change the URL from the testing run file "testing.xml" without the need to go to internal code.

Please let me know if you have any inquires

To view or add a comment, sign in

Insights from the community

Others also viewed

Explore topics