I have a textfield whose DOM is as follows
<input type="text" name="txtCurrentCashTally" id="txtCurrentCashTally" CLASS ="protected" disabled="disabled" value="0" size="20" maxlength="13">
Now I have
xpath: //input[#id='txtCurrentCashTally']/#value='0' to match this field.
I want to assert if this xpath contains a value which is a variable that I use.
Var_A is the xpath //input[#id='txtCurrentCashTally']/#value from Xpath Extractor on the response.
Var_B is from another response.
Using Xpath assertion, is it possible to assert if Var_A = Var_B?
I can try out the "JMeter Variable name to use" but is there a way to pass multiple variable names there?
Sure, just replace this 0 with ${Var_B} and you should be good to go:
If you want to compare 2 JMeter Variables it can be done with Response Assertion:
More information: How to Use JMeter Assertions in Three Easy Steps
After you got the 2 variables use JSR223 Assertion and assert them using:
AssertionResult.setFailure(!vars.get("Var_A").equals(vars.get("Var_B")))
Related
How i can pass the value of below from one http request to another in Jmeter ?
code value generate random value at run time.I need to extract the value of code.
var launch_url = "/abc/FileUpload/FileUpload.application?code=" + code;
I explored RegularExpression / CSS Extractor but was not able to fit in my case.
I am extracting the value of Antiforgerytoken like below sample (Screenshot) and it works -
<input type="hidden" name="ctl00$AntiforgeryToken" id="AntiforgeryToken" value="40579e4b-7718-4bb2-abaa-4d98c391fb48" />
but i am not sure how to extract value of code from this ??
var launch_url = "/abc/FileUpload/FileUpload.application?code=" + code;
Considering, You need to get the code value from the URL shown which comes in the response. Please check the below regEx:-
Hope it helps.
You can use the regular expression extractor element of Jmeter and use the below regular expression to capture the token.
id="AntiforgeryToken" value="(.*?)" />
I am making scripts using JMeter to perform some tasks in which I want to access first request's response in the second request as a value parameter value using XPath extractor.
For Ex.
Here is my response of the first request in XML format:
<a>
<b>
<c>
<my_details>
<first_name>A</first_name>
<middle_name>B</middle_name>
<last_name>C</last_name>
</my_details>
</c>
</b>
</a>
Now, I want to use first name and last name in the second request's value. For that, I am using XPath extractor to get values from the response as given below:
But I got the response like:
JMeterVariables:
**full_name=A
full_name_1=A**
...
...
__jm__Thread Group__idx=0
__jmeter.USER_TOKEN__=Thread Group 1-1
So, my question is, how can I get the full name using single XPath extractor?
Try to extract "first_name" and last "last_name" separately using XPath extractor , Then use Beanshell post-processor to create Jmeter variable for fullname , Like
vars.put("full_name",vars.get("FIRST NAME JMETER VARIABLE")+" "+vars.get("LAST NAME JMETER VARIABLE"));
I was able to achieve the desired result using the concat() function (https://www.w3.org/2005/xpath-functions/).
I utilized XPath2 Extractor with Xpath query set to:
concat(//my_details/first_name, " ", //my_details/last_name)
This leads to output variable being assigned the value "A C":
Please, note that it is currently advised to use XPath2 Extractor
(https://jmeter.apache.org/usermanual/component_reference.html#XPath_Extractor):
How to write json path expressions for the below script in jmeter . I need to get the two dynamic values session id and csrf
<input type="hidden" name="_txtSession_Id" value="tw-2777518705045647360wor" >
<input type="hidden" name="csrf_token" value="QIuBhc0mxMfA0XMczGIoZ+jPRprc3wfxbxCfjHiAykU=" />
You cannot use JSON Extractor on HTML data, consider using CSS Selector Extractor instead.
The relevant configuration would be something like:
Name of created variable: anything meaningful, i.e. _txtSession_Id
CSS Selector Expression: input[name=_txtSession_Id]
Attribute: value
That's it, you will be able to refer the first value as ${_txtSession_Id} where required.
The same way you can extract csrf_token, just change CSS Selector Expression to input[name=csrf_token]
You can test your CSS Expressions using View Results Tree listener
In need to pass a data from a response to the subsequent request. Something goes wrong and the default variable value appears in the request.
First request returns the JSON in response body which looks like this:
{"issued_at":"2016-01-14T12:41:01.000Z","expires":"2016-01-14T12:46:01.000Z","id":"j6M ... MTA=="}
I extract the value of the id attribute using the Regular Expression Extractor:
Then I pass the token variable to the subsequent request parameter:
But the request is created with the default value of the variable:
There is a JSON Path Extractor designed to deal with JSON content type, I believe it would be easier to use it.
The relevant JSON Path query will be as simple as $..id
See Using the XPath Extractor in JMeter (scroll down to "Parsing JSON") for comprehensive information on plugin installation and usage and JSONPath - XPath for JSON for JSONPath language reference and examples.
In regards to your Regular Expression Extractor configuration:
remove 1 from Match No.
Provide $1$ as Template
If you look at the Regular Expression Extractor documentation, the field Template is required. I suggest you to use value $1$ and try again.
The problem was resolved by setting the "Field to check" radio button to "Body" at the "Regular Expression Extractor" dialog and by setting the Template field value to $1$.
Thanks to alphamikevictor and Dmitri T for help!
You should use ${token_g1} to get the value of the first group of the regex match (the value you're looking for).
I am trying to get the value from a hidden input field. I researched and found many sites ( including instances on this site ) showing great examples. When I try them, I am not able to retrieve the value from this hidden field using the methods I have learned. I have tried both an xpath extractor and a regular expression extractor, but neither one retrieves the value from the hidden field.
Also, I will note that in the tree on the left side in JMeter, I put the extractors as a child to the HTTP Request where the token first appears. Are the extractors supposed to be children or are they supposed to be at the same level as the HTTP Request, but just after it in the flow of the test?
==============================
Here, I will explain my set up. There is an HTTP request from a form. There is a token on the form. I need to get the value for this token. Here is the html for the page where the token appears:
<form action="/folder1/part1/save/12345-1234-1234-1234-123456789012" method="post" name="mgr" id="mgr" >
<input type="hidden" name="token" value="1234-12-12-12-1234" id="token" />
==============================
For the Regular Expression Extractor, I have tried all of these, one at a time for each test run:
//input[#type="hidden" and name="token"]/#value
//input[#type="hidden"][#name="token"]/#value
//input[#type="hidden"]/[#name="token"]/#value
//input[#type="hidden"][#name="token"]/#value/[#id="token"]
//input[#type="hidden"]/[#name="token"]/#value/[#id="token"]
For the XPath Extractor, I have tried all of these, one at a time for each test run:
//[#id="token"]
/html/body/div/div[2]/div/form/input[1]
//html/body/div/div[2]/div/form/input[1]
Try this one: //input[#type="hidden" and #name="token"]/#value
Also, you could test your expressions exactly in JMeter. For example, this xpath extraction you could check in XPath Tester element in View Result Tree Listener. There you could find Regexp Tester too