问题在于使用groovy脚本将excel表格中的值替换为soap请求 [英] Issue in replacing the values from excel sheet into soap request using groovy script

查看:140
本文介绍了问题在于使用groovy脚本将excel表格中的值替换为soap请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从excel表单传递给soap请求中的特定字段的值在测试用例级别中不起作用。我能够读取Excel表单,并且执行过程如预期的那样进行,但值不会在Excel表单中的肥皂请求中被替换。
我粘贴了下面的代码,我尝试使用groovy脚本来驱动数据。

  import com。 eviware.soapui.support.XmlHolder 
import java.io.File;
import java.io.IOException;
导入jxl。*;
导入jxl.read.biff.BiffException;
导入jxl.write。*;
log.info(Testing Started)
def reqOperationName =getInsuranceDetails_1_FTC_005;
def inputDataFileName =D:/ SOAP UI Pro / MPI.xls
def inputDataSheetName =MPI
Workbook workbook = Workbook.getWorkbook(new File(inputDataFileName));
WritableWorkbook copy = Workbook.createWorkbook(new File(inputDataFileName),workbook);
WritableSheet sheet1 = copy.getSheet(inputDataSheetName);
log.info(Testing1 Started)
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
String xmlResponse ='$ {'+ reqOperationName +'#Request '+'}'
def reqholder = groovyUtils.getXmlHolder(context.expand(xmlResponse))
try {
rowcount = sheet1.getRows();
colcount = sheet1.getColumns();
for(Row in 1..rowcount-1){

String reqTagName = sheet1.getCell(0,0).getContents()
log.info reqTagName $ b $ (tagCount!= 0){
字符串reqTagValue = sheet1.getCell(0,Row).getContents() )
reqholder.setNodeValue(// *:+ reqTagName,reqTagValue)
reqholder.updateProperty()
}

//测试请求
testRunner.runTestStepByName(reqOperationName)
log.info(Testing3 Started)
def resholder = groovyUtils.getXmlHolder(reqOperationName +#Response)
resTagValue1 = resholder.getNodeValues(// *:productID)
resTagValue2 = resholder.getNodeValues(// *:accountNumber)
resTagValue3 = resholder.getNodeValues(// *:insuranceCategory)
resTagValue4 = resholder.getNodeValues (// *:imei)
resTagValue5 = resholder.getNodeValues(// *:handsetMake)
resTagValue6 = reshol der.getNodeValues(// *:handsetModel)
resTagValue7 = resholder.getNodeValues(// *:insurancePolicyName)
resTagValue8 = resholder.getNodeValues(// *:insuranceStartTimestamp)
//将响应写入Excel工作表
Label resValue1 = new Label(4,Row,resTagValue1);
sheet1.addCell(resValue1);
标签resValue2 =新标签(5,行,resTagValue2);
sheet1.addCell(resValue2);
标签resValue3 =新标签(6,行,resTagValue3);
sheet1.addCell(resValue3);
标签resValue4 =新标签(7,行,resTagValue4);
sheet1.addCell(resValue4);
标签resValue5 =新标签(8,行,resTagValue5);
sheet1.addCell(resValue5);
标签resValue6 =新标签(9,行,resTagValue6);
sheet1.addCell(resValue6);
标签resValue7 =新标签(10,行,resTagValue7);
sheet1.addCell(resValue7);
标签resValue8 =新标签(11,行,resTagValue8);
sheet1.addCell(resValue8);

catch(Exception e){log.info(e)}
finally {
copy.write();
copy.close();
workbook.close();

log.info(Testing Over)

当我尝试要执行上面的代码,错误日志中没有任何错误。我在日志输出中遇到的唯一情况是: Wed Dec 06 15:04:00 IST 2017:INFO:groovy.lang.GroovyRuntimeException:找不到匹配的构造函数:jxl.write.Label(java.lang。 Integer,java.lang.Integer,[Ljava.lang.String;)



对上述问题的任何帮助将非常感谢。



预先感谢您。

新的代码编辑....

  import com.eviware.soapui.support.XmlHolder 
import java.io.File;
import java.io.IOException;
导入jxl。*;
导入jxl.read.biff.BiffException;
导入jxl.write。*;
log.info(Testing Started)
def reqOperationName =getInsuranceDetails_1_FTC_005;
def inputDataFileName =D:/ SOAP UI Pro / MPI.xls
def inputDataSheetName =MPI
Workbook workbook = Workbook.getWorkbook(new File(inputDataFileName));
WritableWorkbook copy = Workbook.createWorkbook(new File(inputDataFileName),workbook);
WritableSheet sheet1 = copy.getSheet(inputDataSheetName);
log.info(Testing1 Started)
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
String xmlResponse ='$ {'+ reqOperationName +'#Request '+'}'
def reqholder = groovyUtils.getXmlHolder(context.expand(xmlResponse))
try {
rowcount = sheet1.getRows();
colcount = sheet1.getColumns();
for(Row in 1..rowcount-1){

String reqTagName = sheet1.getCell(0,0).getContents()
log.info reqTagName $ b $ (tagCount!= 0){
字符串reqTagValue = sheet1.getCell(0,Row).getContents() )
reqholder.setNodeValue(// *:+ reqTagName,reqTagValue)
reqholder.updateProperty()
}

//测试请求
testRunner.runTestStepByName(reqOperationName)
log.info(Testing3 Started)
def resholder = groovyUtils.getXmlHolder(reqOperationName +#Response)
resTagValue1 = resholder.getNodeValue(// *:productID)
resTagValue2 = resholder.getNodeValue(// *:accountNumber)
resTagValue3 = resholder.getNodeValue(// *:insuranceCategory)
resTagValue4 = resholder.getNodeValue (// *:imei)
resTagValue5 = resholder.getNodeValue(// *:handsetMake)
resTagValue6 = resholder.g etNodeValue(// *:handsetModel)
resTagValue7 = resholder.getNodeValue(// *:insurancePolicyName)
resTagValue8 = resholder.getNodeValue(// *:insuranceStartTimestamp)
//将响应写入Excel工作表
Label resValue1 = new Label(2,Row,resTagValue1);
sheet1.addCell(resValue1);
标签resValue2 =新标签(3,行,resTagValue2);
sheet1.addCell(resValue2);
标签resValue3 =新标签(4,行,resTagValue3);
sheet1.addCell(resValue3);
标签resValue4 =新标签(5,行,resTagValue4);
sheet1.addCell(resValue4);
标签resValue5 =新标签(6,行,resTagValue5);
sheet1.addCell(resValue5);
标签resValue6 =新标签(7,行,resTagValue6);
sheet1.addCell(resValue6);
标签resValue7 =新标签(8,行,resTagValue7);
sheet1.addCell(resValue7);
标签resValue8 =新标签(9,行,resTagValue8);
sheet1.addCell(resValue8);

catch(Exception e){log.info(e)}
finally {
copy.write();
copy.close();
workbook.close();

log.info(Testing Over)


解决方案

请尝试下面的代码。它会解决你的问题:

  import com.eviware.soapui.support.XmlHolder 
import java.io.File ;
import java.io.IOException;
导入jxl。*;
导入jxl.read.biff.BiffException;
导入jxl.write。*;
log.info(Testing Started)
def reqOperationName =一些服务
def inputDataFileName =D:/sample/temp8.xls
def inputDataSheetName =Sheet1
Workbook workbook = Workbook.getWorkbook(new File(inputDataFileName));
WritableWorkbook copy = Workbook.createWorkbook(new File(inputDataFileName),workbook);
WritableSheet sheet1 = copy.getSheet(inputDataSheetName);
log.info(Testing1 Started)
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
String xmlResponse = reqOperationName +#Request
def reqholder = groovyUtils.getXmlHolder(xmlResponse)
try {
rowcount = sheet1.getRows();
colcount = sheet1.getColumns();
$ b $ for(Row in 1..rowcount-1){
String reqTagName = sheet1.getCell(0,0).getContents()
def TagCount = reqholder [count (// *:+ reqTagName +)]
if(TagCount!= 0){
String reqTagValue = sheet1.getCell(0,Row).getContents()
$ b $如果(reqTagValue!= null&&!reqTagValue.isEmpty()&& reqTagValue!=)
{

reqholder = groovyUtils.getXmlHolder(xmlResponse)
reqholder.setNodeValue(// *:+ reqTagName,reqTagValue)
reqholder.updateProperty()
testRunner.runTestStepByName(reqOperationName)
$ b $ def resholder = groovyUtils.getXmlHolder (reqOperationName +#Response)

resTagValue1 = resholder.getNodeValue(// *:email)

//将响应写入Excel工作表
标签resValue1 =新标签(2,行,resTagValue1);
sheet1.addCell(resValue1);
}
}


$ b}
} catch(Exception e){log.info(e)}
finally {
copy.write();
copy.close();
workbook.close();
}
log.info(Testing Over)


The values which I try to pass from the excel sheet to the particular field in the soap request are not working in the test case level. I am able to read the excel sheet and also the execution is happening as expected but the values are not replaced in the soap request from the excel sheet. I have pasted the code below which I am trying to implement for data driven using groovy script.

import com.eviware.soapui.support.XmlHolder
import java.io.File;
import java.io.IOException;
import jxl.*;
import jxl.read.biff.BiffException;
import jxl.write.*;
log.info("Testing Started")
def reqOperationName = "getInsuranceDetails_1_FTC_005";
def inputDataFileName = "D:/SOAP UI Pro/MPI.xls"
def inputDataSheetName = "MPI"
Workbook workbook = Workbook.getWorkbook(new File(inputDataFileName));
WritableWorkbook copy = Workbook.createWorkbook(new File(inputDataFileName),workbook);
WritableSheet sheet1 = copy.getSheet(inputDataSheetName);
log.info("Testing1 Started")
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
String xmlResponse = '${' + reqOperationName + '#Request' +'}'
def reqholder = groovyUtils.getXmlHolder(context.expand(xmlResponse))
try{
    rowcount = sheet1.getRows();
colcount = sheet1.getColumns();
for(Row in 1..rowcount-1){

    String reqTagName = sheet1.getCell(0,0).getContents()
        log.info reqTagName
        def TagCount = reqholder["count(//*:"+reqTagName+")"]
        if(TagCount!=0){
            String reqTagValue = sheet1.getCell(0,Row).getContents()
            reqholder.setNodeValue("//*:"+reqTagName, reqTagValue)
            reqholder.updateProperty()                              
        }

    //test the request
    testRunner.runTestStepByName(reqOperationName)
log.info("Testing3 Started")
def resholder = groovyUtils.getXmlHolder(reqOperationName+"#Response")
resTagValue1= resholder.getNodeValues("//*:productID")
resTagValue2= resholder.getNodeValues("//*:accountNumber")
resTagValue3= resholder.getNodeValues("//*:insuranceCategory")
resTagValue4= resholder.getNodeValues("//*:imei")
resTagValue5= resholder.getNodeValues("//*:handsetMake")
resTagValue6= resholder.getNodeValues("//*:handsetModel")
resTagValue7= resholder.getNodeValues("//*:insurancePolicyName")
resTagValue8= resholder.getNodeValues("//*:insuranceStartTimestamp")        
//Write Response into excel sheet
Label resValue1= new Label(4,Row,resTagValue1);
sheet1.addCell(resValue1);   
Label resValue2= new Label(5,Row,resTagValue2);
sheet1.addCell(resValue2);
Label resValue3= new Label(6,Row,resTagValue3);
sheet1.addCell(resValue3);
Label resValue4= new Label(7,Row,resTagValue4);
sheet1.addCell(resValue4);
Label resValue5= new Label(8,Row,resTagValue5);
sheet1.addCell(resValue5);
Label resValue6= new Label(9,Row,resTagValue6);
sheet1.addCell(resValue6);
Label resValue7= new Label(10,Row,resTagValue7);
sheet1.addCell(resValue7);
Label resValue8= new Label(11,Row,resTagValue8);
sheet1.addCell(resValue8);      
    }   
}catch (Exception e) {log.info(e)}
finally{
    copy.write();
    copy.close();
    workbook.close();
}
log.info("Testing Over")

While I try to execute the above code there are no any errors in the error log. The only thing I am getting in the log output is Wed Dec 06 15:04:00 IST 2017:INFO:groovy.lang.GroovyRuntimeException: Could not find matching constructor for: jxl.write.Label(java.lang.Integer, java.lang.Integer, [Ljava.lang.String;)

Any help on the above issue would be very grateful..

Thank you in advance.

New Edit of the code....

import com.eviware.soapui.support.XmlHolder
import java.io.File;
import java.io.IOException;
import jxl.*;
import jxl.read.biff.BiffException;
import jxl.write.*;
log.info("Testing Started")
def reqOperationName = "getInsuranceDetails_1_FTC_005";
def inputDataFileName = "D:/SOAP UI Pro/MPI.xls"
def inputDataSheetName = "MPI"
Workbook workbook = Workbook.getWorkbook(new File(inputDataFileName));
WritableWorkbook copy = Workbook.createWorkbook(new File(inputDataFileName),workbook);
WritableSheet sheet1 = copy.getSheet(inputDataSheetName);
log.info("Testing1 Started")
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
String xmlResponse = '${' + reqOperationName + '#Request' +'}'
def reqholder = groovyUtils.getXmlHolder(context.expand(xmlResponse))
try{
    rowcount = sheet1.getRows();
colcount = sheet1.getColumns();
for(Row in 1..rowcount-1){

    String reqTagName = sheet1.getCell(0,0).getContents()
        log.info reqTagName
        def TagCount = reqholder["count(//*:"+reqTagName+")"]
        if(TagCount!=0){
            String reqTagValue = sheet1.getCell(0,Row).getContents()
            reqholder.setNodeValue("//*:"+reqTagName, reqTagValue)
            reqholder.updateProperty()                              
        }

    //test the request
    testRunner.runTestStepByName(reqOperationName)
log.info("Testing3 Started")
def resholder = groovyUtils.getXmlHolder(reqOperationName+"#Response")
resTagValue1= resholder.getNodeValue("//*:productID")
resTagValue2= resholder.getNodeValue("//*:accountNumber")
resTagValue3= resholder.getNodeValue("//*:insuranceCategory")
resTagValue4= resholder.getNodeValue("//*:imei")
resTagValue5= resholder.getNodeValue("//*:handsetMake")
resTagValue6= resholder.getNodeValue("//*:handsetModel")
resTagValue7= resholder.getNodeValue("//*:insurancePolicyName")
resTagValue8= resholder.getNodeValue("//*:insuranceStartTimestamp")        
//Write Response into excel sheet
Label resValue1= new Label(2,Row,resTagValue1);
sheet1.addCell(resValue1);   
Label resValue2= new Label(3,Row,resTagValue2);
sheet1.addCell(resValue2);
Label resValue3= new Label(4,Row,resTagValue3);
sheet1.addCell(resValue3);
Label resValue4= new Label(5,Row,resTagValue4);
sheet1.addCell(resValue4);
Label resValue5= new Label(6,Row,resTagValue5);
sheet1.addCell(resValue5);
Label resValue6= new Label(7,Row,resTagValue6);
sheet1.addCell(resValue6);
Label resValue7= new Label(8,Row,resTagValue7);
sheet1.addCell(resValue7);
Label resValue8= new Label(9,Row,resTagValue8);
sheet1.addCell(resValue8);      
    }   
}catch (Exception e) {log.info(e)}
finally{
    copy.write();
    copy.close();
    workbook.close();
}
log.info("Testing Over")

解决方案

Try the below code. It will fix your issue :

import com.eviware.soapui.support.XmlHolder
import java.io.File;
import java.io.IOException;
import jxl.*;
import jxl.read.biff.BiffException;
import jxl.write.*;
log.info("Testing Started")
def reqOperationName = "some service"
def inputDataFileName = "D:/sample/temp8.xls"
def inputDataSheetName = "Sheet1"
Workbook workbook = Workbook.getWorkbook(new File(inputDataFileName));
WritableWorkbook copy = Workbook.createWorkbook(new File(inputDataFileName),workbook);
WritableSheet sheet1 = copy.getSheet(inputDataSheetName);
log.info("Testing1 Started")
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
String xmlResponse = reqOperationName+"#Request"
def reqholder = groovyUtils.getXmlHolder(xmlResponse)
try{
    rowcount = sheet1.getRows();
    colcount = sheet1.getColumns();

for(Row in 1..rowcount-1){
       String reqTagName = sheet1.getCell(0,0).getContents()
        def TagCount = reqholder["count(//*:"+reqTagName+")"]
        if(TagCount!=0){
        String reqTagValue = sheet1.getCell(0,Row).getContents()

            if(reqTagValue!=null && !reqTagValue.isEmpty() && reqTagValue!="")
                {

                    reqholder = groovyUtils.getXmlHolder(xmlResponse)
                    reqholder.setNodeValue("//*:"+reqTagName, reqTagValue)
                 reqholder.updateProperty()    
                testRunner.runTestStepByName(reqOperationName)

                def resholder = groovyUtils.getXmlHolder(reqOperationName+"#Response")

                resTagValue1= resholder.getNodeValue("//*:email") 

                //Write Response into excel sheet
                Label resValue1= new Label(2,Row,resTagValue1);
                sheet1.addCell(resValue1);  
                }
            }



    }   
}catch (Exception e) {log.info(e)}
finally{
    copy.write();
    copy.close();
    workbook.close();
}
log.info("Testing Over")

这篇关于问题在于使用groovy脚本将excel表格中的值替换为soap请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆