I want to store an expression in flow variable and want to retrieve it as same that I stored....
For example :-
<set-variable doc:name="Variable" value="#[xpath('//v1:insertDataRequest/v1:Id').text]" variableName="cacheKey"/>
Here in the flow variable called cacheKey I want to store the expression #[xpath('//v1:insertDataRequest/v1:Id').text] as a String so that if I want to retrieve it such as following
<logger message="#[flowVars['cacheKey']" level="INFO" doc:name="Logger"/>
It should retrieve me the value of #[flowVars['cacheKey'] as #[xpath('//v1:insertDataRequest/v1:Id').text] as a String
But in my case whenever I am trying to store
<set-variable doc:name="Variable" value="#[xpath('//v1:insertDataRequest/v1:Id').text]" variableName="cacheKey"/>
It is extracting the xpath value with current message payload and I am getting the extracted value of xpath from payload instead of getting #[xpath('//v1:insertDataRequest/v1:Id').text]
So, my question is how can I store the value #[xpath('//v1:insertDataRequest/v1:Id').text] as a String in flowVars so that I get exactly #[xpath('//v1:insertDataRequest/v1:Id').text] as flowVars value and not extracted value of xpath
Please help
This should work:
<set-variable doc:name="Variable" value="#['#[xpath('//v1:insertDataRequest/v1:Id').text]']" variableName="cacheKey"/>
EDIT:
Apostrophes should be escaped
<set-variable doc:name="Variable" value="#['#[xpath(\'//v1:insertDataRequest/v1:Id\').text]']" variableName="cacheKey"/>
There is no such thing as an eval that reuses the current context in MVEL, and therefor even if you get to store the value as per ~nuno (or just separating somehow the # from the [, perhaps with string appenders) you won't be able to execute it.
I can't see the big picture of your problem, but with what I can guess I would use rather than this a property placeholder with the expressions you need to be able to customise.
For the part of the questions, where you point that you don't wan't to loose the payload, just use an enritcher, it's designed exactly for that and anyone reading it will quickly understand what you were trying to do.
So finally as Nuno suggested, the working solution is :-
<set-variable doc:name="Variable" value="#['#[xpath(\'//v1:insertDataRequest/v1:Id\').text]']" variableName="cacheKey"/>
You can replace set-variable tag by:
<expression-component>
flowVars.cacheKey = "#[xpath('//v1:insertDataRequest/v1:Id').text]";
</expression-component>
Related
I am trying to get an XML element value out of a string but is doesn't work yet.
Normally i only extract the xpath text values but now i want to get the EAN code of the following string:
<div data-retailrocket-markup-block="60c8602d97a528373cb51d77" data-product-id="8710429017146"></div>
Is this possible? And if so how? Thanks a lot!
This is how my HTML value looks like. Please note, there is a carriage return and space after q1. I only want to extract the number next to q as here it is 1.
<span id="sqa">q1
?</span>
I am using Xpath extractor, and it gives me complete value as can be seen via debug sample. The name of my variable is answer_value. I only wanted 1 which is a dynamic number here, not q. As only this number is used in the subsequent request.
Xpath query I am using is //span[#id="sqa"] and it gives me below value. I am not sure how I can split this value in Xpath or need to use a split function of JMeter to do that?
answer_value=q1 ?
Just add a Regular Expression Extractor and configure it to extract a number from the answer_value JMeter Variable.
Place it below the XPath Extractor and configure like this:
You might also want to apply XPath normalize-space() function to remove eventual line breaks:
normalize-space(//span[#id="sqa"]/text())
Demo:
Problem Statement: in my API response, I am getting same set of xml tag repeated multiple times but with different values of the underlying tags which are also repeating across xml response. Also those two underlying values have mapping to each other. I need to extract all the mappings from response and write them to SQL. I am having trouble with extracting the mapping values from the API response.
I am trying to use regular expression extractor to fetch that repetitive main tag which hold those two values. Then I am trying to use for each loop on the output variable of regular expression extractor. And will then write respective values to target table for each of the iteration.
Following tag is repeating multiple times for each cycle. I need to fetch the two values present under <Value> tag for each of the <Object> tag. For example '{abc-def}' and 'D12345' in this case for this particular instance....and so on.
<Object classId="QueryResultRow"><Property i:type="fn40:SingletonId" propertyId="Id"><Value>{abc-def}</Value></Property><Property i:type="fn40:SingletonString" propertyId="DCN"><Value>D12345</Value></Property></Object>
I am unable to get the required two values from each of the tag while retaining the mapping. Also, I am not sure how to use only one of the generated variable from the output of regular expression as it's creating 4 types of variables for each target xml tag.
objVal=<Object classId="QueryResultRow"><Property i:type="fn40:SingletonId" propertyId="Id"><Value>{abc-def}</Value></Property><Property i:type="fn40:SingletonString" propertyId="DCN"><Value>D112345</Value></Property></Object>
objVal_g=1
objVal_g0=<Object classId="QueryResultRow"><Property i:type="fn40:SingletonId" propertyId="Id"><Value>{abc-def}</Value></Property><Property i:type="fn40:SingletonString" propertyId="DCN"><Value>D12345</Value></Property></Object>
objVal_g1=<Property i:type="fn40:SingletonId" propertyId="Id"><Value>{abc-def}</Value></Property><Property i:type="fn40:SingletonString" propertyId="DCN"><Value>D12345</Value></Property>
I would need to use only objVal from here and I am trying to use
Regular expression extractor
Flow of my Test
For Each loop to extract object tags
second for loop to extract two values out of extracted object tags
use of variable created in 4th step in my jdbc sampler
After you have xml in objVal variable,
Use XPath Extractor using JMeter variable Name to use your objVal variable
Use XPath query as /Object/Property/Value
And if Match No. is -1 you will get all values
objVal_value={abc-def}
aa_value_1={abc-def}
aa_value_2=D112345
allows the user to extract value(s) from structured response - XML or (X)HTML - using XPath query language
You can use the below regular expression to fetch the required values.
propertyId="Id"><Value>(.*?)</Value>(.*)propertyId="DCN"><Value>(.*?)</Value>
The values will be present in the below variables.
objval_1_g0
objval_1_g2
objval_2_g0
objval_2_g2
objval_3_g0
objval_3_g2
objval_4_g0
objval_4_g2
You can use a debug sampler to check the variables value.
I would like to extract a line of strings but am having difficulties using the correct RegEx. Any help would be appreciated.
String to extract: KSEA 122053Z 21008KT 10SM FEW020 SCT250 17/08 A3044 RMK AO2 SLP313 T01720083 50005
For Some reason StackOverflow wont let me cut and paste the XML data here since it includes "<>" characters. Basically I am trying to extract data between "raw_text" ... "/raw_text" from a xml that will always be formatted like the following: http://www.aviationweather.gov/adds/dataserver_current/httpparam?dataSource=metars&requestType=retrieve&format=xml&hoursBeforeNow=3&mostRecent=true&stationString=PHNL%20KSEA
However, the Station name, in this case "KSEA" will not always be the same. It will change based on user input into a search variable.
Thanks In advance
if I can assume that every strings that you want starts with KSEA, then the answer would be:
.*(KSEA.*?)KSEA.*
using ? would let .* match as less as possible.
following is my html table structure and i want to validate the complete text inside td using x-path <tr><td>Sagar Nair<br/><b>Owner</b> - Verified</td></tr>
can anyone help for this.
When the tr element in your example is the current element, then the XPath expression string(.) will have as its value the string you say you would like to validate. For the actual validation of the string you are going to need some language other than XPath; since you don't mention a programming language, however, I assume that once you get the string you know what to do with it.