【问题标题】:ReadyAPI - parsing an excel data source by columnReadyAPI - 按列解析 excel 数据源
【发布时间】:2020-12-08 08:03:49
【问题描述】:

在 ReadyAPI 中,可以在数据源测试步骤中配置和读取 excel 数据源。但是,这并没有提供按列顺序读取的选项(我可以看到)。

ReadyAPI 中是否有按列顺序(而不是行顺序)读取数据的选项?

如果没有,是否有一个 groovy 库用于 excel/此示例?

【问题讨论】:

  • 我不使用 ReadyAPI,但在 Groovy 中,如果您没有得到答案,您可以使用 Apache POI。

标签: excel groovy ready-api


【解决方案1】:

@MaxRussell 很抱歉成为坏消息的承担者。我让我的客户代表与工程师核实,看看是否有办法改变 ReadyAPI 读取 EXCEL 文件的方向。这是我得到的答案... “我问过,现在他们似乎不知道如何更改 ReadyAPI 读取表格的方式。ReadyAPI 将 Excel 表格视为数据表,将行视为索引,将列视为索引中的数据。”

此答案于 2021 年 9 月中旬返回,并与 ReadyAPI v3.9.2 一起提供。

但是...我已经编写了一些 Groovy 代码,似乎可以做到这一点...

// IMPORT THE LIBRARIES WE NEED

import com.eviware.soapui.support.XmlHolder
import jxl.*
import jxl.write.*

// DECLARE THE VARIABLES

def myTestCase = context.testCase //myTestCase contains the test case
def counter,next,previous,size //Variables used to handle the loop and to move inside the file

Workbook workbook1 = Workbook.getWorkbook(new File("location of excel file.XLS"))  // Had an issue using XLSX, so switched back to XLS

Sheet sheet1 = workbook1.getSheet(0) //Index 0 will read the first sheet from the workbook, you can also specify the sheet name with "Sheet1"
//Sheet sheet1 = workbook1.getSheet("Sheet1")


size = sheet1.getColumns().toInteger()  // Get number of columns with data
length = sheet1.getRows().toInteger()   // get number of rows with data

def fieldArray = new String[length]

propTestStep = myTestCase.getTestStepByName("Properties") // get the Property TestStep object

counter = 1  //counter variable will eventually be the iteration number

next = (counter > size-2? 0: counter+1) //set the next value

// OBTAINING THE DATA from the spreadsheet
int i = 0

while (i < length) {
    Cell f1 = sheet1.getCell(counter,i)
    
    fieldArray[i] = f1.getContents()
    i++
}


workbook1.close() //close the file


// Apply all of the values to the properties in the test case

def numberOfProperties = myTestCase.properties.size()  // get the number of properties
def tempMap = myTestCase.propertyNames as String[];  // put all of the property names into an array

i = 0
while (i < length) {
    myTestCase.setPropertyValue(tempMap[i], fieldArray[i])
    i++
}

请注意,这不是一项已完成的工作,但我正在将 B 列中的 17 个值加载到要用作数据的属性中。这至少应该让你朝着正确的方向前进。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-05-08
    • 1970-01-01
    • 2013-10-30
    • 2015-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多