지금은 데이터 기반 테스트를 Java로 작성하기위한 자습서를 따르고 있습니다. 내 IDE가 인 IntelliJ 커뮤니티 에디션이고, 다음은 내 코드입니다Apache POI, CREATE_NULL_AS_BLANK이 (가) 오류를 일으키는 경우
package utility;
import config.Constants;
import executionEngine.DriverScript;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.FileInputStream;
import java.io.FileOutputStream;
public class ExcelUtils {
private static XSSFSheet ExcelWSheet;
private static XSSFWorkbook ExcelWBook;
private static XSSFCell Cell;
private static XSSFRow Row;
//This method is to set the File path and to open the Excel File
//Pass Excel Path and Sheet Name as Arguments to this method
public static void setExcelFile(String Path) throws Exception {
try {
FileInputStream ExcelFile = new FileInputStream(Path);
ExcelWBook = new XSSFWorkbook(ExcelFile);
}catch(Exception e){
Log.error("Class Utils | Method setExcelFile | Exception desc: " + e.getMessage());
DriverScript.bResult = false;
}
}
@SuppressWarnings("static-access")
//This method is used to write value in the excel sheet
//This method accepts four arguments (Result, Row Number, Column Number, Sheet Name)
public static void setCellData(String Result, int RowNum, int ColNum, String SheetName) throws Exception{
try{
ExcelWSheet = ExcelWBook.getSheet(SheetName);
Row = ExcelWSheet.getRow(RowNum);
// CHECK IF ERRORS HAPPEN AFTER THIS!!!!!!!!!!!!!!!!
Cell = Row.getCell(ColNum, Row.CREATE_NULL_AS_BLANK);
if(Cell == null){
Cell = Row.createCell(ColNum);
Cell.setCellValue(Result);
}else{
Cell.setCellValue(Result);
}
//Constant variables Test Data path and Test Data file name
FileOutputStream fileOut = new FileOutputStream(Constants.Path_TestData);
ExcelWBook.write(fileOut);
//fielOut.flush();
fileOut.close();
ExcelWBook = new XSSFWorkbook(new FileInputStream(Constants.Path_TestData));
}catch(Exception e){
DriverScript.bResult = false;
}
}
//This method is to read the test data from the Excel cell
//In this we are passing Arguments as Row Num, Col Num & Sheet Name
public static String getCellData(int RowNum, int ColNum, String SheetName) throws Exception{
try{
ExcelWSheet = ExcelWBook.getSheet(SheetName);
Cell = ExcelWSheet.getRow(RowNum).getCell(ColNum);
String CellData = Cell.getStringCellValue();
return CellData;
}catch(Exception e){
Log.error("Class Utils | Method getCellData | Exception desc: " + e.getMessage());
DriverScript.bResult = false;
return "";
}
}
//This method id to get the row count used of the excel sheet
public static int getRowCount(String SheetName){
int iNumber = 0;
try {
ExcelWSheet = ExcelWBook.getSheet(SheetName);
iNumber = ExcelWSheet.getLastRowNum()+1;
}catch(Exception e){
Log.error("Class Utils | Method getRowCount | Exception desc: " + e.getMessage());
DriverScript.bResult = false;
}
return iNumber;
}
//This method is to get the Row number of the test case
//This method takes three arguments(Test Case Name, Column Number & Sheet name)
public static int getRowContains(String sTestCaseName, int colNum, String SheetName) throws Exception{
int iRowNum = 0;
try{
//ExcelWSheet = ExcelWBook.getSheet(SheetName);
int rowCount = ExcelUtils.getRowCount(SheetName);
for(; iRowNum<rowCount; iRowNum++){
if(ExcelUtils.getCellData(iRowNum, colNum, SheetName).equalsIgnoreCase(sTestCaseName)){
break;
}
}
}catch(Exception e){
Log.error("Class Utils | Method getRowContains | Exception desc: " + e.getMessage());
DriverScript.bResult = false;
}
return iRowNum;
}
//This method is to get the count of the test steps of test case
//This method takes three arguments (Sheet name, Test Case ID & Test case row number)
public static int getTestStepsCount(String SheetName, String sTestCaseID, int iTestCaseStart) throws Exception{
try{
for(int i=iTestCaseStart; i<=ExcelUtils.getRowCount(SheetName); i++){
if(!sTestCaseID.equals(ExcelUtils.getCellData(i, Constants.Col_TestCaseID, SheetName))){
int number = i;
return number;
}
}
ExcelWSheet = ExcelWBook.getSheet(SheetName);
int number = ExcelWSheet.getLastRowNum()+1;
return number;
}catch(Exception e){
Log.error("Class Utils | Method getTestStepsCount | Exception desc: " + e.getMessage());
DriverScript.bResult = false;
return 0;
}
}
}
내 문제는 이제 다음 부분입니다 : 내가 지금 무엇을 해야할지하지 않습니다
public static void setCellData(String Result, int RowNum, int ColNum, String SheetName) throws Exception{
try{
ExcelWSheet = ExcelWBook.getSheet(SheetName);
Row = ExcelWSheet.getRow(RowNum);
// CHECK IF ERRORS HAPPEN AFTER THIS!!!!!!!!!!!!!!!!
Cell = Row.getCell(ColNum, Row.CREATE_NULL_AS_BLANK);
은 ... CREATE_NULL_AS_BLANK 빨간색으로 표시되며, "심볼을 해결할 수 없습니다"라고 말하며 데이터 기반 프레임 워크의 모든 단계가 실패했습니다. 내 로그인이
나는 내 코드를 실행할 수있는이 코드org.apache.poi.ss.usermodel.Row.MissingCellPolicy.CREATE_NULL_AS_BLANK;
와 함께 사용하려고하지만 내 프레임 워크는 다음
을 분쇄하기 전에 첫 번째 단계를 수행
2017-10-16 13:19:50,093 INFO [Log] ****************************************************************************************
2017-10-16 13:19:50,093 INFO [Log] ****************************************************************************************
2017-10-16 13:19:50,093 INFO [Log] $$$$$$$$$$$$$$$$$$$$$ Wikipedia_01 $$$$$$$$$$$$$$$$$$$$$$$$$
2017-10-16 13:19:50,093 INFO [Log] ****************************************************************************************
2017-10-16 13:19:50,093 INFO [Log] ****************************************************************************************
2017-10-16 13:19:50,094 ERROR [Log] Class Utils | Method getCellData | Exception desc: null
2017-10-16 13:19:50,094 INFO [Log] Opening Browser
2017-10-16 13:19:53,388 INFO [Log] Closing the browser
2017-10-16 13:19:54,069 INFO [Log] XXXXXXXXXXXXXXXXXXXXXXX -E---N---D- XXXXXXXXXXXXXXXXXXXXXX
2017-10-16 13:19:54,069 INFO [Log] X
2017-10-16 13:19:54,069 INFO [Log] X
2017-10-16 13:19:54,069 INFO [Log] X
2017-10-16 13:19:54,069 INFO [Log] X
누군가가 나를이 문제를 해결하도록 도울 수 있기를 바랍니다.
편집 : "setCellData"부분을 추가하기 전에 프레임 워크가 완전히 작동하고 모든 단계가 완벽하게 실행되었습니다. 그 직후에 오류가 발생합니다
어떤 Apache POI 버전을 사용하고 있습니까? 최신 버전이 아니라면 업그레이드 할 때 어떤 일이 발생합니까? – Gagravarr
내가 사용하는 3.17 ... 그게 어디서 오류가 발생 ... 그럼에도 3.10.1로 다운 그레이드하려고했지만 오류가 여전히 거기에 있었다 – Pawana