SoapUI NG Pro
  • Preface
  • 1. About SoapUI NG Pro
    • 1.1 Introduction to SoapUI NG Pro
    • 1.2 Application Installation Instructions
    • 1.3 License installation instructions
  • 2. Ready API - How to use
    • 2.1 Creation of Project:
    • 2.2 Test Case Creation
    • 2.3 Assertions
      • Assertions - In Nutshell
      • Groovy Request and Response Save
      • Script Assertion
    • 2.4 Data Driven Testing
  • 3. Execution in SoapUI NG Pro
    • 3.1 Running Tests From Test Steps
    • 3.2 Running Tests From Test Suites
    • 3.3 Running Test From Project Level
  • 4. Report Generation in SoapUI NG Pro
    • 4.1 Test case Level
    • 4.2 Test Suite Level
    • 4.3 Project Level
  • 5. Continuous Integration
    • 5.1 Jenkins ReadyAPI - Installation instruction
    • 5.2 CreateTests from Jenkins
    • 5.3 Run Tests from Jenkins
    • 5.4 Resolve License errors in Jenkins
Powered by GitBook
On this page

Was this helpful?

  1. 2. Ready API - How to use

2.4 Data Driven Testing

PreviousScript AssertionNext3. Execution in SoapUI NG Pro

Last updated 5 years ago

Was this helpful?

In SoapUI to perform data driven testing please follow the below steps

  1. Create the property step for performing looping operation

  1. Create the Data Driver for performing data driving

package kiran

import com.eviware.soapui.support.XmlHolder
 import org.apache.poi.xssf.usermodel.*
import org.apache.poi.xssf.usermodel.XSSFWorkbook

// DECLARE THE VARIABLES 
def myTestCase = context.testCase //myTestCase contains the test case
def counter,next,previous //Variables used to handle the loop and to move inside the file
//file containing the data
def fs = new FileInputStream("C:\\SaiKiran_Nataraja\\TestData\\dataFile.xlsx")
def wb = new XSSFWorkbook(fs)
//Enter the sheet in which data needs to be searched: sheet1
def ws = wb.getSheet("Sheet1")
//get the number of rows, each row is a data set
def size = ws.getPhysicalNumberOfRows()
//log.info totalRows
propTestStep = myTestCase.getTestStepByName("PropLoop") // get the Property TestStep object
propTestStep.setPropertyValue("Total", size.toString())
counter = propTestStep.getPropertyValue("Count").toString() //counter variable contains iteration number
counter = counter.toInteger()  
def TextToSearch
def TextToCompare
def row = ws.getRow(counter)
def totColumns = row.getPhysicalNumberOfCells()
// OBTAINING THE DATA YOU NEED
TextToSearch = row.getCell(0).getStringCellValue() // getCell(column)
TextToCompare = row.getCell(1).getStringCellValue() // getCell(column)
//log.info TextToSearch

next = (counter > size-2? 0: counter+1) //set the next value
//close the file
wb.close() 
propTestStep.setPropertyValue("TextToSearch", TextToSearch) //the value is saved in the property 
propTestStep.setPropertyValue("TextToCompare", TextToCompare) //the value is saved in the property 
propTestStep.setPropertyValue("Count", next.toString()) //increase Count value
next++ //increase next value

propTestStep.setPropertyValue("Next", next.toString()) //set Next value on the properties step
//Decide if the test has to be run again or not
if (counter == size-1){
    propTestStep.setPropertyValue("StopLoop", "T")
    log.info "Setting the stoploop property now..."
}else if (counter==0){
    def runner = new com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner(testRunner.testCase, null)
    propTestStep.setPropertyValue("StopLoop", "F")
}else{
    propTestStep.setPropertyValue("StopLoop", "F")
}
  1. Create the data loop groovy script

def myTestCase = context.testCase
def runner

propTestStep = myTestCase.getTestStepByName("PropLoop") // get the Property TestStep
endLoop = propTestStep.getPropertyValue("StopLoop").toString()

if (endLoop.toString() == "T" || endLoop.toString()=="True" || endLoop.toString()=="true"){
    log.info ("Exit Groovy Data Source Looper")
    assert true
}else{
    testRunner.gotoStepByName("DataDriver") //setStartStep
}

4 . In the main test case, call the property in which ever means you want to. If it is a groovy script then call it using below line of code

def searchString = myTestCase.getTestStepByName("PropLoop").getPropertyValue("TextToSearch").toString()

To run it as data driven testing run it in test case mode so that it repeats for the number of iterations based on the excel data you have passed.

Thanks for reading this portion. If you like it please share...