I have a test case which restricts a user to have access to several accounts except what she is assigned to (say only Account-X) . So I use HTTP Request to get Accounts. The results are successful (200 code), I need to examine response data, if data contains other accounts (which that user is not assigned to) then mark that test failure.
I have been usign Bean post shell as such: (where Z2 is Account-X and matches is number of accounts in response data)
if ( (prev.getResponseDataAsString().indexOf(Z2) >= 0) || (matches > 1)
I am told I should have used Response assertion,
Field to test : Text Response,
Pattern matching rules : Equals (not sure of this)
what should I set my "Pattern to Test" then?
Considering your response may contain account X,Y and Z. You can use response assertion and put Account Y and Account Z in pattern test as shown in the below image.
In pattern matching rules select "Contains" and "Not" check. Not check will reverse the assertion.
Below you can see if response contain y or z along with x then request will fail and if only account-x is present then it will pass.
I hope this will help.
Related
Below code is in While controller
${__jexl3(${__jm__While Controller__idx} < 3 && "${responseCode}" != "200",)}
enter image description here
enter image description here
Above is in Regular Expression extractor
Result: It is looping 3 times for successful requests also but I want to loop only for failed requests and for success requests it should execute once
Thanks for in advance
Your regular expression extractor configuration is not correct, you need to apply it to Response Code, not to the Body
With your current configuration it extracts first numeric value from the response body and HTTP status code is not there, it's a special response header
Following another solution with a While Controller, If Controllers, and Flow Control Action (FCA) controllers.
Add the following into the While controller
${__groovy(${__jm__WC__idx}.toInteger() < 5)}
Add the request and two If controllers below them with Flow Control Action elements as shown in the figure
Add the following into the first If Controller
${JMeterThread.last_sample_ok}
Select Break Current Loop in the FCA element
Add the following to the second If Controller
${__jexl3(!${JMeterThread.last_sample_ok})}
Set the FCA to Go to the next iteration of the next loop
If you want to do something else, in addition, to retry, Set pause in the FCA element, add a JSR 223 element inside the FCA and include the actions. For example, I wanted to log the user name of the failing requests and retry.
String username = vars.get("username")
int current_loop_count = vars.get("__jm__WC__idx").toInteger()
log.warn("Attempt# ${current_loop_count.next()} $username ")
current_loop_count.next()<5?:ctx.getThreadGroup().getOnErrorStartNextLoop()
In my test plan I have 2 endpoints bid and win. And if bid endpoint return status 200 (it can also return 204, but I need only 200 so I can't use ${JMeterThread.last_sample_ok}) I need to run win endpoint.
I did:
create defined variable STATUS_OK
Create regular expressions extractor under bid request to get response code :
Add If controller and insert win request under that controller :
But if controller condition not working, Jmeter never run win request.
Any idea why it's not working? or maybe have I can debug it? I would be grateful for any help!!!
Updated including test plan structure:
bid requests - is CSV Data set config wit random jsons for each bid request (did like mentioned here)
thread - it's a thread with 200 users and 1 loop
bid - post request, for body I'm using one of json files ${__FileToString(/home/user/Downloads/jmeter/jsons/${__eval(${JSON_FILE})}.txt,,)}.
Also bid request include currency, bidid etc. it's Json
extractors, I'm using that data to generate correct win URL for
each bid.
if bid made - if controller discussed here
win - get request, where URL queries are different depends on bid response (using Json extractors). Url looks like:
win?auctionId=${AUCTIONID}&bidId=${BIDID}&impId=${IMPRESSIONID}&seatId=${SEAT}&price=${__javaScript((Math.random()* (4 - 1)+1).toFixed(4);)}&cur=${CUR}&adId=${ADID}
For If Controller You should use __groovy or __jexl3 function instead
Interpret Condition as Variable Expression? If this is selected, then the condition must be an expression that evaluates to "true" (case is ignored). For example, ${FOUND} or ${__jexl3(${VAR} > 100)}. Unlike the JavaScript case, the condition is only checked to see if it matches "true" (case is ignored).
Checking this and using __jexl3 or __groovy function in Condition is advised for performances
In your case use
${__groovy(vars.get("BID_STATUS") == vars.get("STATUS_OK") )}
Or
${__jexl3("${BID_STATUS}" == "${STATUS_OK}")}
You need to surround JMeter Variables references with quotation marks like:
"${BID_STATUS}" == "${STATUS_OK}"
Alternatively (better) you can get rid of this Regular Expression Extractor and switch If Controller's condition to use __groovy() function like:
${__groovy(prev.getResponseCode().equals(vars.get('STATUS_OK')),)}
More information: Apache Groovy - Why and How You Should Use It
I want to manipulate the request body of HTTP thread based on the data extracted (using 'Regular Expression Extractor') from the previous HTTP response.
Here is the scenario:-
I have extracted the statusFlag and statusId from 'HTTP request 1' as:
Ref name: status
Reg. Exp: "statusFlag":"(\w+)","statusId":"(\w+)"
So, first I want to check that the value of statusFlag is 'New' or not.
If it is New then I have to proceed and feed statusId in next HTTP request or else display statusFlag mismatch.
Need help. Got stuck badly.
I believe Response Assertion is what you're looking for. Add it after the Regular Expression Extractor and configure it as follows:
Apply to: JMeter Variable -> statusFlag (or your reference name)
Pattern Matching Rules: Equals
Add New as a "Pattern to Test"
The assertion will check whether "statusFlag" is "New" and if not - it will fail the sampler and report the expected and the actual value.
Optionally you can add If Controller after the Response Assertion, use ${JMeterThread.last_sample_ok} as a condition and place 2nd request as a child of the If Controller - it will be executed only if "statusFlag" is new.
See How to Use JMeter Assertions in Three Easy Steps guide for more information on conditionally setting pass or fail criteria to requests in your JMeter test.
That's how your Jmeter project should look like.
Regular Expression Extractor stores extracted value in ct variable that can be accessed in If Controller as "${ct}" == "yourvalue" and, if true, can be also sent as a part of Request 2 body using the same ${ct} reference.
Jmeter project structure
I am using SoapUI Pro 4.5.2 to read data from spreadsheets, put them into Soap requests to my web service, and get responses back to write to a spreadsheet. It's working.
I have two fields in the input data pertinent to my question:
Middle name is defined as a string of 4 characters, and as minOccurs = 1 and maxOccurs = 1.
Postal extension code (the 4-digit number that is optional after the normal 5-digit code) is defined as a string of 4 digits. This field is optional, so it is marked as minOccurs=0 and maxOccurs=1.
When I use the SoapUI UI interface to send a request, this works fine; if there's no value for middle name, SoapUI generates an empty tag and sends it (I guess because of the minOccurs=1). If there's no value for PostalCode, it does not send any tag at all (I guess because of minOccurs=0).
When SoapUI reads data from an Excel spreadsheet, however, the response to the same data is an error indicating that the extended postal code value of '' is not legal, because it must be 4 digits. It appears that SoapUI generates an empty tag for the extended postal code when reading data from the spreadsheet, and sends it.
I found the "Remove Empty Content" option for SoapUI requests, default to false. I set it to true, and now get an error back from validation indicating that middle name is required but not found. I'm guessing that the remove empty content removed all the empty content (reasonable enough), and middle name has to be there, even if empty, because of the minOccurs=1.
Do I have any way out of this tail-chasing problem? I suppose I'm looking for something like a conditional for the output of the postal extension code, so I can eliminate it if it's empty, even if reading values from the spreadsheet.
I am also curious if there are XSD fixes, but I greatly prefer a fix that doesn't involve changing the XSD -- that becomes a political matter.
EDIT FOR DETAIL:
To put input into the request: I have used the SoapUI UI to choose "properties" from the input spreadsheet for each of the input fields; when that's done, one ends up with values in the request fields like:
${SpreadsheetInput#FrstNm}
Where SpreadsheetInput is the name of the datasource step reading the spreadsheet, and FrstNm is one of the properties. I do this with the "Get Data" option off the popup menu you get by right-clicking the request input field, but there may be other ways.
So first your problem:
Remember that internally to SoapUI almost everything is a string. Doing something like:
<postCode>${SpreadsheetInput#PostCode}</postCode>
in your SOAP request, assuming PostCode is either blank or does not exist outright, will expand to:
<postCode></postCode>
and SoapUI will even optimize it to:
</postCode>
Then your validation kicks in, which says you do not need to provide this element, but if you do, it had better be 4-characters long. Which the above fails.
The solution:
You need to pragmatically (meaning you will have to write Groovy code) create this node in your request. There are several ways to handle this. The quick and dirty is with a Groovy step, that goes something like:
def postCode = context.expand('${SpreadsheetInput#PostCode}').trim()
if (postCode != null && postCode != '')
testRunner.testCase.setpropertyValue("postCodeNode", "<postCode>" + postCode + "</postCode>")
else
testRunner.testCase.setpropertyValue("postCodeNode", "")
Then in your request replace the original:
<postCode>${SpreadsheetInput#PostCode}</postCode>
with just:
${#TestCase#postCodeNode}
Notice, the XML node elements are part of the SoapUI property! Again: everything in SoapUI is just a plain string.
If you want something more hard-core, have a look at
dynamically create elements in a SoapUI request. This is mine.
I use JMeter to do performance test of web server. My test case is as following:
step1: send file update request to server.
step2: server will return some files URL as html response
step3: client need to create new request with the URL returned in step2,thus need to parse
the response of step2.
I am new to JMeter, and do not know how to implement it. I basically learned JMeter about the pre-processor and post-processor, but still no clue about how to do.
Ok let's start before the first step :
Right click -> Add -> Threads (Users) -> Thread Group
Now the actual first step (If you use REST) :
Add -> Sampler -> Http Request
You have at the bottom part Send Files With the Request. You can add file attachment if that is what you asked.
Extracting response from the server :
Let's assume your response is this :
<Response>
<name>StackOverflow.com</name>
<url>http://stackoverflow.com/questions/11186423/how-to-parse-response-of-sample1-to-create-new-sample-in-jmeter</url>
</Response>
Here is what you do :
Right click on The http request you previously added (in step 1) -> Post Processors -> Xpath Extractor
Reference Name is the name of the variable in which you want to store the value. Let's name it url. And Xpath query is Response/url or //Response/url if you get more response tags. If you want the first one //Response[1]/url and so on..
Repeat step 1 (copy/paste sampler and remove the Xpath Extractor you don't need it anymore), and change the Server Name or IP to ${url} which is the value previously returned.
And Voila there you go. Let me know if you got more specific questions. Jmeter is fun.
Per Grace comment :
Wants to extract https://192.168.100.46/updserver/download?action=signature_download&token=
Out of response data :
<responseData class="java.lang.String"><html>
<body>
ERROR=0
MSG=N/A
FILELIST=1555;1340778737370;1526545487;
VERSION=1.002
URL=https://192.168.100.46/updserver/download?action=signature_download&token=
INTERVAL=0
</body>
</html>
</responseData>
This should be pretty simple. Add a post processor -> Regular Expression Extractor and put the following :
Reference Name : url
Regular Expression : (http[\S]+)
Template : $1$
Match No. (0 for Random): 1
So now you have url variable that you can use further in your test as ${url}. Let me know if that works for you. I tested with dummy sampler and it works for me.
This is how I extract some value from url and pass it further as variable so next requests will contain it.
Here are some nice screenshot and wider description about making test in JMeter http://jmeter.apache.org/usermanual/build-web-test-plan.html
Add the Thread Group and HTTP Requests
When this HTTP Requests response with some data (in this example in URL) you want to extract it and us it after
So lets go:
Go to your first HTTP Request after which one you receive response with variable:
Add -> Post Processor -> Regular Expression Extractor
In this window set:
Response Field To Check: URL
Reference Name: MY-CUSTOM-VARIABLE-NAME
define name of variable whatever you like
Regular Expression: permanent.part.of.url.com/([a-zA-Z0-9]*)
so expression ([a-zA-Z0-9]*) is responsible for getting all
occurrences of alphabetic and numeric chars after meeting permanent url at start
Template: $1$
only one expression is extracted in our case and it need to be read
Match No. (0 for Random): 1
in this case there is only one match, but if more occur you can
choose which one use
Now put extracted value into next HTTP Request
Path: some.other.url.com/${MY-CUSTOM-VARIABLE-NAME}
remember that you read JMeter variables with this pattern ${}, so
use ${MY-CUSTOM-VARIABLE-NAME} whenever you need this value
Run your test and check what did you get in url of your request with MY-CUSTOM-VARIABLE-NAME
Experiment with regexp to get desired output.
Here is blogpost about this stuff:
http://kenning.co.nz/development/extracting-variables-using-regular-expressions-in-jmeter/
And always useful JMeter documentation:
http://jmeter.apache.org/usermanual/component_reference.html#Regular_Expression_Extractor