I am generating Jmeter's jmx file from a swagger definition, the JMX and test data CSV that gets generated seems pretty useless, it has no parameter information as to what the API expected, no http status code to response mapping information etc.
You can take any definition file, to reproduce this:
go to http://editor.swagger.io/#/
open any example from the file menu
From the generate client menu, click on Jmeter
What I expected was a JMX with the entire skeleton of the API so that the QA people don't have to worry about that and focus only on tests.
All the clients that I produce for other languages/tools are good enough to go except Jmeter, am I doing anything wrong here?
I generated JMeter (JMX) for different APIs and I got it to work, though a few issues and caveats.
First it generates
User Defined Variables to substitute in Host, Port, testCases, csvFileName
a JMX per API
a Thread Group per Method (POST, GET, .. )
a HTTP Header Manager per thread group, blank but useful to be in there.
HTTP Sampler for each request
Loading of CSV Data for filling parameter values
HTTP Status Assertion which is validated on error code defined in CSV file
Caveats and Issues
It does not keep your host from config, it replaces with local host. You must change it or pass it in via command line
It uses a default port of 8080, this caused me some grief as well.
The loop count is controlled by variable, testCases. However there is a bug in swagger-code-gen template for JMeter if you want to pass this in via the command line
testCases variable has a bug in the template it defines testCases as ${__P(host,10)} but it should be ${__P(testCases,10)}
GET Parameters are fill with 0 instead of ${variable_name}, this is from the template in swagger codegen. I have a fix in my fork that I have tested. The other option is just to fix it in the JMX file
Original
And after editing Parameters
Example Swagger that works
The following is the Swagger file I used (modified from echo) and the generated (with modification for Parameters) JMX. I have tested this JMX using RedLine13 Example Test and passing the parameters as required. Passing in parameters
-JtestCases=50
-Jhost=mazimi-prod.apigee.net
-Jport=80
And here is the example Yaml
---
swagger: '2.0'
info:
version: 1.0.0
title: Echo
description: |
#### Echos back every URL, method, parameter and header
Feel free to make a path or an operation and use **Try Operation** to test it. The echo server will
render back everything.
schemes:
- http
host: mazimi-prod.apigee.net
basePath: /echo
paths:
/{id}:
get:
parameters:
- name: id
in: path
description: ID
type: string
required: true
- name: user
in: query
description: name
type: string
required: true
- name: location
in: query
description: location
type: string
required: true
responses:
200:
description: Echo GET
Updated JMEter template in Swagger CodeGen
Since there are a few issues for making this work seamless within SwaggerCode Gen i created an issue and pull request. If you need to use it sooner the fork is over here https://github.com/richardfriedman/swagger-codegen/commit/5aff601eaccf67ec44bb681816d40a25e5aa20a3
Related
this may be trivial question, but I am having problems understanding server variables and how to modify them on swagger.
My objective is to create a server using the specs below (5G 3gpp definitions for of its interfaces).
https://www.3gpp.org/ftp/Specs/archive/OpenAPI/Rel-16/TS29122_PfdManagement.yaml.
As you can see at the top of this file we have a server variable called apiRoot which defines the root of the url of the server. That is set up to default value of example.com. That url will later be used by swagger-ui to provide a graphic interface to the API.
servers:
- url: '{apiRoot}/nnef-eventexposure/v1'
variables:
apiRoot:
default: https://example.com
description: apiRoot as defined in clause 4.4 of 3GPP TS 29.501
I am trying to generate the server with the swagger-codegen which generates a consolidated file with all the elements this spec needs (since the original yaml file contains references to other files)
swagger-codegen generate -i https://www.3gpp.org/ftp/Specs/archive/OpenAPI/Rel-16/TS29122_PfdManagement.yaml -l go-server -o server
The problem is the file embeds the default value. So I can not use that file on multiple hosts.
Is there any way to modify variable apiRoot when executing swagger-codegen? Or even better, is there any way to change the value of the default using some kind of envar? Or is there any way to pass swagger the value of apiRoot
The idea is we can use the same specs in different servers without having to modify the original spec file or the generated one. The problem with modifying the yaml files is that there will be more versions comming from 3gpp which will include apiRoot variable, so we don't wang to keep modifying every single time. We would like to overwrite it somehow on runtime.
I'm trying to inject file content into the request body:
I'm using:
${__FileToString(${__eval(${bundle})},,)}
I've configured the bundle variable using the directory listing plugin:
When I perform the test, I'm getting:
Logs is getting me:
2021-12-28 16:33:53,853 WARN o.a.j.f.FileToString: Could not read open: /patient-bundle-0193.json
According to my configuration, __FileToString should read from /home/jeusdi/projects/workarea/salut/mpi/jsons/bundles/extractions/10000/bundles instead from /...
Any ideas?
Tick Use full path so your bundle JMeter Variable would contain the absolute location of the file.
Be informed that JMeter Variables along with their respective values can be visualized using Debug Sampler and View Results Tree listener combination.
You might also be interested in Introducing the Directory Listing Config Plugin on JMeter article
I'm using JMeter v3.2 and I put up a really simple test plan for testing something. I have a csv file where I save all URLs acquired by a crawler. The URLs are just normal (http://something.com).
After reading those in from the CSV Config and writing them into my HTTP request sampler I get the following issue. The problem comes with the default protocol of JMeter which turns my request URL into this:
GET http://[http://something.com/]/.
Is there a way to turn that off?
Never put anything but ip address or hostname into Server Name or IP input of the HTTP Request sampler.
If you are getting the whole URL from CSV file - use Path input instead like:
Demo (as per View Results Tree listener)
See Using CSV DATA SET CONFIG guide to learn more about parameterisation of your JMeter test with CSV files.
My scenario is load test a functionality which will generate a text file at last, i need to verify the content of that file.
Please guide me step by step to achieve this functionality in jmeter from very beginning to last.
Given you already have your file downloaded to your local hard drive:
Add HTTP Request Sampler to your Test Plan
Configure it as follows:
Protocol: file
Path: /path/to/your/text/file.txt
Add Response Assertion as a child of the HTTP Request
Configure it to test whether the file contains expected data.
See How to Extract Data From Files With JMeter for detailed instructions.
If the file lives in the web, take the same approach, but use http or https protocols to retrieve the file. To save it locally you can use Save Responses to a File listener
In my application the value of p_auth is dynamically changes
I tried to handle it by correlation and it seems fine to me but not getting succeed.
I am attaching some screenshots , Please help me to identify where I am wrong
enter image description here
enter image description here
P_AUTH is Liferay authentication token which is used for CSRF protection, it can be handled in 3 easy steps:
Design your test scenario as follows:
Open login page
Extract p_auth
Pass extracted values from step 2 into login request
Step 2 in details:
If you look into response text from step 1 you will see p_auth in the response body:
In order to extract it into a JMeter Variable add Regular Expression Extractor as a child of the 1st request and configure it as follows:
Reference Name: anything meaningful, i.e. p_auth
Regular Expression: p_auth=(.+?)"
Template: $1$
Usually it is not required to extract formDate parameter, I usually substitute it with ${__time(,)} function
So request itself looks like:
To double check we have successfully logged in - check out Response Data tab of the last request which opens user dashboard:
See How to Load Test CSRF-Protected Web Sites article for a little bit more detailed information on bypassing CSRF protection in JMeter tests.
P.S. I see HTTP Header Manager in this screenshot. If it is something you got during recording - REMOVE IT as it can contain hard-coded irrelevant headers which may harm or at least review headers and leave (or correlate) only those you need