I'm new to Java and Selenium, Selenium is quite fun, I'm working on Selenium WebDriver with TestNG Data Driven framework.
by refer to this tutorial http://software-testing-tutorials-automation.blogspot.sg/2014/07/framework-for-selenium-webdriver-report.html#comment-form
there is a Excel Utility where write data to excel with using HSSF
SuiteUtility.WriteResultUtility(FilePath, TestCaseName, "Pass/Fail/Skip", DataSet+1, "PASS");
Instead of hardcode, I'm planning to using Constant file to replace it. eg,
public static final String KEYWORD_PASS = "PASS";
public static final int COL_TEST_CASE_RESULT = 10; // put it in column no 10
so it will be like these and become more manageable
SuiteUtility.WriteResultUtility(FilePath_TestResult, TestCaseName, Constant.COL_TEST_CASE_RESULT, DataSet+1, Constant.KEYWORD_PASS);
My question is how to modify the code below so I can change the String colName to int column number.
public boolean writeResult(String wsName, String colName, int rowNumber, String Result){
try{
int sheetIndex=wb.getSheetIndex(wsName);
if(sheetIndex==-1)
return false;
int colNum = retrieveNoOfCols(wsName);
int colNumber=-1;
HSSFRow Suiterow = ws.getRow(0);
for(int i=0; i<colNum; i++){
if(Suiterow.getCell(i).getStringCellValue().equals(colName.trim())){
colNumber=i;
}
}
if(colNumber==-1){
return false;
}
HSSFRow Row = ws.getRow(rowNumber);
HSSFCell cell = Row.getCell(colNumber);
if (cell == null)
cell = Row.createCell(colNumber);
cell.setCellValue(Result);
opstr = new FileOutputStream(filelocation);
wb.write(opstr);
opstr.close();
}catch(Exception e){
e.printStackTrace();
return false;
}
return true;
}