Wednesday, September 30, 2015

Data Driven testing Using POI

Scenario:

  • Launch the website
  • login with the credentials
  • create 1000 records by retrieving the  test data from an excel file
Below is the Code:


public class MyCollection_AddObject {
WebDriver driver;
  @Test
  public void AddObject() throws IOException, InterruptedException {
 
 FileInputStream fis= new FileInputStream("D://Rakesh Chityala//Selenium Automation//Test Data//Collectrium Add Object.xls");
 HSSFWorkbook wb= new HSSFWorkbook(fis);
 HSSFSheet s=wb.getSheetAt(0);  
 driver.findElement(By.xpath("//a[@title='My Collection']")).click();  
 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
 for (int i = 1; i <= s.getLastRowNum(); i++) {
 System.out.println("i values is:" +i);
 //System.out.println("Number of rows are: "+s.getLastRowNum());
 //System.out.println("<------------------------------entered for loop-------------------->"+i+ " No.rows found : " +s.getLastRowNum());
 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
 driver.findElement(By.xpath("//div[5]/div/button[3]")).click();
 driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
 for (String winHandle : driver.getWindowHandles()) {
   driver.switchTo().window(winHandle); // switch focus of WebDriver to the next found window handle (that's your newly opened window)
}  
 driver.findElement(By.xpath("(//input[@type='text'])[1]")).sendKeys(s.getRow(i).getCell(0).getStringCellValue());
 driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
 driver.findElement(By.xpath("//div[3]/button")).click();
 WebElement logo = (new WebDriverWait(driver, 60))
   .until(ExpectedConditions.elementToBeClickable(By.xpath("//div[5]/div/button[3]")));
 
 }
 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

 
  }
  @BeforeTest
  public void beforeTest() {
 driver= new FirefoxDriver();
 driver.get("https://url.com");
 driver.manage().window().maximize();
 WebElement myDynamicElement = (new WebDriverWait(driver, 10))
   .until(ExpectedConditions.presenceOfElementLocated(By.id("ember443")));
 driver.findElement(By.id("ember443")).sendKeys("XXXX");
 driver.findElement(By.id("ember446")).sendKeys("XXXX!");
 driver.findElement(By.id("ember434")).click();
 driver.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS);
 WebElement logo = (new WebDriverWait(driver, 60))
   .until(ExpectedConditions.presenceOfElementLocated(By.xpath("//a[@title='My Collection']")));
  }

  @AfterTest
  public void afterTest() {
  }

}

No comments:

Post a Comment