用于读取CSV并分配给属性的SOAPUI Groovy脚本
CSV结构和内容:用于读取CSV并分配给属性的SOAPUI Groovy脚本,csv,properties,soapui,Csv,Properties,Soapui,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和Servi
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请求。我该怎么做呢?这应该可以让你开始了。我曾经将数据读入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)
}
import com.opencsv.bean.CsvBindByName
导入com.opencsv.bean.CsvToBeanBuilder
公共类请求bean{
@CsvBindByName(column=“ClientRef”,必需=true)
私有字符串clientRef;
@CsvBindByName(column=“Status”,required=true)
私有字符串状态;
@CsvBindByName(column=“Type”,必需=true)
私有字符串类型;
@CsvBindByName(column=“Service”,required=true)
专用字符串服务;
公共字符串getClientRef(){
返回clientRef;
}
公共void setClientRef(字符串clientRef){
this.clientRef=clientRef;
}
公共字符串getStatus(){
返回状态;
}
公共无效设置状态(字符串状态){
这个状态=状态;
}
公共字符串getType(){
返回类型;
}
公共void集合类型(字符串类型){
this.type=type;
}
公共字符串getService(){
回程服务;
}
公共无效设置服务(字符串服务){
服务=服务;
}
}
//将CSV值读入bean
List bean=new CsvToBeanBuilder(新文件读取器(“/path to/RequestDataFile.csv”))
.withType(RequestBean.class)
.build()
.parse()
//迭代bean,设置项目级属性并执行测试用例。
豆子,每个{
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(“服务”,it.Service)
//执行测试用例
//def testCase=testRunner.testCase.testSuite.project.getTestSuiteByName(“testSuite”).getTestCaseByName(“testCase”)
//def properties=new com.eviware.soapui.support.types.StringToObject映射()
//testCase.run(属性,false)
}
您需要通过Groovy和解析外部JAR(如OpenCSV)来了解CSV。好的,我们看到了CSV。如果您需要帮助,请提供您的代码。您是否正在使用
ReadyAPI
?干杯,Craig,绝对是一个很好的帮助-非常感谢!您好,我已经下载了OPENCSV 3.9 Jar文件并将其放在bin\ext中,但由于我遇到了多个错误,所以一定是缺少了一些东西-TestCase失败[org.codehaus.groovy.control.multipleCompilementErrorSexception:启动失败:Script1.groovy:9:意外标记:beans@line 9,column 1.beans.each{^org.codehaus.groovy.syntax.SyntaxException:意外标记:beans@line 9,column 1.at org.codehaus.groovy.antlr.antlparserplugin.transformcstinoast(antlrpserplugin.java:140)at org.codehaus.groovy.antlr.antlrpserplugin.parserplugin(antlrplugin.java:108)CSV-to-bean功能需要4.1版。下载的4.1版(谢谢)中提供了该功能,但仍然存在相同的错误-我是否需要在SOAPUI中的任何其他位置声明OPENCSV-运行v5.3.0看起来是“beans.each”语句-//遍历bean,设置项目级别//属性并执行测试用例。beans.each{