JMeter - Conditionals and Assertions - jmeter

I am able to have my test plan set up as so: Thread Group > While Controller > SOAP/XML-RPC Request > CSV Data Set Controller & Response Assertion. When I have one element it is ok, but when I loop through a CSV I get failed.
How do you loop through a CSV (that contains the input parameter values I want to test with) and set an assertion for each please?
E.g. I want to test a currency converter. My Excel sheet contains these rows:
USD,EUR
EUR,GBP
GBP,USD
The jmeter test plan will loop through my Excel and inject each of those parameter pairs to my web service. USD,EUR should return 0.9216, EUR,GBP should return 0.729 etc.
Thanks!

Check the 'CSV Data Set Config' in this post. If it does not clarify, please let me know with your question.
http://www.testautomationguru.com/how-to-test-rest-api-using-jmeter/

Related

How to hit parameterized url in Apache Jmeter?

This is my test URL " http://appr.seconddemo.org/hitssurveys/survey?uid=113&offerid=311&subid=subvalues&offr_id={Email} "
I want to hit the url 1500 times per second , and want to change the "{Email}" with real value in each iteration.
How it's possible please give me a step by step guide.
Considering that you need to pass the emails from the external file, the most efficient way that we are using in software testing companies is to pass the variable from .csv or .txt files using 'CSV Data Set Config' element of the JMeter.
Please find the steps that you need to follow:
Add a 'CSV Data Set Config' element from 'Config Element' by right-clicking the thread group
Set Filename field with complete path to your .csv or .txt file that contains your emails
Set Variable field as 'Email' [This variable name should be same as you set in your url request]
Ignore first line to False
Set other fields as per your requirement
Now add HTTP Sampler in your Thread Group and set the Protocol, Server Name, Method & Path as instructed in the screenshot:
Create .csv or .txt file and add all emails separated by new line:
Hope this answer is useful.
You can use the CSV Data Set Config. Put all your email credentials in the CSV file and make sure you have put this CSV file in your JMeter /bin directory.
Add a CSV dataset config in your test plan. Your CSV dataset config should be like:
Now in your thread group, define the number of threads you want to execute and then in your sampler put the path as follows:
http://appr.seconddemo.org/hitssurveys/survey?uid=113&offerid=311&subid=subvalues&offr_id=${Email}
Depending on where do your emails live there are following options:
If they are in a text file, each email on a new line you can use __StringFromFile() function like:
If they are in a database you can use JDBC PreProcessor to fetch the data from the database table column and put your request under ForEach Controller
If you need to provide just some random characters you can use __RandomString() function.
More information: JMeter Parameterization - The Complete Guide

Use Beanshell for parametrization in jmeter

Currently my test structure is:
User Defined Variable (Name:CAMPAIGN_ID, Value:100)
Thread Group
CSV Data Set Config (to read external txt file of user ids)
HTTP Request
Beanshell Assertion (use JSON path extractor to extract value of a field using CAMPAIGN_ID configured in UDV)
So my test runs fine with one CAMPAIGN_ID.
Now i want to enhance this test and execute it for 10 Campaigns without updating it in User Defined Variable everytime.
So i created a campaign.txt file as below
Campaign1 100
Campaign2 101
Campaign3 103
Questions:
1. What is best approach to achieve this goal ? should i use beanshell prepocessor to read from txt file and store it in vars.put("Campaign1",100) and use for Each loop to loop through.
2. Can someone please help me with the new test structure and code sample ?
Any help is much appreciated !
Are you trying to loop 2 csv files?
For every rows in an outer CSV file (CAMPAIGN_ID), you need to run all the rows of inner csv file (user_id),then take a look at below example.
http://www.testautomationguru.com/jmeter-looping-2-csv-files/

JMeter: how to vary request inside Thread Group

I have to write load tests for web application using JMeter. The application has items available for booking, each item has a 'Book' button. If some user clicks this button for item, it becomes unavailable for other users. My question is:
Is it possible to make JMeter threads to book different items (to make different requests) and how to implement it?
You should be able to determine what parameter is being posted by different "Book" buttons and modify nested requests as needed. Test plan structure should be something like:
Open Booking Page - HTTP Request
Get all Booking IDs - Post Processor
Book - HTTP Request
Where "Post Processor" can be
Regular Expression Extractor
CSS/JQuery Extractor
XPath Extractor
In case of multiple matches Post Processor will return multiple variables like
BookindID_1=some value
BookindID_2=some other value
BookindID_3=some other value 2
....
BookindID_matchNr=10
There are at least 2 options on how to proceed with these values:
Iterate all the values using ForEach Controller
Stick to current virtual thread number via __threadNum function so thread #1 will take BookindID_1 variable, thread #2 - BookingID_2 variable value, etc.
It is also possible to take random value using __Random function but it may result in request failure if item is not available.
The correct way of 2 variables combination looks like:
${__V(VAR1${VAR2})}
So combining BookingID_N and __threadNum will look like
${__V(BookingID_${__threadNum})}
See How to use JMeter Functions post series for more on what can be done via functions.
yes, If every item has static(predefined) unique id,descriptor,identifier then that can be parameterized using a csv config file or random no. generator and selector
Random no generator and selector will work only for integers but csv config is better/standard practice. If you need more help please paste your test plan here with explaination of your need.

Anyway to auto set jmeter assertions to initial responses?

I am building out a test suite in jmeter and want to set the assertions to the initial responses that I get from the api calls. Is there any way to do this besides copy pasta?
For clarity each individual call has its own assertion, which for the moment is the response it is receiving.
I want the assertions to be populated by the responses.
If I understood currectly - you are coming up with some JMeter-Baseline script - you also assume that the response you get now is correct - that is what you expect to get it in future as well , so you want to put the response data in the assertion.
If yes, JMeter will not remember the initial responses. So you need to create your script accordingly.
You can have a beanshell postprocessor to write the the responsedata in a CSV file. Later you modify the script to look for the assertion string from CSV file to compare. This is the statement to get the Response Data.
prev.getResponseDataAsString()
As per How to Use JMeter Assertions in 3 Easy Steps guide, JMeter Assertions have their scope.
If you put an assertion at the same level as all requests it'll apply to all of them. See image below for explanation:
I would use a CSV file with the URL and the assertion string you want to match.

Jmeter Parametrization

I'm very new to Jmeter. I need help with the input data file for jmeter.
Here is my situation.
My test data file structure is like this:
Test Case Name = XXXXXX11
RequestData = AAAAAAAAAA11
Expected Result = BBBBBBBBB11
Test Case Name = XXXXXX22
RequestData = AAAAAAAAAA22
Expected Result = BBBBBBBBB22
and so on ....
Now, I have to send the http request and verify the expected using Jmeter (Maven & Continuous Integration).
How can I parse the given file and verify the expected result?
I have tried the following:
__StringFromFile - but i don't know how to look for the line which has Request data or Expected result;
userParameter - but not sure how to pass values on runtime.
Could any of you please help me?
Do you have single test-case per file (i.e. single appearance of "Test Case Name",...,etc. in file)?
If so then you can possibly try to use custom Variables From CSV File plugin from Jmeter Plugins project.
My suggestion would be to convert your file to csv (with any delimiter you like). The first row becomes your heading, and each additional row becomes your data you want to pass in or validate. For example:
Test Case Name|Request Data|Expected Result
XXXXXX11|AAAAAAAAAA11|BBBBBBBBB11
XXXXXX22|AAAAAAAAAA22|BBBBBBBBB22
You can load this data in to your test plan using the CSV Data Set Config. Once you do, you'll be able to loop through each row of data if you set your Thread Group to Loop Forever. Then all you need to do in the test case is refer to your variables from the csv file like so:
${Test Case Name}.
Thank you so much guys!
I just wrote a bean shell script to parse the CSV file and stored all the request & response in the array and then created a for each loop around my http sampler. That met my requirement.
Thread Group
Beanshell preprocessr (To parse my CSV and to store it in an array)
For each loop (loops thru the array)
http sample
response assertion
Results

Resources