Editing SOAP UI project via just the UI can be a pain, and it includes few tools for refactoring the Test Suite. However Groovy provides a superb tool for refactoring your test suites.
This first Groovy script shows how to iterate all TestSteps, within all TestCases, within All TestSuits of a SOAPUI Project.
It includes two types of guard statement to allow you to control which TestStep are modified. Firstly it checks the Test Suite Name includes the String ”(TARGET)”. The properties testSuite, testCase and testStep all include names allowing for a pretty fine degree of control. This string should obviously be changed to limit the scope of the refactoring. This is essential operating as a refactoring white-list.
Additionally this script ensure the TestSuite, TestCase and TestStep are not disabled. This essentially operate as refactoring black list which allows you prevent the refactoring applying to some Tests.
def project = context.testCase.testSuite.project
def testSuiteList = project.getTestSuiteList()
testSuiteList.each
{
if (!it.isDisabled())
{
def testSuite = it
if (testSuite.name.contains("(TARGET)"))
{
def testCaseList = testSuite.getTestCaseList()
testCaseList.each
{
if (!it.isDisabled())
{
def testCase = it
def testStepList = testCase.getTestStepList()
testStepList.each
{
if (!it.isDisabled())
{
def testStep = it
if (testStep instanceof com.eviware.soapui.impl.wsdl.teststeps.RestTestRequestStep)
{
if( testStep.getAssertionCount() != 5)
{
log.info(testSuite.name+"."+testCase.name+"."+testStep.name+"="+ testStep.getAssertionCount())
def assertionList = testStep.getAssertionList()
assertionList.each
{
def assertion = it
log.info(testSuite.name+"."+testCase.name+"."+testStep.name+"."+assertion.name)
}
}
}
}
}
}
}
}
}
}
Create or Add an Assertion if it doesn't already exist.
assertionName = "Contains Character Encoding"
def assertion = testStep.getAssertionByName(assertionName)
if (assertion == null)
{
def newDocTypeAssertion = testStep.addAssertion("Contains")
newDocTypeAssertion.name = assertionName
newDocTypeAssertion.setToken( /<?xml version="1.0" encoding="UTF-8" ?>/)
log.info("newDocTypeAssertion.getToken()="+newDocTypeAssertion.getToken())
}
assertionName = "XPath Match xml api version 6"
def assertion = testStep.getAssertionByName()
if (assertion == null)
{
def newAssertion = testStep.addAssertion("XPath Match")
newAssertion.name = assertionName
newAssertion.path = "/xmlapi/@version"
newAssertion.expectedContent = "6.0"
}
Rename an SOAPUI Assertion
def assertion = testStep.getAssertionByName("Contains")
if (assertion != null)
{
assertion.name = "XPath Match returnStatus"
}
Delete a SOAPUI Assertion.
assertion = testStep.getAssertionByName(assertionName)
if (assertion!=null)
{
testStep.removeAssertion(assertion)
}