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请求。我怎么能这样做?
答案 0 :(得分:0)
这应该让你开始。我使用OpenCSV将数据读入List
个bean,然后遍历列表并调用一个包含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。