Forum Discussion

radhika1's avatar
radhika1
Contributor
7 years ago

SOAP UI multiple times to run a test case

Can some one tell me how to run a test case mutiple times in soap ui by reading data from excel.

 

Eg my excel has data like sender name ,sender last name with 5 different values.I need to run the same test case  with sender first name and last  name  multiple times.

 

Eg First run will be sender first name1 and sender lastname1

Second t run will be sender first name2 and sender lastname2

9 Replies

    • radhika1's avatar
      radhika1
      Contributor

      Hi,

       

      I am using soap ui open sources so please suggest how to implement it.

      • avidCoder's avatar
        avidCoder
        Super Contributor

        DataSource Loop makes it easier to run multiple test cases.. And this feature you can get once you buy the license. Otherwise,, You need to write java/groovy code to implement this. You can give a try using for loop :-

         

        def ds = testRunner.testCase.getTestStepByName('DataSource')
        def totalRow = 5
        def col1, col2, col3
        def request = ""

        for (row in 1..totalRow) {
        if (row > 1) {
        testRunner.testCase.getTestStepByName('DataSource').next(testRunner, context)
        }
        col1= ds.getPropertyValue('col1')
        col2= ds.getPropertyValue('col2')
        request += "<column1>${col1}</column1><column2>${col2}</column2>"
        }

         This way you need to write codes which is really tough to handle.

  • JHunt's avatar
    JHunt
    Community Hero

    For getting data from Excel you will need a library. You can search for that, one I see a lot is Apache POI. But it's not all that easy to use. An easier approach might be to save your Excel to CSV. Then you can do this:

     

    /* example CSV:
     *
     * Aaronson,Aaron
     * Baggins,Bilbo
     * Dion,Celine   */

    new File('senders.csv')
    .getText()
    .split ('\n')
    .collect { it.split(',') }
    .each { String[] sender ->

        context << [first: sender[1], last: sender[0]]
        
        /* in the test step, use property expansions:
         *  ${first}, ${last} */
         
        testRunner.runTestStepByName('some request step')
        .with { result ->
           
            /* you can add assertions on the test step,
             * or you can do some here */
             
            assert result.responseContext.contains(context.first)
            assert result.responseContext.contains(context.last)
            assert result.responseStatusCode == 201 //created
        }
    }

     

    • SuperSingh's avatar
      SuperSingh
      Contributor

      Add a step for Groovy Script & put the following piece . This will pull data from excel & load it to properties in your test case.

       

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

      Workbook file = Workbook.getWorkbook(new File("C:/Folder1/File1.xls"))
      tc = context.testCase

       

      //This is to access the sheet
      Sheet PersonInfo = file.getSheet(0)

       

      //This will fetch data from cells. getCell(row,column) -- The leftmost cell being (0,0)
      Cell FirstName = PersonInfo.getCell(1,1)
      Cell LastName = PersonInfo.getCell(2,1)
      Cell Address = PersonInfo.getCell(3,1)
      Cell DOB = PersonInfo.getCell(4,1)
      file.close()

       

      //The following piece will load the excel values in SoapUI in Test Case properties
      tc.setPropertyValue("First_Name",FirstName.getContents())
      tc.setPropertyValue("Last_Name",LastName.getContents())
      tc.setPropertyValue("AddressLine1",Address.getContents())
      tc.setPropertyValue("DOB",DOB.getContents())


      Now, In your Request XML, you can fetch that data using the following syntax.
      <firstName>${#TestCase#First_Name}</firstName>
      <lastName>${#TestCase#Last_Name}</lastName>

       

      Thanks,

      PredatorSingh