使用Groovy脚本的数据驱动测试
我使用下面的代码将属性值从Excel文件设置到我的属性步骤,然后将其传递到testcase 当我运行Groovy代码时,excel最后一个单元格中的值进入属性步骤 请帮助我正确设置属性使用Groovy脚本的数据驱动测试,groovy,Groovy,我使用下面的代码将属性值从Excel文件设置到我的属性步骤,然后将其传递到testcase 当我运行Groovy代码时,excel最后一个单元格中的值进入属性步骤 请帮助我正确设置属性 import jxl.* Workbook wb = Workbook.getWorkbook(new File("C:\\Users\\naraysa1\\Desktop\\Address_Doctor\\DataSource_Address_Validate\\Data_AddressValidate.xl
import jxl.*
Workbook wb = Workbook.getWorkbook(new File("C:\\Users\\naraysa1\\Desktop\\Address_Doctor\\DataSource_Address_Validate\\Data_AddressValidate.xls"))
Sheet sh = wb.getSheet(0)
RowCount = sh.getRows();
ColumnCount = sh.getColumns();
for (i=1;i<RowCount;i++)
{
for (j=0;j<ColumnCount;j++)
{
def c = sh.getCell(j, i).getContents();
log.info c
testRunner.testCase.getTestStepByName("Properties_Address").setPropertyValue("ID", c)
testRunner.testCase.getTestStepByName("Properties_Address").setPropertyValue("AddressLine1", c)
testRunner.testCase.getTestStepByName("Properties_Address").setPropertyValue("AddressLine2", c)
testRunner.testCase.getTestStepByName("Properties_Address").setPropertyValue("AddressLine3", c)
testRunner.testCase.getTestStepByName("Properties_Address").setPropertyValue("City", c)
testRunner.testCase.getTestStepByName("Properties_Address").setPropertyValue("State ", c)
testRunner.testCase.getTestStepByName("Properties_Address").setPropertyValue("PostalCode", c)
testRunner.testCase.getTestStepByName("Properties_Address").setPropertyValue("Country", c)
def TestStep = testRunner.runTestStepByName("Search_Address")
}
}
导入jxl*
工作簿wb=Workbook.getWorkbook(新文件(“C:\\Users\\naraysa1\\Desktop\\Address\u Doctor\\DataSource\u Address\u Validate\\Data\u AddressValidate.xls”))
Sheet sh=wb.getSheet(0)
RowCount=sh.getRows();
ColumnCount=sh.getColumns();
对于(i=1;i,在脚本中,将excel的每个单元格中的值分配到所有属性中,并对每个单元格执行teststep
您可能希望将一行中的单元格值映射到不同的属性,并对每行执行测试
定义以下映射
(您可以从excel表格的零行初始化此映射)
现在,您的周期将如下所示:
for (i=1;i<RowCount;i++)
{
for (j=0;j<ColumnCount;j++)
{
def pname = header[j]
if(pname){
def c = sh.getCell(j, i).getContents();
testRunner.testCase.getTestStepByName("Properties_Address").setPropertyValue(pname, c)
}
}
def TestStep = testRunner.runTestStepByName("Search_Address")
}
(i=1;i)的
for (i=1;i<RowCount;i++)
{
for (j=0;j<ColumnCount;j++)
{
def pname = header[j]
if(pname){
def c = sh.getCell(j, i).getContents();
testRunner.testCase.getTestStepByName("Properties_Address").setPropertyValue(pname, c)
}
}
def TestStep = testRunner.runTestStepByName("Search_Address")
}