Setup Menus in Admin Panel

ITeLearn.com

DataDriven Framework-Read Excel Error | Selenium Automation | Discussions | ITeLearn.com

Forum usage guidelines

  1. Search First.: If you don’t find a similar post, start a new topic. If you find a similar thread and still have a question, reply to that topic. Duplicate threads will be ignored/deleted without warning.
  2. Proper Subject: Ensure you choose a very appropriate topic name. Else it will be tough to get support from other members.
  3. Patience, please: Our Tech team or other members will usually try to respond within 24 hours on weekdays and max within 48 hours on weekends. Sometimes sooner.
  4. Share opinions: Please feel free to reply, add or comment on any ongoing topics. Collective learning will be of great benefit to all.

 
ITeLearn reviews from participants.

Please consider registering
guest

Log In

Lost password?
Advanced Search

— Forum Scope —

  

— Match —

   

— Forum Options —

   

Minimum search word length is 4 characters - maximum search word length is 84 characters

Topic RSS
DataDriven Framework-Read Excel Error
April 18, 2017
6:36 pm
Abhinaya Abhinaya
Member
Forum Posts: 6
Member Since:
March 28, 2017
Offline

Please find the below code and advise where I am going wrong.

System prompting the error at the below line saying that “This method must return a result of type String[][]”
“public static String[][] readXL(String fPath, String fSheet) throws Exception{“

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.concurrent.TimeUnit;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class DDF_004{
WebDriver myD;
String vBrowsername,vURL, vEmailID, vActMessage,vExpMessage,vResult;
static int xRows, xCols;
String xlPath,xlSheet,xlPath_Res,xlSheet_Res;
String[][] xlData,xlResults;
static int rowcount;

@Before
public void beforeTest() throws Exception{
//1. Open the browser
System.setProperty(“webdriver.gecko.driver”, “C:\\Users\\home\\Desktop\\abhi\\geckodriver.exe”);
myD=new FirefoxDriver();
myD.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

xlPath=”C:\\Users\\home\\Desktop\\abhi\\selenium topics in order.xls”;
xlSheet=”Testdata_02″;
xlPath_Res =”C:\\Users\\home\\Desktop\\abhi\\selenium topics in order_Results.xls”;
xlSheet_Res=”TestdataResults”;
xlData = readXL(xlPath,xlSheet);
}

@Test
public void myTest()throws InterruptedException{
for(int rowcount=1; rowcount< xRows; rowcount++ ){
vBrowsername=xlData[rowcount][1];
vURL= xlData[rowcount][2];
vEmailID= xlData[rowcount][3];
vExpMessage=xlData[rowcount][4];

}
//2 Go to anyAut
myD.get(vURL);
//Recover Password
recoverPassword(vEmailID);
//6 Verify the message
verifyAlertMessage(vExpMessage);

}

@After
public void afterTest() throws Exception{
// myD.quit();
writeXL( xlPath_Res,xlSheet_Res,xlData);

}
public void verifyAlertMessage(String vExpMsg)throws InterruptedException {
vActMessage=myD.findElement(By.id("hideMe")).getText();
System.out.println("Actual Message is:="+vActMessage);
System.out.println("Expected Message is:="+vExpMsg);
if(vActMessage.equals (vExpMsg)){
xlData[rowcount][5]="vActMessage";

vResult = "Pass";
xlData[rowcount][6]="Pass";

} else {
vResult = "Fail";
xlData[rowcount][6]="Fail";
}
System.out.println("Test case is:=" +vResult);
}
public void recoverPassword(String vEID)throws InterruptedException{
//3 Forgot password
myD.findElement(By.id("forgot_password_link")).click();
//4 Enter the EmailID
myD.findElement(By.id("forgot_email")).clear();
myD.findElement(By.id("forgot_"
+ "email")).sendKeys(vEID);
//5 Click on recover button
myD.findElement(By.name("submit")).click();

}

@SuppressWarnings("unused")
public static String[][] readXL(String fPath, String fSheet) throws Exception{

String[][] xData;

File myxl = new File(fPath);
FileInputStream myStream = new FileInputStream(myxl);
@SuppressWarnings("resource")
HSSFWorkbook myWB = new HSSFWorkbook(myStream);
HSSFSheet mySheet = myWB.getSheet(fSheet);
xRows=mySheet.getLastRowNum()+1;
xCols=mySheet.getRow(0).getLastCellNum();
System.out.println("Total rows:"+xRows);
System.out.println("Total columns:"+xCols);

xData= new String[xRows][xCols];
for (int i=0; i < xRows; i++) {
HSSFRow row=mySheet.getRow(i);
for (int j=0; j<xCols; j++){
HSSFCell cell= row.getCell(j);
String value = "-";
if(cell!=null){
value = cellToString(cell);

xData[i][j]=value;
System.out.println(value);
System.out.println("—-");
}
System.out.println("");
}
myxl=null;
return xData;
}

}

@SuppressWarnings("deprecation")
public static String cellToString(HSSFCell cell) {
// This function helps to convert an object of type excel cell to string value
int type=cell.getCellType();
Object result;
switch (type) {
case HSSFCell.CELL_TYPE_NUMERIC:
result=cell.getNumericCellValue();
break;
case HSSFCell.CELL_TYPE_STRING:
result=cell.getStringCellValue();
break;
case HSSFCell.CELL_TYPE_FORMULA:
throw new RuntimeException("We cant evaluate formulas in Java");
case HSSFCell.CELL_TYPE_BLANK:
result = "%";
break;
case HSSFCell.CELL_TYPE_BOOLEAN:
result=cell.getBooleanCellValue();
break;
case HSSFCell.CELL_TYPE_ERROR:
throw new RuntimeException("This cell has an error");

default:
throw new RuntimeException("Wedon’t support this cell type:" +type);
}
return result.toString();
}

@SuppressWarnings("deprecation")
public static void writeXL(String fPath, String fSheet,String[][] xData) throws Exception{

File outFile = new File(fPath);
@SuppressWarnings("resource")
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet osheet = wb.createSheet(fSheet);
int xR_TS = xData.length;
int xC_TS = xData[0].length;
for(int myrow=0;myrow<xR_TS;myrow++){
HSSFRow row=osheet.createRow(myrow);
for(int mycol=0; mycol<xC_TS; mycol++){
HSSFCell cell = row.createCell(mycol);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue(xData[myrow][mycol]);
}

FileOutputStream fOut = new FileOutputStream(outFile);
wb.write(fOut);
fOut.flush();
fOut.close();

}
}}

April 19, 2017
9:38 am
Techhelp
Member
Forum Posts: 1889
Member Since:
October 26, 2012
Offline

public static String[][] readXL(String sPath, String iSheet) throws Exception{
String[][] xData;

File myxl = new File(sPath);
FileInputStream myStream = new FileInputStream(myxl);
HSSFWorkbook myWB = new HSSFWorkbook(myStream);
HSSFSheet mySheet = myWB.getSheet(iSheet);
xRows = mySheet.getLastRowNum()+1;
xCols = mySheet.getRow(0).getLastCellNum();
xData = new String[xRows][xCols];
for (int i = 0; i < xRows; i++) {
HSSFRow row = mySheet.getRow(i);
for (int j = 0; j < xCols; j++) {
HSSFCell cell = row.getCell(j);
String value = cellToString(cell);
xData[i][j] = value;
System.out.print(value);
System.out.print("####");
}
System.out.println("");
}
myWB.close();
return xData;
}

Forum Timezone: UTC -8

Most Users Ever Online: 70

Currently Online: Syed Gillani
7 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

Techhelp: 1889

Manu: 114

Shan Nathan: 80

Palanki sai charan: 67

Userone: 59

Vishal Anand: 53

Archana Sapre: 51

Geetha Reddy: 44

useL: 38

Priyanka Perumalla: 36

Member Stats:

Guest Posters: 19

Members: 7846

Moderators: 0

Admins: 1

Forum Stats:

Groups: 1

Forums: 22

Topics: 2064

Posts: 5695

Newest Members: Syed Gillani, Naga Venkata Yerramsetti, Amulya Rajendran, kiran pujar, Anupama Odnala, Hitesh Shah, Jaya Vysyaraju, Md Payel Miah, Ashwini Yerra, Jennifer Manual

Administrators: Karthik eLearn (Admin): 49

0 Responses on Discussions"

Main Menu