SOAPUI Groovy脚本,用于读取CSV并分配给属性
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SOAPUI Groovy脚本,用于读取CSV并分配给属性相关的知识,希望对你有一定的参考价值。
CSV结构和内容:
ClientRef,Status,Type,Service
107547,NEW,Inspection,Pest
107321,ALL,WorkOrder,Pest
107443,UPDATED,Collection,Bin
107291,ALL,Delivery,Bin
107411,ALL,Abandoned,Env
107189,NEW,Food,Env
107219,NEW,Protection,Env
我为ClientRef
,Status
,Type
和Service
设置了SOAPUI属性,但是需要将CSV文件中的内容填充到上面的属性中以提交SOAP请求。我怎样才能做到这一点?
答案
这应该让你开始。我使用OpenCSV将数据读入bean的List
,然后遍历列表并调用包含SOAP请求的测试用例。
import com.opencsv.bean.CsvBindByName
import com.opencsv.bean.CsvToBeanBuilder
public class RequestBean {
@CsvBindByName(column = "ClientRef", required = true)
private String clientRef;
@CsvBindByName(column = "Status", required = true)
private String status;
@CsvBindByName(column = "Type", required = true)
private String type;
@CsvBindByName(column = "Service", required = true)
private String service;
public String getClientRef() {
return clientRef;
}
public void setClientRef(String clientRef) {
this.clientRef = clientRef;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getService() {
return service;
}
public void setService(String service) {
this.service = service;
}
}
// Read the CSV values into a bean
List<RequestBean> beans = new CsvToBeanBuilder(new FileReader("/path-to/RequestDataFile.csv"))
.withType(RequestBean.class)
.build()
.parse()
// Iterate through the bean, setting project-level properties and execute a test case.
beans.each {
testRunner.testCase.testSuite.project.setPropertyValue( "ClientRef", it.clientRef )
testRunner.testCase.testSuite.project.setPropertyValue( "Status", it.status )
testRunner.testCase.testSuite.project.setPropertyValue( "Type", it.type )
testRunner.testCase.testSuite.project.setPropertyValue( "Service", it.service )
// Execute the test case
//def testCase = testRunner.testCase.testSuite.project.getTestSuiteByName("TestSuite").getTestCaseByName("TestCase")
//def properties = new com.eviware.soapui.support.types.StringToObjectMap ()
//testCase.run(properties, false)
}
您需要通过Groovy查看soapUI documentation for more about setting properties并解析OpenCSV等外部JAR。
以上是关于SOAPUI Groovy脚本,用于读取CSV并分配给属性的主要内容,如果未能解决你的问题,请参考以下文章
soapUI groovy脚本groovy.lang.MissingMethodException