How to extract a response value when doing http post using Jmeter - jmeter

Can anyone please help me here? I'm trying to do an http post in Jmeter, http works fine, but I'd like to extract the LastName value from the response to use in next http request. I've tried several methods using Xpath Extractor but the Debug sampler shows nothing. I've added XPath_Extractor as a child of HTTP Sampler.
what am I doing wrong here?
Here is what I setup in the XPath Extractor
Reference Name = lstname (which is the variable I carry to next http request)
XPath Query = //*[local-name()='LastName']/text()
also tried
/Reply/CustomerData/#LastName
Main Sample checked
Use NameSpaces- checked
Ingnore whitepspaces checked
Here is my http response
<?xml version="1.0" encoding="UTF-8"?>
<dm:reply xmlns:dm="http://www.xx.com/dm" version="1.0">
<Session>
<TimeDate CurrentDateTime="2015-12-16T08:57:21" CurrentMilliseconds="2881062362"/>
<Reply type="Connection">
<ErrorMessage/>
<ErrorCode>0</ErrorCode>
</Reply>
<TimeDate CurrentDateTime="2015-12-16T08:57:21" CurrentMilliseconds="2881062504"/>
<Reply type="Execute">
<CustomerData FirstName="" LastName="Moni" Address="SD" Chassis="AWD" CountryOfBirth="" CountryOfOriginFullName= Year="2010">
<RecordSet>
</RecordSet>
<ErrorMessage/>
<ErrorCode>0</ErrorCode>
</CustomerData>
</Reply>
<TimeDate CurrentDateTime="2015-12-16T08:57:21" CurrentMilliseconds="2881062590"/>
</Session>
</dm:reply>

You can use regular expression extractor - Post Processor to achieve this.
You need to fill in following parameters
Reference Name: LastName
The regular expression (would look like): LastName="(.*?)"
Template: $1$
Match : 1
Default Value: NotFound
Use ${LastName} in next request to access extracted value of LastName.
Add debug sampler to check if you are extracting correct value.

Why do you need all this namespaces stuff?
Don't check any boxes in the extractor
Use //CustomerData/#LastName as XPath expression
That's it
By the way, you can evaluate XPath Expressions directly against response using XPath Tester mode of the View Results Tree listener. See How to debug your Apache JMeter script article for more tips on getting to the bottom of your JMeter test issue.

Related

Extracted Regex Value not getting passed into next POST request body in Jmeter

In my first request I am able to extract the value using Regular Expression Extractor which is clearly visible into the debug sampler. The value is extracted by setting the following options in Regular Expression Extractor:-
Name of Created Variable:- instanceUID
Regular Expression:- "InstanceUid":"(.*?)"
Template:-$1$
Match No:-1
Default Value:- (Blank)
The value that I want to pass in the next POST request is visible as:-
instanceUID_g1=2ab5dfb8-a217-4ff2-9025-523565b7b7ad
And the body for the next HTTP POST request is set like this:-
${"iInfo":{"InstanceUid":"${instanceUID_g1}","Registry":"${Registry}"}}
When this request seen in detail inside View Results Tree looks like:-
${"iInfo":{"InstanceUid":"${instanceUID_g1}","Registry":"AAX"}}
As seen the value of ${instanceUID_g1} did not get substituted in the POST body as was for variable ${Registry} which was taken from CSV config.
Being new to Jmeter can anyone suggest what did I miss?
Most probably your Regular Expression Extractor placement is not very correct, be informed about JMeter Scoping Rules concept
If you place Regular Expression Extractor as a child of the request - it will be applied to this request only
If you place Regular Expression Extractor at the same level as several requests - it will be applied to all of them
in the latter case it will be applied 1st to 1st sampler, then to Debug Sampler, then to 3rd sampler so on 2nd step it will be overwritten, most probably that's your problem
Also it appears that you're getting the data from JSON so it makes more sense to use JSON Extractor or JMESPath Extractor

JMeter class javax.faces.el.EvaluationException<

Can some one help me fix this issue in JMeter?
I already use my Regular Expression Extractor after editing javax.face
<?xml version='1.0' encoding='UTF-8'?>
<partial-response><error><error-name>class javax.faces.el.EvaluationException</error-name><error-message><![CDATA[See your server log [enter image description here][1]for more information]]></error-message></error></partial-response>
Most probably your regular expression extractor fails somewhere somehow, double check that it is returning the expected value using Debug Sampler and View Results Tree listener combination.
Also using regular expressions might not be the best idea, if you're extracting Viewstate from the HTML response - it might be a better idea to consider using CSS Selector Extractor instead

Unable to correlate value[token], from one sampler to another in JMeter

I have recorded script using BlazeMeter plugin and I want to the use access token which I receive in successful login request, in another request. My Test plan looks like as below
Thread Group : [A]
|- HTTP Sampler - Login Page
|-Regular Expression Extractor [getToken]
|-HTTP Sampler - Other Page
|-Beanshell PreProcessor[Set Header in Authorization]
Regular Expression Extractor parameters and values like below :
Variable Name : token
Regular Expression : {“access_token”:”(.+?)"
Template : $1$
Match No. : 0
Beanshell PreProcessor script like below
import org.apache.jmeter.protocol.http.control.Header;
log.info("Start");
sampler.getHeaderManager().add(new Header("Authorization","Bearer"+vars.get("token")));
log.info(vars.get("token"));
Most probably your Regular Expression Extractor fails as your quotation marks look utterly suspicious. You can double check if the token variable really has the anticipated value using Debug Sampler and View Results Tree listener combination. Also check out jmeter.log file for any suspicious entries, if your Beanshell script fails - the cause will be printed there.
The response data of the Login Page seems to be JSON therefore it makes sense to use the JSON Extractor instead of the Regular Expression Extractor. It allows using JSON Path language in order to extract "interesting" bits of data from the responses. In your case the relevant JSON Path expression would be $.access_token
Since JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for scripting so consider migrating to the JSR223 PreProcessor and Groovy language (you can re-use the same code)
You don't even need the scripting, you can add Authorization header (as well as any other header) using HTTP Header Manager
Could you add debug sampler and try first to confirm your regular expression extractor working as expected? It should provide you the required value of token.
If your token has the required value, I will suggest you to add HTTP Header Manager config element by right clicking on HTTP sampler
HTTP Request => Add => Config Element => HTTP Header Manager
In this config element, you can visually add the Headers as below:
Please Note That:- You have not provided any space/hyphen(-) or between keyword Bear and token.
Refer this link for details :-
https://stackoverflow.com/a/24550552/1115090

JMeter variable not being used in POST request

I am extracting several variables from a login response, using "Regular Expression Extractor" post processors. Most of them work when I reuse the variable, but one doesn't.
The regex extractor has the following settings:
Apply to: Main sample only
Field to check: Body
Name of variable: id_token
Regular Expression: <input type="hidden" name="id_token" value="([^"]+)"
Template:
Match No.:
Default Value:
Use empty default value: (unchecked)
Then in a later POST HTTP request I use the parameter:
Name, Value, URL Encode?, Content-Type, Include Equals
id_token, ${id_token_g1}, true, text/plain, true
When running the test in the "View Results Tree" listener the same POST request's POST data contains
&id_token=%24%7Bid_token_g1%7D
Instead of the value of id_token_g1.
Other variables in the same POST data are being completed correctly.
The Debug PostProcessor from the previous request contains
id_token_g1=eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6IjVEbHphYTlvNEdveWFtWXdLNl9MUS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IK1AKp1BTkQA-kwcqbWIn66Hdjrmepnq3A6nD6pEB-I2tHMgbHIogwHqsGM61OBAGC2y7As3BdF-zepm1m9jISmRX7hiU8u6I1TOhwWIz8VKjlkdmqTQf1lY6I7yAq2Rwtu0zrQ--6el_lB7emX1YvD8whSFpQjI4YNpWJWRZ9ALXC7CudIgN5D4tgzSmEpQrcK-NasXWYf6RMfeDhYTYAbAChgwJ3KwWk6u_5OsX2LgQGbAg23BH9O_9rGg84DTgHM6IMlQG_loX2PnL8B5yqxydbJsz6CBdiLqKg
I have the same issue with session_state_g1
session_state_g1=XZkcgcg9i_FqlFIS-scHuHqMdm5jepyCSSFkF_S4Dx8.99d68c0a8e802c8767d22fb019bd34b5
But not with
access_token_g1=eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6IjVEbHphYTlvNEdveWFtWXdLNl9MUS16akFZTSIsImtpZCI6IjVEbHphYTlvNEdveWFtWXdLNl9MUS16akFZTSJ9.eyJpc3MiOiJodHRwczovL2xvY2FsaG9zdDo0NDM4Ny9pZHMiLCJhdWQiOiJodHRwczovL2xvY2FsaG9zdDo0NDM4Ny9pZHMvcmVzb3VyY2VzIiwiZXhwIjoxNTI5NTA2MzAzLCJuYmYiOjE1Mjk1MDI3MDMsImNsaWVudF9pZCI6ImQ4ZWNmNjMyLWY3MTQtNDYzMS04ZWI5LWViZTMwMjk4Y2MwZiIsInNjb3BlIjpbIm9wZW5pZCIsInByb2ZpbGUiLCJkeW5hbWljY2xhaW1zIiwiZmlsZXN0cmVhbWluZ2FwaSIsInVzZXJtYW5hZ2VtZW50YXBpIl0sInN1YiI6ImU2NWE0M2MwLTllY2EtNDRjYi05YzYzLWU2NjhhMzNhNWQyYiIsImF1dGhfdGltZSI6MTUyOTUwMjcwMSwiaWRwIjoiaWRzcnYiLCJwcmVmZXJyZWRfdXNlcm5hbWUiOiJhbmdlbGFjIiwibG9jYWxlIjoiZW4tR0IiLCJuYW1lIjoiQW5nZWxhIENhdGFsZG8iLCJhdWRpdF9yZWFkX2JpdG1hc2siOiIwIiwiYXVkaXRfd3JpdGVfYml0bWFzayI6IjAiLCJhbXIiOlsicGFzc3dvcmQiXX0.Z2RTMN6NGwC1e8bJANmzvA9rUyo03vCpA3TTNylbdR8EpOvaktgHXHjWCFzxlaXeiL-24DlmVoq3qPHRx0u03nr8ZRD2fb9R_OeHxZ-gVr-2D1Ash1f_429J_4U7zjQfAQSOKHHamzTocSl0orLuvQdc9-oAydPCzpp82UbEDwsnQl_E52dK_LEB4eSiV3sB8rSpmZkmnhCmuSh9iUuMEOmA_zIs2cH_exFWjv5WXbZ8gKR-ATrPNuzoDpghMNZs-Of-dZwsaHfSJpV8C12DQ6wZq-w7m6v2szUpgJh1kHafKzM8Gm8-nMAAPV83hbdALFVvsF9tfcLjin3OEdytsfsfRLDEHLh4E-vo-LyAeHV-TKGuvX60-6tdQsSQXY-egVx1W7NiObmLbFzdRGAiV--tk8QHJ8Vf-nVAT00YXeQxEdMl1lqJFNuNOFxoNXL1ud_frUv1c2xwcnCH0hBpt2avWqN72Bj-15j6uube7IPIVp20NpT0M7FujohB-wQLfVJ8d7Ac_AVNScqasdijpTP5DzmsFybvXAu8n0MEcYHYF0-C8_d0EWW7GxpSEeeVFqKNk7JFgXEo1ta_5Yu7XDpwG7evzMFMw49cImZgcQlxrq3oDnl-qo6r9UXOfvS5QoDILU6dqYUpRSS1-Mz4_JbOmEs78v5ixcrm94PfNis
I have the same problem if I update the name of the HTTP Request sampler (it shows as ${id_token_g1} in the "View Results Tree" listener)
Any ideas what I'm doing wrong?
Make sure your setup is following JMeter Scoping Rules, i.e. you should have setup like:
Open Login Page
Regular Expression Extractor
Perform Login
Make sure you have this hidden input with name id_token in the response data. JMeter can be configured to store response data in .jtl results file, you need to add next 2 lines in user.properties file:
jmeter.save.saveservice.output_format=xml
jmeter.save.saveservice.response_data=true
Don't forget to restore the default configuration once you figure out the cause of the problem. See Results file configuration for more details.
Regular expressions is not the best choice for parsing HTML responses as they can be very fragile in case of markup change (changed order of HTML attributes or the input definition becomes multi-line). So consider switching to CSS/JQuery Extractor instead, the relevant configuration would be something like:
Reference Name: anything meaningful, you can keep id_token
CSS/JQuery Expression: input[id=name]
Attribute: value
In 2nd POST request you can refer the extracted value as ${id_token}
1.Follow Jmeter Scoping Rules.
2.To your regular expression you can give template as $1$ and use ${id_token} instead of ${id_token_g1}.
For more information on regular expression extractors
follow this link.
You can use this website to test your regular expressions.
Let me know if it helps..

Xpath extractor

Can someone help me with this:
I am using xpath extractor of jmeter to retrieve sessionId value from the below response.
I need the value of the sessionId to be stored in some file, so that i can use that value in succeeding calls..My basic response is as below:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:createUserResponse xmlns:ns2="http://www.musicthp.com"
isNewUser="false"
profileId="32109"
sessionId="ryIlb+E5yj7FReA2w96uag=="
success="true">
<duration>316</duration>
</ns2:createUserResponse>`
In order to use the results in a future call, you simply need to use the "Reference Name" as a variable.
If you configure the Xpath Extractor reference name as sessionID, subsequent calls would use ${sessionID}

Resources