Building Your Script
Creating effective test scripts is a crucial aspect of performance testing with BlazeMeter. Whether you're using JMX (Java Sampler) or YAML scripts, following best practices can help to ensure accurate, reliable, and insightful performance testing results. This topic provides guidelines and considerations for creating test scripts in BlazeMeter using both JMX and YAML formats.
By following these best practices, you can create effective test scripts in BlazeMeter. Regularly review and update your scripts to accommodate changes in your application and testing requirements. Additionally, leverage BlazeMeter’s reporting and analytics features to gain insights into test results and optimize your application's performance.
Considerations for JMX Scripts
In JMeter:
-
Thread Group Configuration
Set appropriate values for the number of threads, ramp-up time, and duration in the Thread Group. Consider the expected user load and concurrency.
-
Sampler Configuration
Utilize the HTTP Request Sampler for web-based applications. Ensure accurate endpoint URLs, HTTP methods, and parameterization for dynamic values. Configure HTTP defaults, including protocol (HTTP/HTTPS), server name, and port.
-
Assertions
Implement assertions to validate the expected behavior of your application. Check response data, status codes, or other relevant metrics.
-
Listeners
Choose relevant listeners based on your testing goals. Aggregate Report, Summary Report, and View Results Tree are commonly used for result analysis.
-
Parameterization
Parameterize your test data using CSV files or other data sources. This allows you to simulate real-world scenarios with diverse inputs.
-
Think Time
Introduce think time between requests to simulate real user behavior accurately.
-
Think about Cookies and Sessions
Manage cookies and sessions appropriately, especially when dealing with authentication and user-specific scenarios.
Defining Users
In JMeter:
- Choose the right Thread group for your scenario
- Use Default HTTP request to control your HTTPs requests Server/IP, Protocol, Implementation and so on
- Verify you added a cookie manager
- Check you fetch every dynamic values (for example,
form_build_id
) and use a RegEx and a variable for it - User Define Variables VS User parameters preprocess - know which to use and when
- Use assertion when you can't count on the HTTP response code (login for example)
- Use the header manager to control your requests headers (user-agent) and change the values if needed
Use Default HTTP Requests
In JMeter:
After defining your users, you can move onto defining the tasks that they will be performing.
To begin with, you'll need to specify the default settings for your HTTP requests. Then you will add HTTP Request elements which use some of the default settings you specified here.
Begin by selecting the JMeter Users (Thread Group) element. Click your right mouse button to get the Add menu, and then select Add --> Config Element --> HTTP Request Defaults.
Then, select this new element to view its Control Panel.
Like most JMeter elements, the HTTP Request Defaults Control Panel has a name field that you can modify. In this example, leave this field with the default value.
Skip to the next field, which is the Web Server's Server Name/IP. For the Test Plan that you are building, all HTTP requests will be sent to the same Web server, jmeter.apache.org. Enter this domain name into the field. This is the only field that we will specify a default, so leave the remaining fields with their default values.
Verify You Added A Cookie Manager
It's common practice that most testing should leverage cookie support, unless your application specifically doesn't use cookies.
To add cookie support, simply add an HTTP Cookie Manager to each Thread Group in your test plan. This will ensure that each thread gets its own cookies, but shared across all HTTP Request objects.
To add the HTTP Cookie Manager , simply select the Thread Group , and choose Add --> Config Element --> HTTP Cookie Manager, either from the Edit Menu, or from the right-click pop-up menu.
Sample JMX Script
Creating a JMeter JMX script involves defining thread groups, samplers, and listeners. Here's a concise JMX script for a performance test on https://demoblaze.com with 10 virtual users, a test duration of 5 minutes, and a ramp-up time of 1 minute:
Click the following link to access the sample JMX script.
Considerations for YAML Scripts
-
Concurrency and Ramp-up:
Specify the concurrency and ramp-up time in the YAML script. Ensure it aligns with your testing goals and expected user load.
-
Scenario Definitions:
Define scenarios that represent different user journeys or use cases. Each scenario should contain relevant requests and actions.
-
HTTP Requests:
Clearly define HTTP requests within each scenario. Pay attention to the URL, method, and any necessary headers or parameters.
-
Think about Variables:
Utilize variables for dynamic data, such as user credentials or session tokens. This ensures realistic test scenarios.
-
Assertions and Validations:
Include assertions within the YAML script to validate the correctness of responses. Ensure that the application behaves as expected under load.
-
Reusable Components:
Consider creating reusable components or modules for shared functionalities across scenarios. This enhances script maintainability.
Sample YAML Script
The following is an example of a Taurus YAML file for running a performance test on https://demoblaze.com. This configuration specifies a test for 10 virtual users, a test duration of 5 minutes, and a ramp-up time of 1 minute.
execution: concurrency: 10 ramp-up: 1m hold-for: 5m scenario: simple scenarios: simple: requests: - label: "Open Home Page" url: "https://demoblaze.com"
Explanation:
-
concurrency
: The number of virtual users to simulate concurrently. -
ramp-up
: The time it takes to ramp up to the specified concurrency level. -
hold-for
: The duration of the test at the specified concurrency level. -
scenario
: Specifies the scenario to execute.
In the above example, the scenario named "simple
" is defined with a single request to open the home page of https://demoblaze.com. Adjust the URLs and requests according to your specific test scenario.
Save this content to a YAML file, for example, performance_test.yaml
, and then you can run the test using the following command:
bzt performance_test.yaml
Make sure you have Taurus installed before running the test. You can install Taurus using:
pip install bzt
Alternately, you can create a test in BlazeMeter and upload this file.