Data Driven testing
1. What is Data driven testing?
Read the data from external resource & run the test is called Data driven testing
(parameterization)
2. Why Data Driven testing?
As per the rule of the automation data shouldn’t not hardcoded(fixed) with in a
test scripts, because data modification & maintenance is tedious job when you
want to run the test with different data, instead we should get the data from
external resource like xlsx, .properties file , db , XML, JSON, CMD Line Data
3. What is Advantages of Data driven testing
1. Maintenance of the test data is easy
2. Modification of the test data in external recourse is easy
3. Cross browser /platform testing is easy (means change the browser in property
File)
4. Running test scripts in different Environment is easy
5. Running test scripts in different credentials is easy
6. We can create the test data prior the Suite execution (we can also get the
data from testData team)
7. Rerunning same test Script with multiple time with different data is easy
Data driven testing from Properties File
1. What is Properties File?
Properties is java feature file where we can store the data in from of key & values
pair,
Key & value data type should be always string .
2. Why Property file ?
Property file is light weight & faster to read the data compare to any other
file , & java as own Class to read the data from property
3. How to read data from properties File?
• Get the java representation Object of the Physical file using “FileInputSteam
• Create a Object of “Properties” class & load all the keys
• Read the data using getProperty(“Key”)
Note : properties file light weight & faster in execution compare to Excel
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class ReadDataFromPropertiesFile {
public static void main(String[] args) throws Throwable {
[Link]().setup();
WebDriver driver=new EdgeDriver();
FileInputStream fis = new
FileInputStream("./src/test/resources/[Link]");
//FileInputStream fis=new FileInputStream("C:\\Users\\Shobha\\Downloads\\
[Link]");
Properties pro = new Properties();
[Link](fis);
String URL = [Link]("url");
String UERNAME = [Link]("username");
String PASSWORD = [Link]("password");
[Link](URL);
[Link]([Link]("user-name")).sendKeys(UERNAME);
[Link]([Link]("password")).sendKeys(PASSWORD);
[Link]([Link]("login-button")).click();
}
-----------------------------------------------------------------------------------
-------------------------------------------------------------------------------
import [Link];
import [Link];
import [Link];
public class InsertDataToProperties_File {
public static void main(String[] args) throws Throwable {
Properties pro = new Properties();
[Link]("username", "standard_user");
[Link]("password", "secret_sauce");
[Link]("url", "[Link]
FileOutputStream fos = new
FileOutputStream("./src/test/resources/[Link]");
[Link](fos, "COMMONDATA");
[Link]("data written successfully");
}
-----------------------------------------------------------------------------------
-------------------------------------------------------------------------------
Data driven testing from Excel File
Apache Poi is the open source libraries used to get & write data from all
Microsoft documents like Excel , docx , ppt etc
In real time most the company preferred the keep the test script data in Excel,
because data will be in well-organized manner, so that modification & maintenance
is easier.
Installation steps:
1. Go the Maven Project
2. Edit [Link] file
3. Go to [Link]
4. Search for apache-POI
5. Copy the dependency
6. Add dependency inside the <dependencies> in [Link]
<dependency>
<groupId>[Link]</groupId>
<artifactId>poi</artifactId>
<version>4.1.2</version>
</dependency>
<dependency>
<groupId>[Link]</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.2</version>
</dependency>
program:-
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class FetchSingleDataFromExcel {
public static void main(String[] args) throws Throwable {
//Step1:-Set the path
//FileInputStream fes = new
FileInputStream("./src/test/resources/[Link]");
FileInputStream fes = new FileInputStream("C:\\Users\\Shobha\\Desktop\\
[Link]");
//step2:-Open WorkBook in read mode
Workbook book = [Link](fes);
//step3:-get control to the sheet
Sheet sheet = [Link]("FirstData");
//step4:-get control on row
Row row = [Link](1);
//step5:-get control on cell
Cell cel = [Link](1);
String ExcelDAta = [Link]();
[Link](ExcelDAta);
}
}
-----------------------------------------------------------------------------------
----------------------------------------------------------------------------------
mport [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class InsertSingleDataToExcel {
public static void main(String[] args) throws Throwable {
//Step1:-Set the path
FileInputStream fes = new FileInputStream("./src/test/resources/[Link]");
//FileInputStream fes = new FileInputStream("C:\\Users\\Shobha\\Desktop\\
[Link]");
//step2:-Open WorkBook in read mode
Workbook book = [Link](fes);
//step3:-get control to the sheet
Sheet sheet = [Link]("FirstData");
Row row = [Link](0);
Cell cel1 = [Link](0);
[Link]("TestYantra");
FileOutputStream fos = new
FileOutputStream("./src/test/resources/[Link]");
[Link](fos);
[Link]();
}
-----------------------------------------------------------------------------------
------------------------------------------------------------------------------