SoapUI自动化--Groovy脚本实现随机抽取DataSource(Excel)

def subRow=6 
def startColumn="A" 
def startRow=2 
//以上3个数据,由用户填写,后期实现在testSuite或者testCase的Property中实现取值 
//subRow 总共有多少行数据(不包含表头) 
//startColumn 起始的列名(在Excel中表示为A,B,C,D,E) 
//startRow 表示数据的起始行(在Excel中数据的起始行,有些数据会有表头) 
 
def random=new Random() 
def row=(int)(random.nextFloat()*subRow)+startRow 
def startCell=startColumn+String.valueOf(row) 
//产生随机数,并生成Cell编号 
 
def dataSource=testRunner.testCase.testSteps["DataSource"] 
//com.eviware.soapui.impl.wsdl.teststeps.WsdlDataSourceTestStep 
def excelSource=dataSource.getDataSource() 
//com.eviware.soapui.impl.wsdl.teststeps.datasource.ExcelDataSource 
 
dataSource.setStartRow("0") 
dataSource.setEndRow("0") 
//因为每次只去一条数据,所以开始和结束都为0,即范围为1 
excelSource.setStartCell(startCell) 
//设置读取数据的起始Cell 
//这三句语句的结合,就形成了随机取一行数据的效果 

posted @ 2017-11-28 13:51  春田花花同学会  阅读(366)  评论(0编辑  收藏  举报