Friday, December 13, 2013

Junit-- How to fetch the data from xl sheet.

Junit-- How to fetch the data from xl sheet.


import java.io.FileInputStream;
import jxl.Sheet;
import jxl.Workbook;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.server.RemoteControlConfiguration;
import org.openqa.selenium.server.SeleniumServer;
import com.thoughtworks.selenium.*;
import  org.openqa.selenium.support.ui.Select;

public class DatadrivenJUnit extends SeleneseTestCase
{


@BeforeClass
public void setUp() throws Exception 
{
System.out.println("Started");


}
@Test
public void testDatadrivenJUnit() throws Exception
{

System.setProperty("webdriver.ie.driver", "C:\\HIS-TestingAutomation\\IEDriverServer.exe");
WebDriver ds = new InternetExplorerDriver();
FileInputStream fi=new FileInputStream("C:\\HIS-TestingAutomation\\Test Dat\\TestData.xls");
Workbook w=Workbook.getWorkbook(fi);
Sheet s=w.getSheet(0);
ds.get("http://10.152.3.254/WHIS/WHISLoginPage.aspx?from=d");
ds.manage().window().maximize();
   for (int i = 1; i < s.getRows(); i++)
 { //Read data from excel sheet
  
ds.findElement(By.name("txtUsername")).sendKeys(s.getCell(0, 1).getContents());
ds.findElement(By.name("txtPassword")).sendKeys(s.getCell(1, 1).getContents());
ds.findElement(By.name("ddlLocation")).sendKeys(s.getCell(2, 1).getContents());
// Select location = new Select(ds.findElement(By.name("ddlLocation")));
// location.selectByVisibleText(s.getCell(2, 1).getContents());
//
ds.findElement(By.name("btnLogin")).click();
  } }
@AfterClass
 public void tearDown() throws InterruptedException{

}
 }

No comments:

Post a Comment

TestNG - Can i use the 2 different data providers to same @test methods in TestNG?

public Object [][] dp1 () { return new Object [][] { new Object [] { "a" , "b" }, new Obje...