How to read data from excel using Selenium

We have know that Selenium is using for Web application testing and Browser testing.

Today we are learning how to read data from excel using Selenium.In order to perform this action we need to download third party APIs for excel to load into Selenium.For this we are using jxl.jar file for Excel operations in Selenium.

Please download jxl jar from this download jar

Steps to create script.

1.Create project
2.Create Package
3.Create Class
4.Associate library files to project
5.Create the Excel sheet with data,for example i am using Gmail login.Please fine the below


6.Start the Selenium Server
7.Create the below script

package com.Gmail.Login;

import static org.junit.Assert.*;

import java.io.FileInputStream;
import java.io.IOException;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.server.SeleniumServer;
import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.SeleneseTestCase;

@SuppressWarnings({ "unused", "deprecation" })
public class Gmaillogins extends SeleneseTestCase{

   @Before
   public void setUp() throws Exception {
       SeleniumServer ss=new SeleniumServer();
       ss.start();
       selenium=new DefaultSelenium("localhost",4444,"firefox", "http://www.gmail.com");
       selenium.start();
   }

   @After
   public void tearDown() throws Exception {
   }

   @Test
   public void test() throws BiffException, IOException, InterruptedException {
       selenium.open("/");
       selenium.windowMaximize();
       FileInputStream fis=new FileInputStream("D:\\2014\\Java_Applications\\gmail_login.xls");
       Workbook wb=Workbook.getWorkbook(fis);
       Sheet s=wb.getSheet(0);
       selenium.type("id=Email",s.getCell(0,1).getContents());
       selenium.type("id=Passwd",s.getCell(1,1).getContents());
       Thread.sleep(3500);
   }

}

8.Save the script

9.Run the script

No comments:

Post a Comment