Forum Discussion
Hey wiseAcre
It seems like this is getting waaaaaaaaaay more complicated than it needs to be. Are you using ReadyAPI! or SoapUI?
You don't really need the tail end of the script - once you've incremented the RefID value, can't you just use the GetData function to do the work for you of picking up the incremented value?
Don't understand
Can you just explain (again) your use case - forgive me - but from what I understand, you just need to increment an existing ref id for a subsequent request which doesnt need anywhere near all that groovy - you just need a little bit.
So can you just explain from scratch exactly what you want to do.
i.e. is the ReferenceID generated from the testcase's previous response or is it hardcoded to a TestCase property at the start?
are you passing this incremented ReferenceId to another teststep within the same testcase OR do you need this incremented RefId for a teststep in another testcase?
Can you just describe the teststep hierarchy you have in your testcases at the moment (list what test steps you have in your testcase and the sequence of the steps)?
Sorry - I need to go back to basics to make sure I'm not misunderstanding. I'm pretty literal with no imagination so I need to make sure I really understand what you need before I can fix your groovy/come up with an approach where you dont need too much groovy.
nice one,
Rich
Ritchie,
This is my first experience using Groovy scripts and setting up a load test with multiple test steps, I've been using a Udemy course on Webservices/Rest API Testing so I have what I can only assume is a good reference. That said, the course does not cover all, here is my use case:
1. Eight test step requests from Oracle OIBEE projects have been gathered to form a Load Performance Test Suite
2. Each test step's payload.xml file needs to have the ReferenceID value incremented each time a request is sent otherwise the system will error and it will not be processed (nor assigned a TransactionID).
3. I have Groovy script incrementing the ReferenceID in the groovy console, solution was found on Stackoverflow as noted.
4. Now I need to sync the script with the payload.xml so each time I send a request from the test step itself, the RefID auto-increments. Currently, if I increment the Script and then execute a Request, the ReferenceID is incremented, but if I do NOT increment the Script and then execute a Request, the new Request shows the same ReferenceID as the previous one, though the TransactionID does increment, but that request is errored.
5. Finally, after my script is functioning, I'll use it in all 8 of the test steps so when I throw off a Load Test with the 8 test steps all of the requests will at least process to the extent that each request will be assigned a new Reference & TransactionID, whether they error in a system if they overload is another issue, but not my concern.
Thanks for your interest.
Stephan
- richie4 years agoCommunity HeroHey wiseAcre,
Just to be clear, i wasnt criticising your groovy, it just looked like a lot of it was superfluous to requirements which made me think i was misunderstanding something.
More questions:
Q1. What is the datatype and minlength and maxlength of the ReferenceId
Q2. Does the ReferenceId have to be incremented or does it just need to be unique?
Q3. Going on memory here cos im on my phone. In the original script you had an if clause something like 'if ReferenceId > 999000'. Can you just explain what this value was and what the purpose of the if clause was supposed to do?
Ta
Rich
When you say the - wiseAcre4 years agoOccasional ContributorRitchie,For this testing environment, the ReferenceID does not have a min or max length, it simply needs to be unique. I actually tried another solution where I used the java mathRandomUtils library to generate a random number, but that generated negative numbers too so I canned that. The IF statement with a max value is simply a loop control mechanism.No criticism taken, when I can get this whole thing worked out, I'll post it as a complete solution.
- richie4 years agoCommunity HeroHey wiseAcre,
If it just has to be unique this is even easier.
You had the right idea with the random number generator.
Theres a number of different ones i use....a guid/uuid generator, number generator based on current date/time.
We can use a dynamic scripting property based on the date/time of when it executes. You wont need any of the groovy.
Im on my phone and cant remember the date/time option, but i can show you using the guid/uuid dynamic scripting option.
In your payload, instead of creating loads of groovy to 1. create a number, 2. pass it to the payload, 3. Increment the number and then repeat. You just need to add in the dynamic scripting property instead.
E.g.
For json payload:
"jsonAttribute": "$ {=java.util.uuid.randomuuid()}"
Or for xml payload:
<element1>$ {=java.util.uuid.randomuuid()}</element1>
When the payload is submitted it will dynamically generate a unique GUID/UUID value in the payload.
I'll dig around tomorrow and see if i can find the equivalent dybamic scripting property based on current date/time. Its i think 10chars long rather than the 30chara the GUID/UUID is made up of.
I think we've sorted your problem out fella!
Nice one!
Rich - wiseAcre4 years agoOccasional Contributor
Ritchie,
I'm still at loggerheads on this one: issue is still passing the incremented value to the xml payload, here's what I have including libraries. BTW: the udemy video I've been watching states that one must use the XmlHolder & the WSDL library. What's been killing me are "MissingMethodException" errors. I've included all of my attempts--commented out--to date. I've been stumped for so many hours on this, I decided to start a Groovy course from scratch. The Java Devs are too busy with their stuff so I'm left on my own. I'll get it eventually, question is "when is eventually?" Again, thank you for your interest in this issue.import java.util.Random;
import org.apache.commons.lang.math.RandomUtils
import com.eviware.soapui.support.XmlHolder //assists transfer'g values to payload
import com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext
def ReferenceID = testRunner.testCase.getProperty("ReferenceID");
def RefID = ReferenceID.value = RandomUtils.nextInt(new Random()); //new Random(System.currentTimeMillis());
log.info (RefID);
// Above workstestRunner.testCase.setPropertyValue("ReferenceID", $('{#RefID}' + 1)); // Getting Missing Method Exception error with this
//log.info context.expand('{$#TestCase#ReferenceID}');//def RefID = testRunner.testCase.getPropertyValue ('${#TestCase#ReferenceID}');
//def xmlRef = new XmlHolder(RefID);//log.info context.extent(ReferenceID.value);
//def RefID=testRunner.testCase.setPropertyValue("ReferenceID",('${#TestCase#ReferenceID}'));//def updateRef = new WsdlTestRunContext("ReferenceID");
//log.info context.expand("RefID");
// Call the service AddTestStep.run(testRunner,context) - wiseAcre3 years agoOccasional Contributor
So here is the solution for incrementing a parameter in a payload xml file, two requisites to the Groovy are:
* A Property needs to be defined, in this use case it was called "incrementValue"
* The value in-question needs to be 'parameterized', I'm 'P-izing' ReferenceId as follows:
<req:ReferenceId>${Properties#incrementValue}</req:ReferenceId> // Calls the Pre-set Property "incrementValue
and finally only four lines of script are required:
def incrementValue = context.expand('${Properties#incrementValue}');
incrementValue=incrementValue.toInteger() + 1;
incrementValue=incrementValue.toString();
log.info "incrementValue: " + incrementValue; // Optional as this simply prints the text in the groovy editor
testRunner.testCase.getTestStepByName("Properties").setPropertyValue("incrementValue",incrementValue);I'm labeling this solution as solved, much thanks to Ritchie and others who provided valuable feed-back during the past two weeks.
Cheers, wiseAcre
Related Content
Recent Discussions
- 4 days ago