How to get the value of property expansion in groovy - web-services

Let's say I have this formula in a soap request
${test#Response#//ns1:authentification/bloc1/bloc2/idSession}
If next step I want to save this value in test case property using groovy, how can I get the runtime value ?
Or is it possible to do it without even using groovy ?

To get this value in the groovy script and then save it in a TestCase property you can use the follow code:
def idSession = context.expand('${test#Response#//ns1:authentification/bloc1/bloc2/idSession}')
testRunner.testCase.setPropertyValue("propName",idSession)
Hope this helps,

Related

Use of if controller for check condition in jmeter

I need to add a check condition for the search result page that, if a search result is found, the script should run further otherwise it should stop on the same step.
This is my Condition in if controller:
${__javaScript("${depdate}"=! null)}
Here depdate is the regex parameter. If search results are found then its value will be null otherwise it will display content. It's a part of a json string.
I have put all further step in the if controller, but not success. Can anyone help me out of this? What is the reason that this is not working.
What is wrong here with what I am performing?
The reason is that your "${depdate}" will never be null.
If ${depdate} variable is set - it will be variable value
If ${depdate} variable is not set - it will be default value (which is ${depdate}
Demo:
So change your expression to be `${__javaScript(vars.get("depdate") != null)} and everything should start working fine.
See How to Use JMeter's 'IF' Controller and get Pie guide for more information on using IF conditions in your JMeter test.

Regular expression default value

Jmeter passes default value when trying to fetch a part of response in my case is a unique name which I want to pass in next request but it takes default value:
{"status":"success","body":{"uniqueName":"jpr1444130495897","voucherType":"sales","transactions":[{"creditAccount":{"uniqueName":"acctomerge","name":"Mayank"},"debitAccount":{"uniqueName":"dacc","name":"dummyaccount"},"amount":2228}],"voucherNo":1912,"date":"01-09-2015","tag":"dummydata","description":"Q3goK8QrUo"}}
In above response I have to capture uniquename & pass it in my next request. But by default it take default value.
Bean shell assertion contains:
${__setProperty(uniqueName,${uniqueName})}
Next request is this.
Still fetching default value. Somebody please help.
As Biffen said it is better to use JSON Path Extractor that comes with jmeter plugins (http://jmeter-plugins.org/wiki/JSONPathExtractor/). It's a lot easier for JSON - just put JSON path (probably in your case just uniqueName will be enough, but you can put there $.body.uniqueName) add a variable name as uniqueName as well, so there will be no problem to use it later as ${uniqueName} in the next request. And that's it.
Oh, and your post suggests that you try to extract it with Beanshell assertion instead of Regular Expression Extractor by the way - that also can be a case.
What exact uniqueName you need to extract? There are 3 of them in your JSON data:
jpr1444130495897
acctomerge
dacc
It isn't necessary to convert variable to property to use in next request. If both requests live in the same thread group - it's enough to use reference name like ${uniqueName}
For JSON data it's more handy to use JSON Path Extractor (available via JMeter Plugins project). See Using the XPath Extractor in JMeter guide (scroll down to "Parsing JSON") for plugin installation and usage instructions.

Test both pages using split gem

I am using the split gem for A/B testing. I have 2 versions of a page for the test. How can our tester test both of these pages without changing the code?
I tested it simply by changing show to show_b in
- if #experiment == 'b'
= render "show_b"
- else
= render "show"
But how can the tester do this?
If you want a tester to be able to force a certain alternative to render a particular template, you can pass a URL parameter to override the normal behavior.
In your controller, you should have something like this to assign the test:
#experiment = ab_test("experiment_name", "a", "b")
For a tester to access a specific version (and not have the test alternative randomly assigned), you can format the URL like so:
http://myawesomesite.com?experiment_name=b
This will always assign the b test alternative, and render the show_b template.
See this section of the Split documentation for more information.
Where you assign #experiment variable? If it from DB you can simple change it via admin panel, before visit page.

Unable to call object from a List located in external BeanShell script [Jmeter]

My end goal here is to get a string from a list that is created dynamically from a JSON response. I am having troubles calling a value from the list that is created in an external BeanShell script. The external script reads the JSON response and creates the list from the filtered response.
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.Filter;
try{
String json = new String(prev.getResponseDataAsString());
List allPositiveAffects = JsonPath.read(json, "$.affectTags[?(#.value > 0.0)].key", new Filter[]{});
vars.putObject("allPositiveAffects",allPositiveAffects);
log.info("allPositiveAffects: " + allPositiveAffects);
int positiveAffectCount = allPositiveAffects.size();
vars.put("positiveAffectCount",Integer.toString(positiveAffectCount));
} catch (Throwable ex){
log.error("Error:\n", ex);
}
allPositiveAffects returns the expected values, so now I want to get one of those values into a subsequent JSON POST.
My Jmeter test setup:
- Thread Group
+ JSON GET request
- BeanShell PostProcessor
+ JSON POST request
Attempting to get a value from allPositiveAffects has proven to be not as easy as calling allPositiveAffects.get(n) like I can within my BeanShell script.
I haven't figured out an easy way to get the contents of the Lists. Am I missing something? I have tried several different things in my JSON POST request. The latest being:
//json POST data
{
"entries":[
"id": -1,
"key": "${__BeanShell(${allPositiveAffects}.get(1))}"]
}
Which returns the following error:
java.lang.ClassCastException: net.minidev.json.JSONArray cannot be cast to java.lang.String
Any help on a solution or workaround for this would be greatly appreciated. It would be a lot easier for me to be able to call a List instead of creating various variables.
I believe that you could just add .toString() to your expression like:
`${__BeanShell(${allPositiveAffects}.get(1).toString())}`
By the way, Beanshell has some performance overhead so I would rather suggest going for JSON Path Extractor which is available via Extras with Libs Set of JMeter Plugins package, it should be more convenient and less resource consuming.
See Using the XPath Extractor in JMeter (scroll down to "Parsing JSON") for installation instructions and some JSON Path language reference examples.

Load testing with SOAP UI

I have a SOAP UI 4.5.1, I have made a load test, it is working fine. My problem is that I run the same request every time and I need to change the values of the soap request I am sending.
For e.g. I have a block of my soap request:
<ns:Assessment>
<ns:Project>
<ns:ProviderId>SHL</ns:ProviderId>
<ns:ProjectId>SampleAssessment</ns:ProjectId>
</ns:Project>
</ns:Assessment>
Provider ID: SHL
Project ID: SampleAssessment
Is there a way to make those values changing from some kind of interval?
For e.g.: Provider IDs [SHL, SLH, LHS]
Project IDs [SampleAssessment, TestAssessment, AnotherAssessment]
And with a load test I am making three request so that for the first request values looks like this:
<ns:Assessment>
<ns:Project>
<ns:ProviderId>SHL</ns:ProviderId>
<ns:ProjectId>SampleAssessment</ns:ProjectId>
</ns:Project>
</ns:Assessment>
for the second like this:
<ns:Assessment>
<ns:Project>
<ns:ProviderId>SLH</ns:ProviderId>
<ns:ProjectId>TestAssessment</ns:ProjectId>
</ns:Project>
</ns:Assessment>
and so on...
Is there a way to make this happen with SOAP UI?
From my experience, you will need to use a Groovy Script step.
For example, if you have a step before your request that is a script, you can use something like:
context.setProperty("ProviderId", "SHL")
Then in your request, use:
<ns:ProviderId>${ProviderId}</ns:ProviderId>
Of course, this doesn't buy you much by itself. There are few ways to vary what the context.setProperty("ProviderId", "SHL") line will set. You can create a collection and iterate over it using something like:
def providers = ['ABC', 'DEF', 'GHI', 'JKL']
providers.each() {
context.setProperty("ProviderId", it)
testRunner.runTestStepByName( "nameofteststep" )
}
Where "nameofteststep" is the name of the Soap Request test step. This might sound odd, but if you right click the test step and disable it, the groovy script will still be able to execute it but it will not run sequentially. By that I mean that the groovy script will run it 4 times, but it won't run a fifth time when the script is complete because it is after the script. Then you just need to keep in mind that each load test thread makes four requests, but I am pretty sure that the SoapUI statistics will take this into account for you... might want to keep an eye out for it, though.
Alternatively, you could check the 'threadIndex' and set a the context variable based on that. A bit like this here: Log ThreadCount.
You could also use a collection without a loop and increment an index that you save as a testcase property and send the string corresponding to the index.
Personally, I think the first way is the most straightforward but I can provide an example of the other ones if you like.
There is a simple way of doing this without writing a groovy script.
After creating a test case you should include the below test steps:
1-Data source
2-Request
3-Loop
Data source will read an excel file (or other data source methods such as XML, groovy, JDBC, gird .. however the excel is the simplest one).
You should include the datas (that you need to change within the request)
Within the test request you need the right click and select "get data" . please notice that your test request should be as below
<ns:ProviderId>${ProviderId}</ns:ProviderId>
Then the last step is the "Loop" . This for returning to the first step until the data ends.
I hope this helps.