Arrays SoapUI/Groovy根据数组动态比较JSON响应
我试图将JSON响应中的节点值与从excel电子表格中收集的值进行比较,我为excel电子表格构建了一个数组。数组包含来自多个列的值,但我想看看数组中是否有JSON节点值。最后,我需要将多个节点值与数组进行比较。目前我似乎无法让这项工作只对一个人起作用。我做错了什么Arrays SoapUI/Groovy根据数组动态比较JSON响应,arrays,json,groovy,soapui,Arrays,Json,Groovy,Soapui,我试图将JSON响应中的节点值与从excel电子表格中收集的值进行比较,我为excel电子表格构建了一个数组。数组包含来自多个列的值,但我想看看数组中是否有JSON节点值。最后,我需要将多个节点值与数组进行比较。目前我似乎无法让这项工作只对一个人起作用。我做错了什么 import com.eviware.soapui.*; import java.lang.*; import java.util.*; import java.io.*; import java.net.*; import gro
import com.eviware.soapui.*;
import java.lang.*;
import java.util.*;
import java.io.*;
import java.net.*;
import groovy.lang.*;
import groovy.util.*;
import groovy.json.JsonSlurper;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
//Create an array to hold the cell values
def cellValues = [];
//Get the JSON in a format to easily access
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context);
def ResponseMessage = testRunner.testCase.testSteps["ProductSkuLookupService"].getPropertyValue("response");
def jsonResult = new JsonSlurper().parseText(ResponseMessage);
//Get the number of recommended expressions nodes
def rspnsNumRcmndExprsns = jsonResult.product.recommendedExpressions.size();
//Get the file from the location specified in the test case custom properties
def String dataFilename = context.expand( '${#TestCase#dataFilename}' );
if(dataFilename != null && !dataFilename.equals(""))
{
XSSFWorkbook wb = new XSSFWorkbook(dataFilename);
XSSFSheet sheet = wb.getSheet("exprsnList");
XSSFRow row;
XSSFCell cell;
def totalNumRows;
def numRows;
//Get the total number of rows with data on the sheet
totalNumRows = sheet.getPhysicalNumberOfRows();
//log.info " The total number of rows are " + totalNumRows;
//Get the number of rows without the header row
numRows = totalNumRows - 1;
//log.info " The number of rows to use are " + rows;
def cols = 0;
cols = sheet.getRow(0).getPhysicalNumberOfCells();
//log.info " The total number of columns are " + cols;
if(numRows == rspnsNumRcmndExprsns)
{
for(int i = 1; i < totalNumRows; i++)
{
row = sheet.getRow(i);
//log.info " Row # " + i;
for(int j = 0; j < cols; j++)
{
//log.info " Cell # " + j;
cell = row.getCell(j);
//log.info " The value in the cell is " + cell;
cellValues.push(cell);
}
}
log.info jsonResult.product["recommendedExpressions"]["imageUrl"].every{it in [cellValues]}
}
else
{
assert false, "The number of nodes does not match the number of rows.";
}
}
else
{
assert false, "The file name is missing.";
}
return;
您正在将单元格推送到数组中。我认为您的要求是将单元格内容推送到数组中 取而代之的是:
for(int j = 0; j < cols; j++)
{
//log.info " Cell # " + j;
cell = row.getCell(j);
//log.info " The value in the cell is " + cell;
cellValues.push(cell);
}
for(int j=0;j
使用下面的代码
for(int j = 0; j < cols; j++)
{
//log.info " Cell # " + j;
cell = row.getCell(j);
//log.info " The value in the cell is " + cell;
cellValues.push(cell.getStringCellValue());
}
for(int j=0;j
在Excel中存储响应似乎有点疯狂?实际上没有在Excel中存储响应。。。我的测试数据(验证数据)在excel中提供给我。我把它放到一个数组中。从这里,我想比较响应和数组。数组是什么样子的?上面提供了数组的代码。
for(int j = 0; j < cols; j++)
{
//log.info " Cell # " + j;
cell = row.getCell(j);
//log.info " The value in the cell is " + cell;
cellValues.push(cell.getStringCellValue());
}