How to read json file into jmeter using Random csv config - jmeter

To read this data into jmeter random csv config data.
Sample Json is as below :
{
"key": "COMMUNICATIONS",
"id": "72ec45ba-f0a1-11e9-81b4-2a2ae2dbcce4",
"description": "6666666666666666.",
"name": "***********************",
"overview": "*************.",
"subCategories": [
{
"key": "PHONES_VOIP_TROUBLESHOOTING",
"id": "72ec46e6-f0a1-11e9-81b4-2a2ae2d",
"description": "fix my phone network as it is down.access my voicemails",
"name": "Phones/VOIP troubleshooting",
"overview": "fix my phone network as it is down.access my voicemails",
"support": "Windows, MAC"
}
]
}

Store the data you want into i.e. test.csv file in JMeter's "bin" directory like:
COMMUNICATIONS,72ec45ba-f0a1-11e9-81b4-2a2ae2dbcce4,6666666666666666,***********************,*************.,PHONES_VOIP_TROUBLESHOOTING,72ec46e6-f0a1-11e9-81b4-2a2ae2d,fix my phone network as it is down.access my voicemails,Phones/VOIP troubleshooting,fix my phone network as it is down.access my voicemails,Windows, MAC
Add Random CSV Data Set Config to your test plan and configure it as follows:
Filename: test.csv
Variable Names: key,id,description,name,overview,subKey, subId,subDescription,subName,subOverview,support
other fields can be left intact
Once done you can click Test CSV Reading button and you should see generated JMeter Variables names along with respective values
Now you can parameterize your JSON payload in HTTP Request sampler and replace hard-coded values with the JMeter Variables names:
{
"key": "${key}",
"id": "${id}",
"description": "${description}",
"name": "${name}",
"overview": "${overview}",
"subCategories": [
{
"key": "${subKey}",
"id": "${subId}",
"description": "${subDescription}",
"name": "${subName}",
"overview": "${subOverview}",
"support": "${support}"
}
]
}
That's it, when you run your test you will see that JMeter Variables are replaced with the values from the CSV file in the runtime using i.e. View Results Tree listener
Going forward just add more entries to the test.csv file so each JMeter Thread (virtual user) could pick up a random value on each iteration.
See Introducing the Random CSV Data Set Config Plugin on JMeter article for more details.

Related

How to update the multiple file names in request from csv file using Jmeter

We have a POST api and we can send multiple files in a request.
I created a csv file with all file Names. Its updating same filename each json object.
How can i get the unique filename in json object from csv? Or is there any approch to get unique files from a file?
Request:
[
{
"filePath": "Filename1",
"orgId": "org123",
"Domain": "abcd.com",
},
{
"filePath": "Filename2",
"orgId": "org123",
"Domain": "abcd.com",
},{
"filePath": "Filename3",
"orgId": "org123",
"Domain": "abcd.com",
},{
"filePath": "Filename4",
"orgId": "org123",
"Domain": "abcd.com",
},{
"filePath": "Filename5",
"orgId": "org123",
"Domain": "abcd.com",
}
]
I don't think it's possible using CSV Data Set Config, it reads next line on each iteration of each virtual user (or according to Sharing Mode setting), but none of the Sharing Modes allows reading multiple lines in a single shot, moreover you need to pass them into single request somehow.
If you need to create one section like this:
{
"filePath": "filename from CSV here",
"orgId": "org123",
"Domain": "abcd.com",
}
per line in the CSV file you could do this using JSR223 PreProcessor and the following Groovy code:
def payload = []
new File('test.csv').readLines().each { line ->
payload.add([filePath: line, orgId: 'org123', Domain: 'abcd.com'])
}
vars.put('payload', new groovy.json.JsonBuilder(payload).toPrettyString())
generated JSON could be accessed as ${payload} where required
You can create multiple variable names under CSV Data Set Config element(for FileName1,FileName2..etc)and use them.

Jmeter - How to extract value from the request (not response) using RegEx

I have JSON request as following:
{
"type": "SIGNUP",
"data": {
"userAccountInfo": {
"email": "ta0620050706#gmail.com",
"password": "qweQwe123!"
},
"userAddressInfo": {
"country": "United States"
},
"userPersonalInfo": {
"firstName": "test",
"lastName": "test"
}
}
}
How can extract ta0620050706#gmail.com from the following request, considering the value of the email is always dinamic?
Any help is appreciated!
If you're talking about HTTP Request sampler and the above JSON is in the "Body Data" tab like:
You can extract the email by adding a JSR223 PreProcessor and using the following code there:
vars.put('email', new groovy.json.JsonSlurper().parseText(sampler.getArguments().getArgument(0).getValue()).data.userAccountInfo.email)
It will extract the value you're looking for and store it into ${email} JMeter Variable
More information:
Apache Groovy - Parsing and producing JSON
Apache Groovy - Why and How You Should Use It

SonarQube 5.5 API - componentKey convention

I'm trying to extract coverage data from our SonarQube instance using the 'api/measures/component' endpoint. This is for a multi module java project. Using POSTMAN i can query for a single java file using a 'componentKey' which is build up of string like this
[maven-groupId]:[maven-artifactId]:[path to java file]
which generates a string like
com.i.pc.e.components.o:om-wf-e:src/main/java/com/i/e/o/wf/actions/Xxxx.java
and returns this json response
{
"component": {
"id": "AVci_6G7elHqFlTqG_OC",
"key": "com.i.pc.e.components.o:om-wfl-e:src/main/java/com/i/e/o/wf/actions/Xxxx.java",
"name": "Xxxx.java",
"qualifier": "FIL",
"path": "src/main/java/com/i/e/om/wf/actions/Xxxxx.java",
"language": "java",
"measures": []
},
"metrics": [
{
"key": "coverage",
"name": "Coverage",
"description": "Coverage by unit tests",
"domain": "Coverage",
"type": "PERCENT",
"higherValuesAreBetter": true,
"qualitative": true,
"hidden": false,
"custom": false,
"decimalScale": 1,
"bestValue": "100.0",
"worstValue": "0.0"
}
]
}
This is fine for a one-off request but I need to do this for a number of Java source files and I won't have the Maven details to hand.
Is there a convention or documentation on the format of the 'componentKey'?
Ideally i'd like to define the full package and java source file name in the 'compomentKey' or is there a way to look up the 'componentId' via some other REST API call?
Use the components service to iterate through your tree (or sub-trees within your tree) starting from your project and feeding your sonar.projectKey value into the baseComponentKey parameter. Pay particular attention to the strategy parameter, which determines what sub-set of children a call retrieves.
Once you have the data on each child, it should be simple to iterate through them to get their measures.

Cucumber: read a template with placeholders

I am writing a cucumber framework to test a set of API calls which use long JSON formatted parameters. I would like to hide the JSON in a template file in order to make the scenario easier for my users to read and DRYer, in that the templates may be used by other scenarios and feature files. The templates contain placeholders and I would like to rig the cucumber/ruby code to fill in the values defined in the table of examples. It appears that ERB is the closest thing to doing the replacement. However, I have not found a way to bind the definitions from the table of examples.
It may be that the only way around this is to run the feature file and template through a pre-processor which combines them and manufactures the final feature file. I am looking for a more elegant single step solution, if possible.
Example feature file code:
Feature: Create users
Scenario Outline: Test create a merchant user
Given I am logged in
When I send a :post request to "createUser" using the "Merchant" template:
Then the JSON response should have "$..status" with the text "success"
Examples:
| OrgName | KeyName | KeyValue |
| CClient_RMBP_0_UNIQ_ | paramX | TRUE |
| CClient_RMBP_1_UNIQ_ | paramY | some text |
| CClient_RMBP_2_UNIQ_ | paramZ | 12345 |
Sample Merchant.json File:
{
"Organization": {
"parameters": [
{
"key": "orgName",
"value": {
"value": "<OrgName>"
}
},
{
"key": "<KeyName>",
"value": {
"value": "<KeyValue>"
}
}
]
},
"parentOrganizationId": "1",
"User": {
"firstName": "Mary",
"lastName": "Smith",
"id": "<OrgName>",
"language": "en",
"locale": "US",
"primaryEmail": "primary#mailaddr.com",
"cellPhone": "1-123-456-7890"
},
"active": "true"
}
I prefer to hide any notion of the response format from the cucumber steps.
Instead i'd prefer to have the steps at a higher level and have validate methods within the step definitions.
e.g.
When I attempt to create a user using the <type> template
Then the response is successful and contains the user's details
and in my step definition I would have a validate_response method which grabs the last response and checks the user details against the input.

Parse response from a "folder items" request to find a file

Using the v2 of the box api, I use the folder items request to get information on files in a folder: http://developers.box.com/docs/#folders-retrieve-a-folders-items
I'm looking at trying to parse the response data. Any ideas how I can do this in bash to easily find a file in the user's account? I would like to find the name of the file where I can get the ID of the file as well.
response looks something like this:
{
"total_count": 25,
"entries": [
{
"type": "file",
"id": "531117507",
"sequence_id": "0",
"etag": "53a93ebcbbe5686415835a1e4f4fff5efea039dc",
"name": "agile-web-development-with-rails_b10_0.pdf"
},
{
"type": "file",
"id": "1625774972",
"sequence_id": "0",
"etag": "32dd8433249b1a59019c465f61aa017f35ec9654",
"name": "Continuous Delivery.pdf"
},
{ ...
For bash, you can use sed or awk. Look at Parsing JSON with Unix tools.
Also if you can use a programming language, then python can be your fastest option. it has a nice module json http://docs.python.org/library/json.html. It has a simple decode API which will give a dict as the output
Then
import json
response_dict = json.loads(your_response)
I recommend using jq for parsing/munging json in bash. It is WAY better than trying to use sed or awk to parse it.

Resources