Data Driven Testing
Storing data in external resource, fetching data from external resource and utilizing in test script.
External resource can be
1) property file
2) Excel sheet
3) Data Base
Advantages of Data Driven Testing :
1) Allows to test application with multiple sets of data values during Regression testing.
2) Test data and verification data can be organized in just one file, and it is separate from the test case logic.
3) Actions and Functions can be reused in different tests.
4) Any changes in the test script do not effect the test data.
Disadvantages of Data Driven Testing :
1) Data validation is a time-consuming task when testing large amount of data.
2) A text editor like Notepad is required to create and maintain data files.
3) Maintenance is a big issue as large amount of coding needed for Data-Driven testing.
.properties file :
A .properties file is a simple text file mainly used in Java to store configuration data. Such files can be used for externalizing test data.
Each line in a .properties file normally contains a single data.
How to create properties file with .properties extension:
1) Select project and right click
2) Select New and Click on Folder
3) Enter Folder Name and click on Finish
4) Select Folder and right click
5) Select New and click on File
6) Enter file name with .properties extension and click on Finish
7) Store the data in properties file using key value format.
Example :
package DataDriven;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;
@Test
public class Script_02 {
public void login() throws IOException {
Properties p=new Properties();
FileInputStream f=new
FileInputStream("C:/Selenium/rutuja/configuration/config.properties");
p.load(f);
WebDriver driver=new FirefoxDriver();
driver.get(p.getProperty("url"));
driver.findElement(By.id("email")).sendKeys(p.getProperty("emailid"));
driver.findElement(By.id("pass")).sendKeys(p.getProperty("password"));
driver.close();
}
}