使用 SOAPUI 在多个测试用例中循环测试步骤

Loop test steps in multiple test cases using SOAPUI

我在自动化 Web 服务时遇到了一些问题。

实际上我有一个 excel sheet 包含所有需要的输入和输出。

我写了一个 groovy 脚本来检索输入,将它们保存在属性中,执行查询,检索输出并将它们与 excel 输出进行比较。

我的问题是所有流程都作为一个测试用例执行。

我想 "pimp" 我的流程,以便我的 Excel sheet 的每一行都作为测试用例处理。

这是 groovy 代码:

import jxl.*
import jxl.write.*

Workbook workbook1 = Workbook.getWorkbook(new File("C:\Users\****\Desktop\GroovyPSSheet.xls"))
Sheet sheet1 = workbook1.getSheet(0)

for (int i=6; i<sheet1.getRows(); i++)
    {
        sleep 1000
        if (sheet1.getCell(0,i).getContents()=="")
        {
            i++
        }
        Cell clairance = sheet1.getCell(3,i)
        Cell etatpatho = sheet1.getCell(2,i)
        Cell idlReq = sheet1.getCell(1,i)
        Cell idprod = sheet1.getCell(0,i)
        Cell typeprod = sheet1.getCell(4,i)
        testRunner.testCase.setPropertyValue( "clairance", clairance.getContents() )
        testRunner.testCase.setPropertyValue( "etatpatho", etatpatho.getContents() )
        testRunner.testCase.setPropertyValue( "idlReq", idlReq.getContents() )
        testRunner.testCase.setPropertyValue( "idprod", idprod.getContents() )
        testRunner.testCase.setPropertyValue( "typeprod", typeprod.getContents() )
        sleep 500
        def ExecuteQuery = testRunner.testCase.testSteps['ExecuteQuery']
        ExecuteQuery.run( testRunner, context )
        sleep 1000
        groovyUtils = new com.eviware.soapui.support.GroovyUtils(context )
        holder = groovyUtils.getXmlHolder ("ExecuteQuery#Response")

        id_type_alerte = holder.getNodeValue("//id_type_alerte")
        testRunner.testCase.setPropertyValue( "id_type_alerte", sheet1.getCell(5,i).getContents() )

        idproduit = holder.getNodeValue("//idproduit")
        testRunner.testCase.setPropertyValue( "idproduit", sheet1.getCell(6,i).getContents() )


        typeproduit = holder.getNodeValue("//typeproduit")
        testRunner.testCase.setPropertyValue( "typeproduit", sheet1.getCell(7,i).getContents() )

        id_ter_per = holder.getNodeValue("//id_ter_per")
        testRunner.testCase.setPropertyValue( "id_ter_per", sheet1.getCell(8,i).getContents() )

        lib_ter_per = holder.getNodeValue("//lib_ter_per")
        testRunner.testCase.setPropertyValue( "lib_ter_per", sheet1.getCell(9,i).getContents() )

        id_ter_com = holder.getNodeValue("//id_ter_com")
        testRunner.testCase.setPropertyValue( "id_ter_com",sheet1.getCell(10,i).getContents() )

        id_typ_ter = holder.getNodeValue("//id_typ_ter")
        testRunner.testCase.setPropertyValue( "id_typ_ter", sheet1.getCell(11,i).getContents() )

        lib_ter = holder.getNodeValue("//lib_ter")
        testRunner.testCase.setPropertyValue( "lib_ter", sheet1.getCell(12,i).getContents() )

        id_nature_ci = holder.getNodeValue("//id_nature_ci")
        testRunner.testCase.setPropertyValue( "id_nature_ci", sheet1.getCell(13,i).getContents() )

        id_ter = holder.getNodeValue("//id_ter")
        testRunner.testCase.setPropertyValue( "id_ter", sheet1.getCell(14,i).getContents() )

        id_sequence_ter = holder.getNodeValue("//id_sequence_ter")
        testRunner.testCase.setPropertyValue( "id_sequence_ter", sheet1.getCell(15,i).getContents() )

        id_fic_ci = holder.getNodeValue("//id_fic_ci")
        testRunner.testCase.setPropertyValue( "id_fic_ci", sheet1.getCell(16,i).getContents() )
        sleep 1000

    }


workbook1.close()

谢谢!

似乎您想从当前 testSuite 中为数据表中的每一行获取下一个 testCase 而不是执行操作每次在当前 testCase 中。我不确定这是你的目标,但你可以从当前的 testSuite 和下一个 select 中收集所有的 testCases每行一个,这样的事情可以解决问题:

// get all testCases from the current testSuite as List
def allTestCases = testRunner.testCase.testSuite.testCases.collect{ name, testCase ->
    return testCase
}

// row iteration
for (int i=6; i<sheet1.getRows(); i++)
{
     // get a testCase
     def testCase = allTestCases.take(1);
     // drop the element from the list to change next iteration
     allTestCases = allTestCases.drop(1);
     ...
     ...
     // in the rest of your code use the testCase variable from the list
     // instead of using testRunner.testCase which always take the current one
     testCase.setPropertyValue("clairance", clairance.getContents())
     testCase.setPropertyValue("etatpatho", etatpatho.getContents())
     ...
     def ExecuteQuery = testCase.testSteps['ExecuteQuery']
     ExecuteQuery.run( testRunner, context )
     ...
}

希望对您有所帮助,