webdriver, dataprovider, datadriven, excel, testng framework

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

import org.openqa.selenium.By;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;


public class yahoo_login_dp_excel
{
    FirefoxDriver fd;
   
    @DataProvider(name="p1")
    public Object[][] xldata() throws Exception
    {    ///////////reading data from excel and parametrise using dataprovider   
        FileInputStream fs=new FileInputStream("e:\\sel_dec\\data.xls");
        Workbook wb=Workbook.getWorkbook(fs);
        Sheet ws=wb.getSheet(0);
       
        String str[][]=new String[3][2];
        for(int r=1;r        {
              
         str[r-1][0]=ws.getCell(0, r).getContents();
         str[r-1][1]=ws.getCell(1,r).getContents();        
        }        
        return str;
    }
    @BeforeClass
    public void BeforeClass()
    {
     fd=new FirefoxDriver();
   
    }   
   
    @Test(dataProvider="p1")
    public void fn_login(String uid,String pwd) throws Exception
    {
        fd.get("http://www.yahoomail.com");
        fd.findElement(By.name("login")).sendKeys(uid);
        fd.findElement(By.name("passwd")).sendKeys(pwd);
        fd.findElement(By.name(".save")).click();
        Thread.sleep(5000);
        try
        {
          if(fd.findElement(By.linkText("Sign Out")).isDisplayed())
          {
           System.out.println("Login is success");
           fd.findElement(By.linkText("Sign Out")).click();
          }
         }
         catch(Exception e)
         {
          System.out.println("Login is failed");
         }
      }
   

   @AfterClass
   public void AfterClass()
   {
       fd.close();
   }

}

Comments