How to extract complete Product name using regex or x-path - jmeter

I have an Html page which contains many script tags and inside each script tag I have a structure like:
<script>window.pagedata={listItems:[{"name": "Multi-Warna Lembut Silikon Casing Ponsel Untuk Apple iPhone 11 Case 11 Pro Max Tidak Berbau dan Tidak Beracun Casing iPhone 11 pro-Max"}]}</script>
My goal is to extract all the name from this script tag using a regex or a x-path in JMeter.

You can extract name using below regular expression. Please note that if your requirement is to extract any one product name from response (assuming you have lot of product names in response), you can put match No. as "0" (which selects randomly). Else, if you need product name which comes at first occurrence, you can define match no as "1".
Regular Expression : \{"name": "(.*?)"\}
If your goal is to extract all names, then please use "-1" in match No. Variable substitution will be ${name_1}, ${name_2} ..etc;

You can use regulare expression extractior post processor and refer to the regex as shown below.
Result:

Add Regular Expression Extractor as a child of the request which returns the names, you're looking for
Configure it as follows:
Name of created variable: anything meaningful, i.e. name
Regular Expression: {listItems:\[{"name":\s*(.+?)"
Template: $1$
Match No: -1
That's it, you should be able to access the extracted values as ${name_1}, ${name_2}, etc.
Demo (assumes Dummy Sampler to mimic multiple products)
More information: JMeter Regular Expressions

Related

XPath to be precised into one in order to extract text from a web page?

I have a few Xpaths as below:
//*[#id="904735f0-bb82-11ea-a473-6d0f51688222"]/div/p
//*[#id="729c0860-a71d-11ea-b994-53a3e91a35c2"]/div/div/div[1]/div/p
//*[#id="2555ab30-bb84-11ea-9e8b-277e7f6208b2"]/div/div/div[1]/div/p
//*[#id="7e100250-a71d-11ea-b994-53a3e91a35c2"]/div/div/div[1]/div/p
//*[#id="811727d0-a71d-11ea-b994-53a3e91a35c2"]/div/div/div[1]/div/p
All of the above are used to extract text from a single web page since text is located at different view--ports, but I wish to find a single xpath to extract text for all of them. Is it possible to use 'and' and multiple ID's to extract all of it through one xpath?
Any other suggestions would be appreciate.
You can use the or operator for the last four.
And the merge-nodes operator | to add the first one.
So to select all 5 expression in one, use the following expression:
//*[#id="904735f0-bb82-11ea-a473-6d0f51688222"]/div/p | //*[#id="729c0860-a71d-11ea-b994-53a3e91a35c2" or #id="2555ab30-bb84-11ea-9e8b-277e7f6208b2" or #id="7e100250-a71d-11ea-b994-53a3e91a35c2" or #id="811727d0-a71d-11ea-b994-53a3e91a35c2"]/div/div/div[1]/div/p
A shorter and more generic solution could be :
(//div/div/div[1]/div/p|//div/p)[parent::*[string-length(#id)=36 and substring(#id,24,1)="-"]]
First part with () is used to specify the end of the path. Since #id attributes have the same length, we use it inside the predicate. We also verify the presence of a - at a specific position with substring.

How to get the required value from the existing value when there is no suffix?

I'm trying to use regular expression extractor concept in Jmeter. By using regEx concept I'm able to get the required token id's. And for all I'm using regEx as (.*?). So this is working fine when we have constant prefix and suffix text/values.
But in this case, there is no suffix,
Ex: Key is = #bluerelay.com/a43a816dcdd14873bd5757b3a3709d5c,
ClickHereForImageForm
I want to take the key ID into a variable with using RegEx. I have tried to get it with (.*?) but it didn't work, it returns the full value, not the required part. It'd be excellent if you could give any suggestion.
The source value is:
https://navitus-internal-app.bluerelay.com/#/token/systemadministrator#bluerelay.com/a43a816dcdd14873bd5757b3a3709d5c
The expected result is to extract a43a816dcdd14873bd5757b3a3709d5c from the above URL and put it into a variable.
You can use regex to get last text after / sign
(.*)\/(\w+)
See demo

Jmeter Regular Expression Extractor not giving results

I have recorded a workflow in Jmeter using Recording controller.
In that workflow, a URL parameter 'member_id' get generated and appear in URL.
This 'member_id' is getting used further in the workflow.
In the recorded script, value of 'member_id' is saved in a variable. Screenshot
Here the problem is; When I execute the scripts, then instead of newly generated 'member_id', the saved value is getting used in the later samples.
I want to fetch the new value and update the saved value, so that it can be used in later samples
I have tried to fix this issue by fetching the 'member_id' from the URL and save it in a variable
I have tried 'Regular Expression Extractor' but I am not able to read the value.
Screenshot
But when I print the response, I am getting only first digit of new 'member_id'.
Screenshot
You're using wrong regular expression, it stops whenever it finds the first match
According to the JMeter documentation on Regular Expressions:
( and ) these enclose the portion of the match string to be returned
. match any character
+ one or more times
? don't be greedy, i.e. stop when first match succeeds
So the solution will be to remove the question mark from your regular expression:
member_id=(.+)
or even better, if you're looking for numbers you should limit your search criteria to digits only like:
member_id=(\d+)
References:
Using RegEx (Regular Expression Extractor) with JMeter
Perl 5 Regex Cheat sheet

Need help in building a regular expression

Need help on building a regular expression to extract the value "2:_id93" and the uid. Here there are multiple sets of data with different status. How ever, i would like to search for the values corresponding to "In Update"
In Update
Can you try the below regular expression?
In Update(.*?)policytableId:(.*?)',null,\[\['uid','(.*?)'
Add Regular Expression Extractor as a child of the request which returns the above data
Configure it like:
Name of created variable: anything meaningful, i.e. id
Regular Expression: In Update.*searchResults:policytableId:(.+?)'
Template: $1$
That's it, you should be able to access the extracted value as ${id} where required.
Demo:
More information:
JMeter: Regular Expressions
Using RegEx (Regular Expression Extractor) with JMeter
Perl5 Regex Cheat Sheet

How to extract the response using a regular expression for Jmeter?

How can I extract the response using a regular expression for Jmeter.
Jmeter is not extracting the response item that I want to extract. I've tried several times, but I failed. How can I extract the response item?
Response data is as shown in the screenshot:
The value which I need to extract has been highlighted.
I tried extracting using the following expression, but it failed:
<h2>.+?<a hfref="http://(.+?)">.+?</a>.</h2>
Please follow the below steps to extract the Id value.
In your Regular Expression Extractor, configure below details. Use the regular expression as Public/FormsPreview.aspx\?Id\=(.+?)& to retrieve the Id.
You can use other unique left/right boundaries as well, as your regular expression.
How to validate your regular expression extractor?
To validate your regular expression extractor, add a Debug Sampler (Right Click on your thread group > Add > Sampler > Debug Sampler)
Execute the test plan
In View Results Tree you can see the c_ID value as shown below.
Depending on how vary can result be (I mean, how the form is changing? is that only querystring Id parameter that is different? could there be another response (than Object Moved) with Id that you don't want to parse? etc.), the regular expression in the Regular Expession Extractor Post-Processor (which fits best here) would be different.
From simplest context-agnostic, Id=(\d+) (that is considering you have numeric Id), to making it case-insensitive (?i)Id=(\d+) and/or alphanumeric Id=([0-9a-zA-Z]+), or even whatever symbols are in (but you'd be forced to start to include context in this case ) Id=(.+?)& - and up to one that uses broader context evaluating the whole multiline stuff, like (?im)<title>Object\smoved</title>.+<a\shref=.+Id=(\d+)
And don't forget to use $1$ as your Template and take the Match 1.
I suggest you to stick to the most narrow and most context-agnostic one you can afford (the very first example here).
Add some assertions to make sure you're on the right page - despite the fact they executed after post-processors, you'd see something is wrong, at least.
You can add regular expression extractor like following

Resources