Giter Site home page Giter Site logo

apache-jmeter's People

Contributors

jtmobs avatar qainsights avatar

Watchers

 avatar

apache-jmeter's Issues

Add a Listener

Listeners

In this exercise, we are going to see about Listeners, how to add them and how to execute JMeter test plan.

About Listeners

Listeners just listens to the test results, but it can perform other tasks.

⚠ Listeners are resource intensive, it should not be used during the load testing.

Listeners are processed at the end of the scope in which they are found.

There are many types of Listeners available in JMeter. In this exercise, we are going to cover View Results Tree.

The View Results Tree shows a tree of all sample responses, allowing you to view the response for any sample. In addition to showing the response, you can see the time it took to get this response, and some response codes.

⌨️ Activities

  1. In your S01_PetStore test plan, add a View Results Tree element as shown below.

View Results Tree

  1. To execute JMeter test plan, click on Run button in the toolbar, or hit Ctrl + R. After couple of seconds, you will get two green items in View Results Tree as shown below.

Success Requests

  1. Toggle between Sampler result, Request, Response data for both of the requests and understand the context.

Push the changes to go to your next exercise ➡.

Upload your first JMeter test plan

Create your first Thread Group

🚀 Launching JMeter

The prerequisite to launch JMeter is to have Java installed in your computer. You can interact with JMeter using the CLI and Non-CLI mode. Command Line Mode is the recommended mode for performance testing purposes. But to create or edit, you can launch JMeter in Non-CLI mode.

Go to the location where you extracted the content of JMeter file e.g. C:\Tools\apache-jmeter-5.3

Navigate to bin folder and launch jmeter.bat for Windows OS or jmeter.sh for Linux/macOS systems.

If Java is installed properly, JMeter will launch as shown below.

JMeter

Congratuations on launching JMeter 🎉

Test Plan

In JMeter world, you create test plans which has the file extension of .jmx. If you open .jmx file in your favorite editor, you can see the XML tags.

A typical JMeter test plan consists of at least one Test Plan element and one or more Thread Groups and/or Samplers/Other elements.

📌 You cannot delete Test Plan element

Thread Group

Thread Group is the inception for any JMeter tests. In Thread Group you can configure the number of threads/users, duration, ramp up period etc.

In this exercise, we are going with the default values of Thread Group.

Let's get started 🚀

⌨️ Activities

  1. Launch JMeter
  2. Add a Thread Group by right clicking on Test Plan > Threads (Users) > Thread Group
  3. Go to File > Save, enter S01_PetStore.jmx and hit Save button
  4. Push the JMeter test plan to your repo

After successful push, I will let you know the next steps.

Tips
📌 Whenever you want to add any type of elements, just right click on the appropriate parent element.

📌 If you want to delete any element, press Delete key in your keyboard.

CAUTION: Undo is not possible in JMeter.

📌 Instead of deleting, you can disable the element by clicking on right clicking on it > Disable.

Timers

Timers

Note that timers are processed before each sampler in the scope in which they are found; if there are several timers in the same scope, all the timers will be processed before each sampler.

What are Timers? ⏲

JMeter has different types of Timers. Frequently useds timers are: Constant Timer, Uniform Random Timer, Precise Throughput Timer etc.

⏳ Timers injects a delay before it executes Samplers in scope.

A user who knows how to place an order in the ecommerce application navigates faster in their pace. But if a user is new to the application, then the user's pace is slow. Because every user is unique.

To simulate the real world scenario in the test plan, it is important to add relevant delay between the requests. Also, it will help you test the application in a right way, instead of throwing up the load without delay which will trigger a server crash 💥.

⌨️ Activities

  1. To your Pet Store plan, let us add a Constant Timer for each HTTP request.
  2. Right on the first HTTP Request, go to Add > Timer > Constant Timer.
  3. Add 1000 in Thread Delay. Unit of time in JMeter is milliseconds.

Timers

  1. Click on View Results Tree element and then click on Run

You can observe a delay between the HTTP requests when the test is running.

👏 Kudos! Now you know how to add Timers to JMeter test plan.

Push the changes to navigate further. We are almost there, keep up the pace.

Assertions

Assertions

Assertions - the action of stating something or exercising authority confidently and forcefully.

Assertions in JMeter ✔

Assertions are used to perform additional checks on samplers, and are processed after every sampler in the same scope. To ensure that an Assertion is applied only to a particular sampler, add it as a child of the sampler.

JMeter has different types of Assertions. Few assertions are expensive. It is not advisable to enable them during the load test. Commonly used Assertions are Response Assertion, JSON Assertion, Size Assertion etc.

⌨️ Activities

  1. For the Pet Store scenario, we are going to add a Response Assertion for the Search HTTP request. Before we get started, let us change the name of the HTTP Requests as shown below.

HTTP Requests

  1. To add a Response Assertion, right click on 03_Search HTTP request > Add > Assertions > Response Assertion.

  2. Set the below properties as shown below for the assertions. Below assertion validates the HTTP Response Code exactly matches 200, if not it will show it as failure in the View Results Tree.

Response Assertion

  1. Hit Run to observe the results.

Below is the sample failed assertion.

Failed Assertions

Push the changes to proceed further.

Add HTTP Sampler

HTTP Sampler

As you aware, we are going with the default number of threads in Thread Group. In this exercise, you will learn about HTTP Request element.

HTTP Sampler lets you send an HTTP/HTTPS request to a web server. It also lets you control whether or not JMeter parses HTML files for images and other embedded resources and sends HTTP requests to retrieve them.

Before adding HTTP Sampler, let's add the default settings to your HTTP Requests. To define the default settings for HTTP Requests we are going to add HTTP Request Defaults.

HTTP Request Defaults element lets you set default values that your HTTP Request controllers use.

In this exercise, we are going to add two HTTP requests to the test plan.

Let's dive into the activities.

⌨️ Activities

  1. Add a HTTP Request Defaults by right clicking on Thread Group > Config Element > HTTP Request Defaults.
  2. Add the properties to the HTTP Request Defaults as shown below.

HTTP Request Defaults

  1. Add a HTTP Sampler by right clicking on Thread Group > Sampler > HTTP Request.
  2. Add / to the Path

HTTP Request 1

  1. Add another HTTP Sampler
  2. Add /actions/Catalog.action to the Path

HTTP Request 2

  1. Save your test plan by pressing Ctrl + S
  2. Push the test plan to the repo to go to next exercise.

View Results

Test Execution

CLI Mode

It is recommended to run the test using the CLI mode to get the optimal results.

Here is the command to run the test in CLI mode.

.\jmeter.bat -n -t .\S01_PetStore.jmx -l Run1.jtl

DISCLAIMER

In this exercise, we are going to run the test using just only one thread and for 30 seconds only. Because, we are not authorized to run the test in the desired environment.

ALL THE PERFORMANCE TESTING ACTIVITIES MUST BE CARRIED OUT IN THE NON-PRODUCTION ENVIRONMENT.

I AM NOT RESPONSIBLE FOR ANY SORT OF DAMAGE CAUSED DUE TO YOUR LOAD TESTING FOR ANY WEBSITES/APPS/SERVICES/SYSTEM/ENTITY.

Please act responsibly.

⌨️ Activities

  1. Before we start the test, click on Thread Group, select Specify Thread lifetime and enter 30 in the Duration (seconds) text box.

  2. Disable View Results Tree

  3. Hit Save and close the JMeter.

  4. Launch Command Prompt (for Windows) or Terminal (for Linux/macOS). Navigate to JMeter directory bin folder.

  5. Issue the below command.

.\jmeter.bat -n -t .\S01_PetStore.jmx -l Run1.jtl

During the test, you can observe the statistics in the command prompt. Once the run is done, you will get the status as shown below.

Run 1

  1. To view the results in JMeter. Launch JMeter and add any listener and browse the jtl file which got generated in the bin folder.

Summary Report

Literally you can add any type of listener to visualize the results.

Push the changes to proceed further to conclude your exercise.

Transaction Controller

Transaction Controller

Just like any other programming language, you can control the execution flow using Logic Controllers in JMeter.

Logic Controllers which determines the order in which Samplers are processed.

There are different types of controllers in JMeter. Commonly used ones are: If, Transaction, While, Loop etc.

⌨️ Activities

We are going to measure the performance of Search functionality. Transactions are nothing but the collection of sequential steps/requests. Let us add transactions to the Pet Store test plan.

Instead of adding the transaction controller, we are goint to insert it to the HTTP requests.

  1. Right click on 01_Launch > Insert Parent > Logic Controller > Transaction Controller. This will insert a transaction controller to the selected request. Rename the transaction controller to T01_Launch.

  2. Check Generate parent sample checkbox.

  3. Repeat the steps for other two HTTP requests as shown below.
    Transaction Controller

  4. Hit Run to view the results.

Transactions Results

Push the changes to proceed further.

Data Parameterization

Data Parameterization

In this exercise, we are going to see about data parameterization and add Login request in our test plan.

What is Data Parameteization?

In real world, every user is unique. To simulate the real world scenario, it is critical to test the application with different sets of data.

If you test your application with the same test data, your response likely will be served from the cache. Your performance test results will not yield the real performance.

Generating test data in run time is expensive. It is important to generate the test data well ahead.

Creating test data is beyond the scope of this training.

About CSV Data Set Config

In JMeter, data parameterization can be achieved using CSV Data Set Config.

CSV Data Set Config is used to read lines from a file, and split them into variables. It is easier to use than the __CSVRead() and __StringFromFile() functions. It is well suited to handling large numbers of variables, and is also useful for testing with "random" and unique values.

Scenario

As you know we are working on Pet Store application. Assume that you need to create a test plan for Search scenario.

  1. Launch Pet Store
  2. Navigate to https://petstore.octoperf.com/actions/Catalog.action
  3. Search for different pets using the search text box.

Sample Test Data

angelfish
cat
dog
bird
bulldog

⌨️ Activities

  1. In your S01_PetStore, add a new HTTP Sampler and fill the below properties.

HTTP Method: POST
Path: /actions/Catalog.action
Parameters:
keyword as fish
searchProducts as Search

Add Parameters

As you see, we have not done with the parameterization. Let's get started.

  1. Add a CSV Data Set Config by right-clicking on the Thread Group > Add > Config Element > CSV Data Set Config

  2. Copy the above test data and save it as PetSearch.csv in your bin folder.

  3. Configure the CSV Data Set Config as shown below.

CSV Data Set Config

You can add multiple Variable Names if the CSV test file has multiple columns.

  1. Go to the POST HTTP Request and edit the keyword to ${P_SearchKeywords}. ${P_SearchKeywords} holds the value of the variable from CSV Data Set Config in runtime.

CSV POST HTTP

  1. Since we have 5 rows in our test data, click on Thread Group and change the Loop count to 5.

  2. Hit the Run button and click on View Results Tree to view the results for each test data.

CSV Results

You are a super star 🌟!

Push the changes to go to your next exercise ➡.

Welcome!

Welcome to this course!

Before we can start learning JMeter, let us make sure you have the right setup. You need to install the following things to learn effectively.

Let's get started.

  • Check that OpenJDK is installed/configured
  • Check that Git is installed
  • Check JMeter is installed/configured
  • Clone this repository on your local machine

Points to note:

📌 Always install the latest stable versions of the software unless the version specified.
📌 Below exercises have been tested using JMeter 5.3 in OpenJDK 15.

OpenJDK

  • Download OpenJDK and follow the instructions mentioned here. Similar instructions can be found in the internet for Linux or macOS operating systems.

Git

  • Download and install Git for your platform from here

Apache JMeter

  • Download Apache JMeter from here
  • Extract the contents and keep it your favorite location.

There are additional components you can install if you are planning to develop JMeter, but those are completely optional and beyond the scope of this training.

Clone this repository

This is your workspace to learn JMeter. Clone this repository by issuing the below command.

git clone <repository-url>

Getting started

Once you have everything installed, let's get started.

Close this issue, and I will comment with your next steps.

Points to note:

📌 Sometime I respond too fast ⚡, please bear with me.
📌 Sometime I respond slow, just refresh your browser 😊

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.