Using selenium rc java for checking json respose - selenium-rc

I want to test my json response using selenium rc (java) and to print all the response which has garbage value
My json response is as follows :
{"date":"2012-03-02","data":[{"id":17,"Level":4,"Status":1},{"id":128,"Level":4,"Status":0},{"id":13,"Level":5,"Status":1},
So i would like to know how i can use selenium id to check the above mention scenario

Well, some pointers to help you gt the answers..there was a captureNetworkTraffic flag in RC that needs to be set while starting selenium instance. Then use a selenium function to capture the traffic. Then use a JSON library to parse the JSON and do string comparison for garbage value (depending on what you consider as garbage value :) )
You can search for captureNetworkTraffic usage and then a json library for the language that you plan to use.

Related

How to write xpath assertion for the xml in Jmeter

I am using Jmeter to test the api transaction
Response:
<ProcessByAcctResult><Inquiry.IVR.OUT TraceId="1233"><ResponseCode>00</ResponseCode&gtgt;</Inquiry.IVR.OUT></ProcessByAcctResult>
My Response is given above..
I wanted to assert responseCode is 00 if not should make it fail on the performance test. How to write a xpath for this.. or else any other way also fine..
Currently i am storing the variable using Regex Extractor and REsponse Assertion to compare the value.. Any other better solution
What you provided is not a valid XML therefore you're only limited to Response Assertion configured like:
More information: Response Assertions in JMeter 3.2 - New and Improved
However if you're getting a real XML just not able to properly copy and paste it and your response actually looks like:
<ProcessByAcctResult>
<Inquiry.IVR.OUT TraceId="1233">
<ResponseCode>00</ResponseCode>
</Inquiry.IVR.OUT>
</ProcessByAcctResult>
Then you can use the following XPath Assertion configuration:

Unable to send object value in next request json body

I am trying to send object value based on condition to the previous request.
From above,pricecheck i will get formtype value based on form type validation i have to send guests info in request..
here i am able to validate but not able to pass the object value if i try any string i can able to do,please help me.
You need to put a string value in vars, surrounded with quotes " and escape inner quotes\",as
vars.put("guests", "{ \"title\":\"Mr\", .... }");
You're violating 2 major best practices:
You're referring JMeter Variables like ${form} in the JSR223 Test Elements while you should be using vars.get('form') construction instead
You're using JavaScript language which is a performance anti-pattern, since JMeter 3.1 you should be using Groovy language for scripting
Check out Parsing and producing JSON article to learn more about reading and generating JSON in Groovy.
Also posting code in form of screenshots is not something you should be doing otherwise the chance of getting a comprehensive answer will be much less

JMeter, How to encrypt whole bodydata in HTTP Request Sampler?

I'm using jmeter 5.0 to test my web application.How to encrypt the whole bodydata using AES before post ?
I've tried to do it with BeanShell PreProcessor,but it seems there is no method to reset the bodydata,what I found is how to print the bodydata.
log.info("test");
String bodydata = sampler.getArguments().toString();
log.info(bodydata);
I've aleardy known how to implement the AES funtion by importing a java calss.What I expect is resetting the bodydata of plaintext to encrypted text.
Put in body data just a JMeter variable as ${encryptData}
And in preprocessor set the variable with your encrypted value:
vars.put("encryptData", encryptData)
There is Arguments.removeAllArguments() function which clears the sampler body
You can add the new body via Arguments.addArgument() function. Example code:
sampler.getArguments().removeAllArguments();
sampler.addNonEncodedArgument("","your_encrypted_data_here","");
sampler.setPostBodyRaw(true);
Since JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for scripting mainly due to the fact that Groovy has much better performance comparing to Beanshell. So consider migrating to JSR223 PreProcessor on next available opportunity, the same code should work fine.
Under your "HTTP Request" add an "User Defined Variables" (empty values), Make sure as well to key in ${inputJson} in the "Parameters" text field in the "BeanShell PreProcessor" Element.

Change Response Data in View Results Tree Jmeter

I try to make load testing using protobuf protocol. The incoming response has a binary format and not readable in View Result Tree (VRT), kinda:
But I can to convert this hell to the readable format like normal String in the BeanShell PostProcessor.
The question is is there any way to change the information which is showing VRT?
Used prev.setResponseData() and prev.setMessageData() - do not work.
UPDATE:
ok it`s work with prev.setMessageData() but the messages is visible on Sampler result tab:
Use SampleResult.setSamplerData()
Example:
prev.setResponseData( decodedString);
prev.setDataType( org.apache.jmeter.samplers.SampleResult.TEXT );

JSR223 Postprocessor to parse json in jmeter

I have used BSF Postprocessor to parse json in one of my jmeter test files. My code is as follow.
eval('var response = '+prev.getResponseDataAsString());
vars.put("userAccountID", response.ID);
But i have found that BSF post processor reduces Jmeter's performance. So i am going for JSR223 Post processor. I need to know what is the corresponding code for above in JSR223 (JAVA language). Thanks in advance;
I suggest to use jsr223 assertion and javascript. Then you can just simply check and parse your data. for example:
var response = SampleResult.getResponseDataAsString();
var jsonOutput = JSON.parse(response);
Now you can simply operate on "jsonOutput".
#UPDATE#
Looks like in new JMeter version using javascript is deprecated because of performance and lack of options to manipulate data.
(Back then when i was test developer my example had been working just fine; thats why i show it here)
Probably better option is to migrate to Groovy:
http://michalsi.github.io/performance-tests/2018/01/08/jmter-working-with-json.html
There is no out-of-box support of JSON in Java SE hence sample code will depend on JSON library for Java you choose.
May I suggest take a look at JSON Path Extractor Post Processor instead? It is designed to parse JSON data and doesn't require any scripting.
For more information on the JSON Path Extractor see Using the XPath Extractor in JMeter guide (scroll down to "Parsing JSON" section)

Resources