Groovy-MissingPropertyException-没有此类属性

时间:2019-03-21 18:27:13

标签: groovy soapui

下面是我在SOAP UI中编写的Groovy脚本,当我执行以下代码时,将读取excel中的第一个值并将其存储在属性选项卡中

来源

import com.eviware.soapui.support.XmlHolder
import java.io.File
import java.io.IOException
import jxl.*
import jxl.read.biff.BiffException;
import jxl.write.*

log.info("Started")
def myTestCase = context.testCase
def reqOperationName = "Add";
def source = "D:\\Automation\\SourceRD.xls";
def inputDataSheetName = "Input";

Workbook workbook = Workbook.getWorkbook(new File(source));
WritableWorkbook copy = Workbook.createWorkbook(new File(source), workbook);
WritableSheet sheet1 = copy.getSheet(inputDataSheetName);

def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def reqholder = groovyUtils.getXmlHolder(reqOperationName + "#Request")
try {
    rowcount = sheet1.getRows();
    size = rowcount.toInteger()
    propTestStep = myTestCase.getTestStepByName("Properties")
    propTestStep.setPropertyValue("Total", size.toString())
    colcount = sheet1.getColumns();
    rowcount=2;
    for (Row in 0..rowcount - 1) {
        for (Col in 0..colcount - 1 ) {
            String reqTagName = sheet1.getCell(Col,0).getContents()
        String reqTagValue = sheet1.getCell(Col,Row).getContents()
            propTestStep = myTestCase.getTestStepByName("Properties")
            propTestStep.setPropertyValue(reqTagName, reqTagValue)
        }
    }

} catch (Exception e) {
    log.info(e)
} finally {
    copy.write();
    copy.close();
    workbook.close();
}
log.info("Success")

以下是我循环的groovy脚本

def myTestCase = context.testCase
def runner

testRunner.gotoStepByName("Source")

如何通过修改源代码来迭代Excel中的下一行?可能要操纵rowCount和总行数吗?

1 个答案:

答案 0 :(得分:0)

您的变量名是sheetl(带有L),并且您的代码使用的是sheet1(带有1)。