Getting array index out of bound exception while designing data driven framework.

Hi

I have done everything correctly but still getting the error…please help.

Getting array index out of bound exception while designing data driven framework. Getting array index out of bound exception while designing data driven framework.

1 – Library class


package ExcelData;
import java.io.File;

import java.io.FileInputStream;

import org.apache.poi.ss.usermodel.Sheet;

import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class ExcelLibrary {

XSSFWorkbook w;

Sheet s;

public ExcelLibrary(String path)

{

try {

File src = new File(path);

FileInputStream fi= new FileInputStream(src);

w = new XSSFWorkbook(fi);
}catch (Exception e) {
e.getMessage();

}

}

public String getData(int SheetNum,int rownum,int colnum)

{

s = w.getSheetAt(SheetNum);

String data1 = s.getRow(rownum).getCell(colnum).getStringCellValue();

return data1;
}

public int RowCount(int SheetIndex)

{

int totalrow=w.getSheetAt(SheetIndex).getLastRowNum();

totalrow=totalrow+1;

return totalrow;
}

}

2 –  main class


package Library;
import java.util.List;
import ExcelData.ExcelLibrary;
import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.openqa.selenium.support.ui.ExpectedConditions;

import org.openqa.selenium.support.ui.Select;

import org.openqa.selenium.support.ui.WebDriverWait;

import org.testng.annotations.AfterMethod;

import org.testng.annotations.DataProvider;

import org.testng.annotations.Test;
public class Customer {

WebDriver d;

WebDriverWait wait;
@Test(dataProvider="Data")

public void login(String serialNumber) throws InterruptedException

{
d=new FirefoxDriver();

d.get("http://182.71.82.92:88/");

d.manage().window().maximize();

wait=new WebDriverWait(d, 10);

WebElement e = d.findElement(By.xpath(".//*[@id='Repair']/a"));

wait.until(ExpectedConditions.visibilityOf(e)).click();

Thread.sleep(5000);

d.findElement(By.xpath(".//*[@id='home']/div[1]/div[2]/div[1]/span[1]/input[2]")).sendKeys("s");

String g = "CORE ALU LIGHT SERVICE MODULE";

WebElement t = d.findElement(By.xpath(".//*[@id='home']/div[1]/div[2]/div[1]/span[1]/div"));

wait.until(ExpectedConditions.visibilityOf(t));

List<WebElement>li=d.findElements(By.xpath("//div[@class='ProfileCard u-cf Typeahead-suggestion Typeahead-selectable']"));

for(WebElement web:li)

{

if(web.getText().equals(g))

{

System.out.println("Selected value is"+g);

web.click();

break;

}

}

d.findElement(By.xpath(".//*[@id='home']/div[1]/div[2]/div[2]/input[1]")).sendKeys(serialNumber);

d.findElement(By.xpath(".//*[@id='home']/div[1]/div[2]/div[4]/button")).click();

WebElement m= wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//*[@id='WarantyStaus']")));

wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//*[@id='WarantyStaus']/option[3]")));

Select s1=new Select(m);

s1.selectByValue("5");

WebElement m1= wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//*[@id='IssueCategory']")));

Select s = new Select(m1);

Thread.sleep(5000);

s.selectByVisibleText("DM5");

WebElement m2= wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//html/body/section/div[1]/div[6]/div[1]/div/div[1]/div[7]/div[2]/select")));

Select s2 = new Select(m2);

Thread.sleep(5000);

s2.selectByVisibleText("Malfunction");

WebElement m3= wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//html/body/section/div[1]/div[6]/div[1]/div/div[1]/div[7]/div[3]/select")));

Select s3 = new Select(m3);

Thread.sleep(5000);

s3.selectByVisibleText("Import / Export");

Thread.sleep(5000);

d.findElement(By.xpath(".//*[@id='home']/div[1]/div[7]/div[5]/button")).click();

Thread.sleep(5000);

d.findElement(By.xpath(".//*[@id='home']/div[4]/button[2]")).click();

d.findElement(By.xpath(".//*[@id='menu1']/div[1]/div[2]/div[2]/input")).sendKeys("automate");

d.findElement(By.xpath(".//*[@id='menu1']/div[1]/div[2]/div[5]/input")).sendKeys("ticket");

d.findElement(By.xpath(".//*[@id='menu1']/div[1]/div[2]/div[8]/input")).sendKeys("panigrahis@cloudxtension.com");

d.findElement(By.xpath(".//*[@id='menu1']/div[1]/div[2]/div[11]/input")).sendKeys("panigrahis@cloudxtension.com");

d.findElement(By.xpath(".//*[@id='menu1']/div[1]/div[2]/div[14]/input")).sendKeys("9818431585");

d.findElement(By.xpath(".//*[@id='menu1']/div[1]/div[2]/div[17]/textarea")).sendKeys("Oxford, Oxford, Oxfordshire OX1 4AQ, UK");

d.findElement(By.xpath(".//*[@id='menu1']/div[1]/div[2]/div[19]/input")).sendKeys("OX1 4AQ");

d.findElement(By.xpath(".//*[@id='menu1']/div[1]/div[2]/div[22]/input")).sendKeys("Oxford");
WebElement m4= wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//*[@id='Country']")));

Select s4 = new Select(m4);

Thread.sleep(5000);

s4.selectByVisibleText("Finland");

Thread.sleep(5000);

d.findElement(By.xpath(".//*[@id='menu1']/div[1]/div[2]/div[30]/input")).click();

Thread.sleep(5000);

d.findElement(By.xpath(".//*[@id='agree']")).click();

Thread.sleep(5000);

d.findElement(By.xpath(".//*[@id='body']/div[1]/div[12]/button[2]")).click();
}

@AfterMethod

public void close()

{

d.quit();

}
@DataProvider(name="Data")

public Object[][]DataDriven()

{

ExcelLibrary li = new ExcelLibrary("D:\\my workspace\\Suunto\\src\\TestData\\ExcelData.xlsx");

int rows=li.RowCount(0);

Object[][] data2=new Object[rows][0];
for(int i=0;i<rows;i++)

{

data2[i][0]=li.getData(0, i, 0);

System.out.println(data2);
}

return data2;
}
}

snpanigrahi9 Train Asked on December 27, 2015 in Selenium WebDriver.
Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.