Thursday 3 October 2013

Login Scenario – Providing Login Detail from Excel Sheet

Excel Sheet format should be in .XLS format
import java.io.FileInputStream;
import jxl.Sheet;
import jxl.Workbook;
import com.thoughtworks.selenium.*;
import org.openqa.selenium.server.*;
import org.testng.annotations.*;
public class Loginexcel {
public Selenium selenium;
public SeleniumServer seleniumserver;
@BeforeClass
public void setUp() throws Exception {
RemoteControlConfiguration rc = new RemoteControlConfiguration();
seleniumserver = new SeleniumServer(rc);
selenium = new DefaultSelenium(“localhost”, 4444, “*firefox”, “http://”);
seleniumserver.start();
selenium.start();
}
@Test
public void testDefaultTNG()throws Exception {
FileInputStream fi=new FileInputStream(“E:\\Selenium\\LoginExcel.xls”);
Workbook w=Workbook.getWorkbook(fi);
Sheet s=w.getSheet(0);
selenium.open(“http://127.0.0.1/orangehrm-2.6/login.php”);
selenium.windowMaximize();
for (int i = 1; i < s.getRows(); i++)
{
//Read data from excel sheet
String s1 = s.getCell(0,i).getContents();
String s2 = s.getCell(1,i).getContents();
selenium.type(“txtUserName”,s1);
selenium.type(“txtPassword”,s2);
selenium.click(“Submit”);
Thread.sleep(2000);
selenium.click(“Link=Logout”);
}
}
@AfterClass
public void tearDown() throws InterruptedException{
selenium.stop();
seleniumserver.stop();
}
}

No comments:

Post a Comment

Angular JS Protractor Installation process - Tutorial Part 1

                     Protractor, formally known as E2E testing framework, is an open source functional automation framework designed spe...