Preparing the test environment
- Create a folder where SOAP data driven testing will occur, e.g. C:\SOAPUIRulesTest
- In the project folder (e.g. DTTest) is where the SOAPUI project will be stored
- In the project folder, create a result folder for each instance of the testing you want to run, e.g. output
- In the date/time stamped test case folder is where the following will reside
- input CSV file
- results XML files from SOAPUI
- results spreadsheet Preparing the input CSV file
- Create a CSV file into the test case folder, e.g. input.csv
- Format the CSV file as follows:
- First row is the name of tags which the values will be replaced with
- Row 2 onward are the tag values
- The last column is the expected result field - this is used to create an assertion in SOAPUI against which to test
soapUI Project
- Open soapUI and create a new project using the WSDL path for the Rule Service - keep the name short as long names may cause path issues down the line
- Create the test suite as part of the project creation or afterwards
- Save the project into theproject folder created earlier (not the date/time stamped folder) Test Suite
- Create a new test suite
Test Case
- Create a new test case - keep the name short line "TestCase1" - this name will be used later
- Select the test case and select options
- Make sure you unselect "Abort on Error" Test Request Add Test Request and select "Create Optional Elements"
- You should now see the SOAP XML structure, e.g.
Setup Script
- In the test case open the "Setup Script" tab and paste the following code inside
//Setup script:
//def directory = "C:/SOAPUIRulesTest/getClientRiskAppetiteClassification" def directory = "c:\{path}
//Output the headings
for (i=0; i<context.fieldNameArray.size(); i++)
{
}
context.fileWriter.append("TestResult"+"\r\n")
//set the properties for the first record
p=0
for (i=0; i<context.fieldNameArray.size(); i++)
{
testCase.setPropertyValue(context.fieldNameArray[i],propData[p++].trim())
//e.g. "uniqueId" = propData[0])
}
p=0
for (i=0; i<context.fieldNameArray.size()-1; i++)
{
context.fileWriter.append(propData[i]+",")
}
//Rename request test steps for readability in the log; append the
element name to the test step names
testCase.getTestStepAt(0).setName("TestRequest_" + propData[0]+"_"+propData[propData.size()-1])
- Change the file path to where the CSV file is stored (in the date/time stamped folder)
- Adjust all the "setPropertyValue" statements to match the xml tags mentioned in the Test Request substitutions earlier
Groovy Script (ReadNextLine)
- Now add a Groovy script called "ReadNextLine"
- Now paste the following code into the window for the script:
//Setup script:
//def directory = "C:/SOAPUIRulesTest/getClientRiskAppetiteClassification"
def directory = "C://result"
for (i=0; i<context.fieldNameArray.size(); i++)
{
}
context.fileWriter.append("TestResult"+"\r\n")
//set the properties for the first record
p=0
for (i=0; i<context.fieldNameArray.size(); i++)
{
testCase.setPropertyValue(context.fieldNameArray[i],propData[p++].trim())
//e.g. "uniqueId" = propData[0])
}
p=0
for (i=0; i<context.fieldNameArray.size()-1; i++)
{
context.fileWriter.append(propData[i]+",")
}
//Rename request test steps for readability in the log; append the
element name to the test step names
testCase.getTestStepAt(0).setName("TestRequest_" +
propData[0]+"_"+propData[propData.size()-1])
Adjust all the "setPropertyValue" statements to match the xml tags mentioned in the Test Request substitutions earlier
Assertion
- Click on the Assertion tab for the Test Request
Add details as:
- This sets the assertion to match the last column of the CSV file
- Run the test case to make sure all tests now pass
No comments:
Post a Comment