Database File as Data Provider

 If user want to provide data using database below is the properties which user need to configure in property file as per the requirement.


Following is the testcase where sql query is required to get data from database.

    	@QAFDataProvider(sqlQuery="select username,password,isvalid from login_table")
	@Test(description = "Database as data provider ")
	public void login(Map <String, String> data) {

Configure/Override QAFDataProvider parameters by providing property :

    • Configuration for individual tests :

To set data provider parameters for individual test method, you can provide property as shown below.


For example,

      • login.testdata=dataFile=resources/data/loginbyjson.json
      • login.testdata=dataFile=resources/data/loginbyexcel.xls; sheetName="login"
      •        (xml's node as a key)
      • login.testdata=sqlQuery=select col1,col2,col3 from login_table


    • Configuration globally :

To configure parameters globally for all data driven test user can set property by "global.testdata" parameter as shown below.


For example,

      • global.testdata=dataFile=resources/data/${class}/${method}.csv
      • global.testdata=dataFile=resources/data/testdata.xls; sheetName=${class};
      • global.testdata=dataFile=resources/data/${class}.xls; sheetName=${method}
      • global.testdata=key=${method}/data
      • global.testdata=dataFile=resources/testdata.xls; key=${method}_data        (xls key)

As shown in the above examples ${class} and ${method} parameters are used which user can use as per the requirement.

Priority for parameters to take effect is:

  • Parameters set using test method specific test data property, i.e. "<testcase_name>.testdata"
  • Parameters set using global test data property, i.e. "gloabal.testdata"
  • Parameters hardcoded in QAFDataProvider annotation itself 
Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request


Article is closed for comments.
Powered by Zendesk