Capture values using JSON extractor with multiple combination values rules - jmeter

from below response we need to capture
if OrderNumber":{"value":"J-40-000093-VAN0001"} we need capture guid":"26177172834105110*
{"changes":{},"commits":[],"committedObjectsOmitted":false,"deletes":[],"hasMoreItems":false,"newpersistable":[],"objects":[{"attributes":{"_ShowSites":{"value":false},"ICONStatusTime":{"readonly":true,"value":1674457196799},"DeliveryDate":{"value":null},"NativeMobile.Order_DeliveryAddress":{"value":null},"NativeMobile.Order_CustomFlowItems_Temp":{"value":null},"Status":{"value":"Complete"},"RequiredByDate":{"value":1674529200000},"CollectionASAP":{"value":true},"TotalPriceAtOrderSubmission":{"value":"122.42"},"NativeMobile.Order_Checkout_JobOrder":{"value":"68116944363989153"},"DropToCommunalArea":{"value":false},"CustomerReference":{"value":"testing1"},"OrderType":{"value":"JobOrder"},"DeliveryAccessRestricted":{"value":false},"NativeMobile.Order_SGBranch":{"readonly":true,"value":null},"APIAttemptsCount":{"readonly":true,"value":"1"},"Address":{"value":null},"OrderEmailStatus":{"value":"Success"},"_CreatedDate":{"value":1674456764925},"HasAtLeastOneItem":{"value":true},"NativeMobile.Order_UserAccount_Operative":{"value":"66991044457146029"},"CheckInDate":{"value":1674457678401},"NativeMobile.Order_Job_WiderOrder":{"value":null},"RequiresMobileSync":{"value":false},"ICONOrderStatus":{"readonly":true,"value":"Pending"},"TotalOrderPriceAtCheckIn":{"value":"122.42"},"OrderNumber":{"value":"J-40-000093-VAN0001"},"JobNumber":{"value":"jbdemo"},"FulfilmentMethod":{"value":"Collection"},"DeliveryAttended":{"value":null},"OrderAPI":{"value":"ICON"},"CustomerOrderTypeAtSubmission":{"readonly":true,"value":"JobOrder"},"OrderDateSubmitted":{"value":1674456764928},"SubOrderType":{"value":null},"NativeMobile.Order_OrderingEntity":{"value":"31806672368314430"},"ICONAPIStatus":{"value":null},"OrderPostStatus":{"value":"Success"},"isDeletedOnMobileDevice":{"value":false},"OrderNumberInteger":{"value":"93"}},"guid":"26177172834105110","hash":"fh+MfPCaDRjTn9gjdva5Qx5uxU+6lBjGDcmIpFWJ0OY=","objectType":"NativeMobile.Order"},
from below response
if NativeMobile.OrderItem_Order":{"value":"26177172834105120"} and NativeMobile.OrderItem_CustomerProduct":{"value":"28710447624498114"} we need to capture guid":"3659174697251949
{"changes":{},"commits":[],"committedObjectsOmitted":false,"deletes":[],"hasMoreItems":false,"newpersistable":[],"objects":[{"attributes":{"ProductCode":{"value":null},"NativeMobile.OrderItem_Order":{"value":"26177172834105120"},"NativeMobile.OrderItem_DynamicCustomerProduct":{"value":null},"RequiresMobileSync":{"value":false},"AmountMatched":{"readonly":true,"value":"0"},"CheckInQuantity":{"value":"1"},"LineNumber":{"value":"4"},"CheckinPrice":{"value":"1"},"LineStatus":{"value":"Pick note printed"},"ProductName":{"value":null},"isDeletedOnMobileDevice":{"value":false},"OrderQuantity":{"value":"1"},"CheckinQuantityEdit":{"value":"0"},"NativeMobile.OrderItem_CustomerProduct":{"value":"28710447624498114"},"IsDeleted":{"value":false},"_CreatedDate":{"value":1674476500360},"FullyMatched":{"readonly":true,"value":false}},"guid":"3659174697251949","hash":"pzZHRHrMSglxWv+E8I+/1JFXiztj1NRykkEe3mWUhvM=","objectType":"NativeMobile.OrderItem"}
Please help me to capture the guids
Thanks

Wasn't that you who asked an identical twin of this question here? The solution would be exactly the same:
Take a look at JSON Extractor, the relevant JsonPath queries would be:
$.objects[?(#.attributes.OrderNumber.value == 'J-40-000093-VAN0001')].guid
$.objects[?(#.attributes.['NativeMobile.OrderItem_Order'].value == '26177172834105120' && #.attributes.['NativeMobile.OrderItem_CustomerProduct'].value=='28710447624498114')].guid

Related

Dynamic value occurrence changing every time in response

I am trying to capture below value
FullyMatched":{"readonly":true,"value":false}},"guid":"3659174697251659"
and i used below expression
FullyMatched":{"readonly":true,"value":false}},"guid":"(.*?)"
But there is lot of other values with these boundaries and 3659174697251659 value occurrence changing in response every time when replay script in jmeter
Match count: 46
Match[1][0]=FullyMatched":{"readonly":true,"value":false}},"guid":"3659174697251656"
Match[1][1]=3659174697251656
Match[2][0]=FullyMatched":{"readonly":true,"value":false}},"guid":"3659174697251652"
Match[2][1]=3659174697251652
Match[3][0]=FullyMatched":{"readonly":true,"value":false}},"guid":"3659174697251557"
Match[3][1]=3659174697251557
Match[4][0]=FullyMatched":{"readonly":true,"value":false}},"guid":"3659174697251648"
Match[4][1]=3659174697251648
Match[5][0]=FullyMatched":{"readonly":true,"value":false}},"guid":"3659174697251553"
Match[5][1]=3659174697251553
Match[6][0]=FullyMatched":{"readonly":true,"value":false}},"guid":"3659174697251644"
Match[6][1]=3659174697251644
Match[7][0]=FullyMatched":{"readonly":true,"value":false}},"guid":"3659174697251549"
Match[7][1]=3659174697251549
Match[8][0]=FullyMatched":{"readonly":true,"value":false}},"guid":"3659174697251545"
Match[8][1]=3659174697251545
Match[9][0]=FullyMatched":{"readonly":true,"value":false}},"guid":"3659174697251636"
Match[9][1]=3659174697251636
Match[10][0]=FullyMatched":{"readonly":true,"value":false}},"guid":"3659174697251632"
Match[10][1]=3659174697251632
Match[11][0]=FullyMatched":{"readonly":true,"value":false}},"guid":"3659174697251537"
Match[11][1]=3659174697251537
Match[12][0]=FullyMatched":{"readonly":true,"value":false}},"guid":"3659174697251659"
Match[12][1]=3659174697251659
Match[13][0]=FullyMatched":{"readonly":true,"value":false}},"guid":"3659174697251655"
Please help me to handle this occurrence changing issues in response
It looks like you're trying to extract a value from JSON
JSON is not a regular language therefore it's not the best idea to use regular expressions
Consider switching to JSON Extractor, it provides much more powerful, robust, readable and reliable way to fetch the "interesting" data from JSON using JSONPath language.
Going forward consider including the full response, it's not possible to guess how does it look like from what you posted.

How to remove special characters, string , number from regax

I have. done paramerization in recorded requests in jmeter , when i rerun it some requests. are failing but i have done capture variables and pass to
next requests but there is issue
format ofresponse is changing dynamically
my regax - stateToken":"(.+?)"
\x2D is. additionalpart is coming some time so i need re write regax to remove this when we getting that
Fail Case
002KljInsq318mkPTkDTuJ06eLSxIQmVga\x2DSuvHmDe
{"stateToken":"00UaBoY\x2D81AIL32Nz9qmUJrIarSv3OgfUdd8FHGSkb"}
{"stateToken":"003LYZGSYKn3io1ocOwCBNcp2I\x2Dt8UbkdBfruaC6C0"}
{"stateToken":"00C8O4pt\x2DcSPEzHrt69zqmEGta9KbjdwywEVdkICku"}
{"stateToken":"00JgMsy7\x2DzXDP0gxaeWv4dj8EguFTWtnLxV\x2DBKTkIq"}
Working
{"stateToken":"00fswJVHKpW7dNhNVK0bRclBBrsuMLHBBevJ8IS1Wz"}
{"stateToken":"00ZVZXpSJn7v3lxNTrEqy1mAGydgroO5apvoTlWH2u"}
any ideas ?
It looks like your application has a functional issue, if it returns the token which cannot be used for authentication is sounds like a bug so instead of trying to implement a workaround in JMeter you should report it as it needs to be fixed.
JSON is not a regular language hence using regular expressions for extracting data from it is not the best idea, I would recommend considering using JSON Extractor or JSON JMESPath Extractor instead
If you still want to bypass the intermittent issue with tokens and remove the problematic element from the token (I repeat I doubt real user of your application will do this) you can do it using a suitable JSR223 Test Element and the code like:
def before = vars.get('token')
log.info('Before: ' + before)
def after = before.replace('\\x2D','')
log.info('After : ' + after)
vars.put('token', after)
Demo:

How to correlate different values in a RegEx with multiple matches with JMeter- Correlation Recorder?

I have a problem in JMeter that I can't figure out how to solve.
Situation:
I want to load test an ASP.NET-website.
bzm - Correlation Recorder used for recording and correlation
ScriptResource and WebResource have multiple occurrences
Now I used following RegEx to extract the ScriptResource values: <script src="(.+/ScriptResource.+?)". Then I stored the 3 matched values into 3 different variables. But I can't replace the values in the found order.
Example:
First Match: stored in : AspNet_ScriptResource
Second match stored in: AspNet_ScriptResource_1
Third match stored in: AspNet_ScriptResource_2
The three matches have all different values, can't paste one value into all 3 matches.
So I have to write the value from AspNet_ScriptResource into the first match (matchNr=1).
AspNet_ScriptResource_1 into second match (matchNr = 2) and
AspNet_ScriptResource_2 into third match (matchNr = 3).
But in the Correlation Rules (in the Correlation Recorder) in the "Correlation Replacement" section, there is no option to choose in which matchNr to write.
Correlation Recorder: Correlation Rules
I tried to use a BeanShell Preprocessor with a for-loop but I only found a way to write in the logs, not in the response body.
Is there a way to solve this with the Correlation Recorder plugin? If not, what options do I have to handle such a scenario?
Thanks for your help! :)
You can raise an enhancement request for the bzm - Correlation Recorder via JMeter Plugins support forum or if you're a BlazeMeter customer and need this piece of functionality asap - you can open a support ticket for implementation of the feature.
Currently it seems that the Correlation Recorder expects you to provide a regular expression either with the unique match or you will have multiple substitutions with the same value.
With regards to Beanshell approach:
You can substitute response data, but not with the PreProcessor, you need to do this via the PostProcessor using prev.setResponseData() function
Since JMeter 3.1 you're supposed to be using JSR223 Test Elements and Groovy language for scripting
If you need to change request data, not the response data, you can do this via sampler.getArguments() function

Json assertion with condition

I have a json key 'total' in api response, which will return values on condition. Need to assert if response value is >= 0 and 0. Please suggest a simple way to achieve this.
I have already tried Json assertion which is not of much help.
I expect 'total' to contain a value greater than 0 (zero) at certain time and 0 (zero) at certain time.
Use the below regEx to fetch the values:=
total=\d+
Put it in Regular Expression Extractor postprocessor.
It will fetch only 0 or any positive number else not found. Now, put if controller to work further with your scenerio.
Hope this helps.
Update:- Put assertion to check if the response contain the required parameter,if yes it will pass else fail. So, if negative then it will fail.
In this, you dont need to put regular expression extractor as you can put expected regEx directly in response assertion.

Handling Dynamic Xpath

Am automating things using Selenium. Need your help to handle Dynamic Xpath as below:
Driver.findElement(By.xpath("//[#id='INQ_2985']/div[2]/tr/td/div/div[3]/div")).click();
As above INQ_2985 changes to 2986,2987,2988 etc during each run
HTML CODE:
< div> class="context-menu-item-inner" style="background-image:url(../images/productSmall.png);">Tender Assignment < /div>
Tried different combinations as below but with no success:
// Driver.findElement(By.name("//input[#name='Tender Assignment']")).click();
// Driver.findElement(By.className("context-menu-item-inner")).click();`
Can you help me on this.
you can try using contains() or starts-with() in xpath,
above xpath can be rewritten as follows,
Driver.findElement(By.xpath("//*[starts-with(#id,'INQ')]/div[2]/tr/td/div/div[3]/div")).click();
if you can post more of your html, we can help improve your xpath..
moreover using such long xpath's is not recommended, this may cause your test to fail more often
for example,if a "new table data or div" is added to the UI, above xpath will no longer be valid
you should try and use id, class or other attributes to get closer to the element your trying to find
i personally recommend using cssSelectors over xpath
you can use many methods,
use implicity wait;
driver.findElement(By.xpath("//*[contains(#id,'select2-result-label-535')]").click();
driver.findElement(By.xpath("//*[contains(text(), 'select2-result-label-535')]").click();
Good to use Regular expression
driver.findElement(By.xpath("//*[contains(#id,'INQ_')]")
Note: If you have single ID with name starts from INQ_ then you can take action on the element . If a bunch of ID then you can extract as a List<WebElements> and then match with the specific text of the element ( element.getText().trim() =="Linked Text" and if it matched then take action. You can follow other logic to traverse and match.
you can use css -
div.context-menu-item-inner
Use this xpath:
driver.findElement(By.cssSelector("div.context-menu-item-inner").click();
The best choice is using full xpath instead of id which you can get easily via firebug.
e.g.
/html/body/div[3]/div[3]/div[2]/div/div[2]/div[1]/div/div[1]
if your xpath is varying
Ex: "//*[#id='msg500']" , "//*[#id='msg501']", "//*[#id='msg502']" and so on...
Then use this code in script:
for (int i=0;i<=9;i++) {
String mpath= "//*[#id='msg50"+i+"']";
driver.findElement(By.xpath(mpath)).click();
}

Resources