Ask a Question

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

SOLVED
sreelokesh
Occasional Contributor

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 as 2sec for all the 250 test cases, I would like to know if I can change the assertion value for all test cases using a groovy script to 5sec instead of changing assertion value for each individual test case.

 

Thanks,

Lokesh

1 ACCEPTED SOLUTION

Accepted Solutions
nmrao
Community Hero

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

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) }
			}
		}
	}
}

 

Capture.PNG

 



Regards,
Rao.

View solution in original post

15 REPLIES 15
rupert_anderson
Valued Contributor

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

Hi Lokesh,

 

Have you tried setting a project level property e.g. responseTime and then using this to set the response time in all the Assertions e.g. using a property expansion ${responseTime} ?

 

Regards,

Rupert

Author of SoapUI Cookbook
AlexKaras
Community Hero

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

Hi Rupert,

 

This is obviously how it had to be done initially, but I take it that Lokesh already has 250 tests with the hardcoded value of 2secs... 🙂

So I think that the question should be read as: "Could someone please provide me with the groovy script sample to iterate through all test steps within test project, find assertions and update the value of one of its properties (e.g. set timeout value to ${responseTime})"

 

P.S. My experience with SoapUI is quite limited and I don't have such code sample at hand (and don't need it at the moment), but if this is possible I would like to see the sample as well. (Just for my education 🙂 )

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
rupert_anderson
Valued Contributor

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

Hi Alex,

 

Thanks, I kind of knew that was what was being asked - for your information, Lokesh has been messaging me privately and I have already provided him with a Groovy script to copy a REST service's request body across all its POST REST Request TestSteps (250).

 

In this particular case, I could certainly enhance the Groovy script to update all Assertions across all his TestSteps, but I don't see it as the best way forward - better to set the Assertions up to use a property.

 

Of course, now that he has 250 Assertions to update - maybe a 'hacky' compromise would be to:

  • Setup the responseTime property
  • Edit the SoapUI project file XML and globally replace the "250" with ${responseTime}

Of course, please backup the project file first in case it goes wrong!

 

Thanks,

Rupert

 

 

Author of SoapUI Cookbook
rupert_anderson
Valued Contributor

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

Sorry Alex, forgot to add the current request copy script in case it is of any interest / use for others:

 

https://gist.github.com/bearsoftware/cfed4594dc3ae1ce7a419ca5fc9b5747

 

I was actually trying to work with Lokesh to perfect it and then I was going to blog it, but my day job is quite busy at the moment! 🙂

 

Thanks,

Rupert

Author of SoapUI Cookbook
AlexKaras
Community Hero

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

Thank you a lot, Rupert. Pretty informative and useful! (As always from you)

And yes, I agree that direct edit of project file may be the fastest and easiest way in this given case. Great piece of advise!

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
rupert_anderson
Valued Contributor

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

Thanks Alex, very kind of you to say 🙂

 

If Lokesh needs the Groovy replaceall, we can work on that too!

 

Thanks,

Rup

Author of SoapUI Cookbook
nmrao
Community Hero

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

If it has to be done very quickly, I would do it in a dirty way. Be sure and careful before adopting it, there is back copy of the soapui project.

 

Close the project from SoapUI

Open the project in a favourite text editor.

Search for (change the value if it is different, when you say 2 seconds, did you put 2000?)

<token>2</token>

Try replacing it with (do not apply replace all, but still this can be quick way)

<token>${#Project#RESPONSE_TIME_SLA}</token>

 

Save the project.

Now Open the project in SoapUI

Define project level custom property RESPONSE_TIME_SLA and assign the value what ever you want.

This not helps with current change, but also for any changes in the future since it is parameterized.

 

Hope this helps.



Regards,
Rao.
nmrao
Community Hero

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

Oh, I just noticed that you already proposed what I thought and added a reply.


Regards,
Rao.
rupert_anderson
Valued Contributor

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

No problem Rao, I think your answer is a bit better and more detailed than when I mentioned the same thing earlier! 🙂

Author of SoapUI Cookbook
cancel
Showing results for 
Search instead for 
Did you mean: