Forum Discussion

sreelokesh's avatar
sreelokesh
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

    https://github.com/nmrao/soapUIGroovyScripts/blob/master/groovy/UpdateResponseSLA.groovy

     

    /**
     * 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
     * SOAP, REST, JDBC, HTTP
     */
    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) {
    		log.info "Found a request step assertion with Response SLA type, and updating its value"
    		assertion.setSLA(sla)
    	}
    }
    //Actual script that traverse thru the project -> suite -> case -> step
    project.testSuiteList.each { suite ->
    	log.info "Looking into test suite: ${suite.name}"
    	suite.testCaseList.each { tCase ->
    		log.info "Looking into test case: ${tCase.name}"
    		tCase.testStepList.each { step ->
    			log.info "Looking into test step: ${step.name}"
    			if (step instanceof WsdlTestRequestStep 
    				|| step instanceof RestTestRequestStep
    				|| step instanceof JdbcRequestTestStep
    				|| step instanceof HttpTestRequestStep) {
    				log.info "Found a request step of required type"
    				def assertions = step.assertionList
    				assertions.each{ updateAssertionSLA(it, newSLA) }
    			}
    		}
    	}
    }