Follow

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.

    	 	db.driver.class=com.mysql.jdbc.Driver
		db.connection.url=jdbc:mysql://localhost:3306/db
		db.user=username
		db.pwd=password

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) {
		doLogin(data.get("username"),data.get("password"));
		assertLoginMsg(data.get("isvalid"))
	}

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.

	       <testcase_name>.testdata=[<param>=value]  

For example,

      • login.testdata=dataFile=resources/data/loginbyjson.json
      • login.testdata=dataFile=resources/data/loginbyexcel.xls; sheetName="login"
      • login.testdata=key=login.data        (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.

               global.testdata=[<param>=value]

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

0 Comments

Article is closed for comments.
Powered by Zendesk