Я создал сценарий с ключевым словом groovy (в Katalon), чтобы использовать POI XSSF для чтения файла Excel.
, но с ошибкой "Нет такого свойства: CellType для класса: excel. readexcel "при запуске тестового примера.
Я не уверен, является ли это проблемой библиотеки POI, или я использую неправильный синтаксис?
это groovy
package excel
import java.io.IOException
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import com.kms.katalon.core.annotation.Keyword
public class readexcel {
@Keyword
def post(String name) throws IOException{
try {
//FileInputStream excelFile = new FileInputStream(new File(FILE_NAME));
FileInputStream fis = new FileInputStream("C:\\JY\\testmatrix.xlsx");
Workbook workbook = new XSSFWorkbook(fis);
Sheet datatypeSheet = workbook.getSheetAt(0);
Iterator<Row> iterator = datatypeSheet.iterator();
while (iterator.hasNext()) {
Row currentRow = iterator.next();
Iterator<Cell> cellIterator = currentRow.iterator();
while (cellIterator.hasNext()) {
Cell currentCell = cellIterator.next();
//getCellTypeEnum shown as deprecated for version 3.15
//getCellTypeEnum ill be renamed to getCellType starting from version 4.0
if (currentCell.getCellType() == Cell.CELL_TYPE_STRING) {
System.out.print(currentCell.getStringCellValue() + "--");
} else if (currentCell.getCellType() == CellType.NUMERIC) {
System.out.print(currentCell.getNumericCellValue() + "--");
}
}
System.out.println();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Это тестовый сценарий для вызова ключевого слова и распечатки результата для проверки успешного чтения.
import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import internal.GlobalVariable as GlobalVariable
def result = CustomKeywords.'excel.readexcel.post'('')
println(result)
Ошибка
2020-02-04 15:15:14.758 DEBUG testcase.try - 1: result = excel.readexcel.post("")
Version--Description--Date--
1.0--Test matrix for collection of test data and summary of test cases for Drug Service.--2020-02-04 15:15:16.044 ERROR k.k.c.m.CustomKeywordDelegatingMetaClass - ❌ No such property: CellType for class: excel.readexcel
2020-02-04 15:15:16.046 ERROR c.k.katalon.core.main.TestCaseExecutor - ❌ Test Cases/try FAILED.
Reason:
groovy.lang.MissingPropertyException: No such property: CellType for class: excel.readexcel
at excel.readexcel.post(readexcel.groovy:42)
at excel.readexcel.invokeMethod(readexcel.groovy)
at com.kms.katalon.core.main.CustomKeywordDelegatingMetaClass.invokeStaticMethod(CustomKeywordDelegatingMetaClass.java:50)
at try.run(try:16)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:337)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:105)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1580800511604.run(TempTestCase1580800511604.groovy:21)