Hamza Amami Hamza Amami - 1 month ago 12
Groovy Question

Loop test steps in multiple test cases using SOAPUI

I'm having some issue in automating web services.

Actually I have an excel sheet containing all the input and outputs needed.

I wrote a groovy script that retrieve inputs, save them in properties, execute query, retrieve outputs and compare them with excel outputs.

My problem is that all the process is execute as one test case.

I want to "pimp" my process so that every line of my Excel sheet is dealt as a test case.

Here's the groovy code :

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()=="")
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



Thanks !


Seems that you want to get a next testCase from the current testSuite for each row in the your datasheet instead of performing the operation in the current testCase each time. I'm not sure that this is your goal, but you can collect all the testCases from the current testSuite and select the next one for each row, something like this can do the trick:

// 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 )

Hope it helps,