Data Driven Test Using CSV File In Selenium WebDriver

Earlier nosotros learnt how to perform information driven software automation testing using Java Excel API to read information from excel file In THIS POST. We produce got too used Apache POI API to read information from excel file In information driven software automation framework creation. Steps to produce information driven framework are given on THIS PAGE. Now let's
read information from CSV file to perform data driven software testing In selenium WebDriver. Bellow given steps volition exhibit y'all how to read information from from CSV file.

Download required files
We need opencsv-3.2.jar file to read information from CSV file in addition to I produce got prepared sample CSV information file (Detail.csv) to role It In bellow given example.
  1. DOWNLOAD and extract zip folder to acquire both to a higher house files. 
  2. Add "opencsv-3.2.jar" file In your project's construct path In eclipse. You tin larn how to add together external scandalize files In project's construct path In THIS POST.
  3. Copy glue "Detail.csv" file In D: drive.
"Detail.csv" file produce got to a greater extent than or less information in addition to nosotros volition role that information In out test. Main matter to larn hither Is how to read that information from CSV file.

Now run bellow given representative In Eclipse. It volition read information from CSV file in addition to role It In webdriver software automation essay representative to produce amount cast fields.

package Testing_Pack;  import java.io.FileReader; import java.io.IOException; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; import com.opencsv.CSVReader;  populace bird CSVRead {   //Provide CSV file path. It Is In D: Drive.  String CSV_PATH="D:\\Detail.csv";  WebDriver driver;     @BeforeTest  populace void setup() throws Exception {   driver = novel FirefoxDriver();   driver.manage().window().maximize();   driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);   driver.get(" ");  }    @Test  populace void csvDataRead() throws IOException{      CSVReader reader = novel CSVReader(new FileReader(CSV_PATH));   String [] csvCell;   //while loop volition live on executed till the final draw of piece of job In CSV.   patch ((csvCell = reader.readNext()) != null) {       String FName = csvCell[0];    String LName = csvCell[1];    String Email = csvCell[2];    String Mob = csvCell[3];    String companionship = csvCell[4];    driver.findElement(By.xpath("//input[@name='FirstName']")).sendKeys(FName);    driver.findElement(By.xpath("//input[@name='LastName']")).sendKeys(LName);    driver.findElement(By.xpath("//input[@name='EmailID']")).sendKeys(Email);    driver.findElement(By.xpath("//input[@name='MobNo']")).sendKeys(Mob);    driver.findElement(By.xpath("//input[@name='Company']")).sendKeys(company);    driver.findElement(By.xpath("//input[@value='Submit']")).click();    driver.switchTo().alert().accept();   }    } }

More interesting articles here :Generation Enggelmundus Internet Marketing Tool here :Zeageat IM 

http://www.software-testing-tutorials-automation.com/
Post a Comment (0)
Previous Post Next Post