SOAPUI - changing request element value - web-services

I read some articles about SOAPUI, one of them is this SoapUI getting request parameters in mock service script and I think the solution I am looking for is something using Groovy.
I have a SOAP Web Service that I want to run some testes with a dynamically changing request. This request...
<soapenv:Body>
<req:MyrRquest>
<req:number>XPTO</req:number>
</req:MyrRquest>
</soapenv:Body>
My idea is to run a loop from a starting value increasing 1 until I reach my maximum. And I would like to replace XPTO with this changing value.
Did anyone ever attempted this? What is the best way to do that?

Here is the way it can be done, by the use of groovy step.
Define a test case with two test steps:
Test Request step(soap, the one you shown)
Groovy Script Step(this is the additional one which I am proposing)
Define below three test case level custom properties like what you needed min and max times it should be repeatedly executed and provide values as per the test and keep CURRENT_VALUE same as MIN_VALUE which is one time job. Because, CURRENT_VALUE that gets incremented each time and do not want to alter MIN_VALUE each time the test runs. That way, do not have reset the value after each time test case is executed.
MIN_VALUE
MAX_VALUE
CURRENT_VALUE
Note that this cannot run individual steps i.e., the test case has to be executed in order to fulfill your need as it has to repeat the number of times, and hope that is ok for you.
In the test request, need to use the current value place holder.
Change: <req:number>XPTO</req:number>
To : <req:number>${#TestCase#CURRENT_VALUE}</req:number>
Here is the groovy script code:
//Read the test case level properties as integers
def min = context.testCase.getPropertyValue('MIN_VALUE') as Integer
def max = context.testCase.getPropertyValue('MAX_VALUE') as Integer
//Get the previous step name
def pStepName = context.testCase.testStepList[context.currentStepIndex-1].name
//min+1, because already test request is executed once
((min+1)..max).each {
//update the current value incremented by 1
context.testCase.setPropertyValue('CURRENT_VALUE', it.toString())
log.info "Running step ${pStepName} for ${it} time"
//run the previous test step
testRunner.runTestStepByName(pStepName)
}
//finally resetting current value to min value as test finishes
context.testCase.setPropertyValue('CURRENT_VALUE', min.toString())
This groovy script step basically takes care of running the first step for n-1 times, because step 1 already executed before groovy script test step where n is the total number of times required to be executed(n = max - min).
And as mentioned earlier, just run the test case.

Related

Test request on postman to evaluate performance

I was given a job on postman application which I never used that I experienced today. So I have to write queries that must be repeated in a loop in order to have results over different periods of time to check performance (basically tests). I wanted to know how to write the test query to check results in a loop based on duration, date, size.

Postman - how to target the final iteration?

I would like to run a Postman test on just the final iteration of a test run - I am building a variable (array) of response time values across all of the iterations and then want to test this variable for extreme values once we've reached the last / final iteration.
I hoped pm.info.iteration would have my answer but didn't see anything relevant.
I'm using a data file - the test runner highlights how many iterations are applicable (rows in the csv) as soon as the file is chosen so I'm guessing that Postman does know 'final' iteration? I just haven't worked out how to get at it.
My workaround is to hard code the number of iterations per test run based on how many rows my csvs currently have (e.g. if(pm.iteration.info === 70) but not ideal as the data file is likely to grow.
As #DannyDainton mentioned you can use iterationCOunt
iteration index starts from 0 ,so use
(pm.info.iteration === (pm.info.iterationCount-1) )

How to know when elasticsearch is ready for query after adding new data?

I am trying to do some unit tests using elasticsearch. I first start by using the index API about 100 times to add new data to my index. Then I use the search API with aggs. The problem is if I don't pause for 1 second after adding data 100 times, I get random results. If I wait 1 second I always get the same result.
I'd rather not have to wait x amount of time in my tests, that seems like bad practice. Is there a way to know when the data is ready?
I am waiting until I get a success response from elasticsearch /index api already, but that is not enough it seems.
First I'd suggest you to index your documents with a single bulk query : it would save some time because of less http/tcp overhead.
To answer your question, you should consider using the refresh=true parameter (or wait_for) while indexing your 100 documents.
As stated in documentation, it would :
Refresh the relevant primary and replica shards (not the whole index)
immediately after the operation occurs, so that the updated document
appears in search results immediately
More about it here :
https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-refresh.html

Reuse data across iterations

For testing a POST request to an API, I'm using postman. What I'm trying to achieve is that every request I do selects some data from a big file (randomly) and uses this data to populate the body of the request.
What I would like is that I can select for example 10 iterations and have every one of this iterations pick some random data out of the file I would provide.
I have this working for 1 iteration.
The problem is that in Postman I can't find a way to use the data for the first iteration for all iterations.
A workaround could be to copy-paste the data for every iteration I would like to do, but since this will be a rather large dataset I would like to avoid this.
In short, I'm looking for a way to provide a file to the postman runner and use the data in that file for every iteration I would run.
You can try and call your request in a while function with pm.setNextRequest('nameOfYourRequest');
function reccurrentCall(iterations){
while(iterations !== 0){
postman.SetNextRequest('nameOfYourRequest');
iterations--;
};
And call the function with number of Iterations you want to make
recurrentCall(5);

Is there a way to access the iteration number in Postman REST Client?

I'm using postman for API testing. I'm running a large number of tests and I want to print the iteration number to the console on some of them. Is there a way to get the iteration number as an environment-like variable?
According to Postman API Reference, pm.info.iteration - is the value of the current iteration being run.
Example:
console.log(pm.info.iteration);
It is possible now! You can access the iteration variable, in the same way you access other variables like responseBody.
I don't know if there is an internal way to get the iteration number but I believe you should be able to track this number through code yourself. Here's a quick code snippet:
var value = environment.count;
value++;
postman.setEnvironmentVariable("count", value);
If you put this in the pre-request editor or the test editor of a collection that you are sure will run once per iteration it will effectively track the iteration count.
You can get the iteration number with
pm.info.iteration:Number
Is the value of the current iteration being run.
Postman Sandbox API reference
I got there like this:
const count = pm.info.iteration+1
console.log("======== LITERATION "+count+" ========");