Forum Discussion

sreelokesh's avatar
Occasional Contributor
9 years ago

Updating SLA time assertion for all the test cases in a project

Hi,   My current project structure look like this ..    Project     -- Test suite 1          -- 10 Test cases    -- Test suite 2           -- 20 Test cases   ....   I had given assertion ...
  • nmrao's avatar
    9 years ago

    Groovy Approach

    Note that though it is tested in a limited environment, have a copy of your original soapui project before running this script. This will modify the value of Response SLA assertion for most of the types which supports Response SLA i.e., HTTP, SOAP, REST and JDBC test requests



    Add a Groovy Script step in the same project, in any test case. and copy the below and run the script:


    Like it is mentioned earlier reply, it assigns a project level custom property RESPONSE_TIME_SLA as value of Response SLA assertion. So, you need to define the same project level property and put a value that is needed and save the project.


    Of course, if you are executing the project using SOAPUI_HOME/bin/testrunner.bat/.sh utility, and the there is network latency you can still increase the value from the command-line itself (without even require to modify the value in project) by passing "-PRESPONSE_TIME_SLA=500" along with testrunner command line options.


    You can also find it here


     * This script updates value of Response SLA assertion in the soapui project
     * with value mentioned for 'newSLA' variable below which 
     * currently assigns project level custom property call RESPONSE_TIME_SLA and
     * you need to define it with required value for the request steps of type
    import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep
    import com.eviware.soapui.impl.wsdl.teststeps.RestTestRequestStep
    import com.eviware.soapui.impl.wsdl.teststeps.JdbcRequestTestStep
    import com.eviware.soapui.impl.wsdl.teststeps.HttpTestRequestStep
    import com.eviware.soapui.impl.wsdl.teststeps.assertions.basic.ResponseSLAAssertion
    //update the new value as needed
    def newSLA = '\${#Project#RESPONSE_TIME_SLA}'
    //Get the project object
    def project = context.testCase.testSuite.project
    //Closure to update the Response SLA assertion value
    def updateAssertionSLA = { assertion, sla ->
    	if (assertion instanceof ResponseSLAAssertion) { "Found a request step assertion with Response SLA type, and updating its value"
    //Actual script that traverse thru the project -> suite -> case -> step
    project.testSuiteList.each { suite -> "Looking into test suite: ${}"
    	suite.testCaseList.each { tCase -> "Looking into test case: ${}"
    		tCase.testStepList.each { step -> "Looking into test step: ${}"
    			if (step instanceof WsdlTestRequestStep 
    				|| step instanceof RestTestRequestStep
    				|| step instanceof JdbcRequestTestStep
    				|| step instanceof HttpTestRequestStep) { "Found a request step of required type"
    				def assertions = step.assertionList
    				assertions.each{ updateAssertionSLA(it, newSLA) }