Book Image

Master Apache JMeter - From Load Testing to DevOps

By : Antonio Gomes Rodrigues, Bruno Demion (Milamber), Philippe Mouawad
Book Image

Master Apache JMeter - From Load Testing to DevOps

By: Antonio Gomes Rodrigues, Bruno Demion (Milamber), Philippe Mouawad

Overview of this book

Load tests help identify the maximum number of requests a software system can handle. One popular open source tool for load testing is JMeter. By leveraging the features and capabilities of JMeter, you can perform extensive load testing and fix issues in your application before they become problematic. This book is written by JMeter developers and begins by discussing the whole process, including recording a script, setting it up, and launching it, enabling you to almost immediately start load testing. You'll learn the best practices that you must follow while designing test cases. You'll also explore the different protocols offered by JMeter through various real-world examples. Finally, you'll see how to integrate JMeter into the DevOps approach and create professional reports. You'll discover ways to use the eco-system of JMeter to integrate new protocols, enrich its monitoring, and leverage its power through the use of the cloud. By the end of this book, you'll know all that's needed to perform comprehensive load testing on your applications by using all the best practices and features of JMeter.
Table of Contents (14 chapters)

Save Our Script

Now, let's start our navigation session.

  1. To do this, simply click the Start button on the HTTP(S) Test Script Recorder element:
    Figure 1.11: HTTP(S) Test Script Recorder
    Figure 1.11: HTTP(S) Test Script Recorder

    Note

    Note that the default listening port of JMeter proxy server is 8888.

    Note the first time you start the recorder, it takes more time as it generates a Certificate Authority that you can use to intercept HTTPS traffic.

  2. This will open a Recorder: Transactions Control window, allowing us to set in real time the name of each recorded step transactions and their grouping based on time:
    Figure 1.12: Recorder: Transactions Control
    Figure 1.12: Recorder: Transactions Control
  3. In this chapter, we will use the Request Parameters example delivered with Apache Tomcat.

    From the browser, navigate to the website:

    http://server:8080/examples/servlets/

    In our case, it will be:

    http://localhost:8080/examples/servlets/

    Here is the first page:

    Figure 1.13: First page of our scenario
    Figure 1.13: First page of our scenario
  4. Then, click on the Execute link of the Required test servlet:
    Figure 1.14: Request Parameters Example with no entries
    Figure 1.14: Request Parameters Example with no entries

    Enter first and last name and click on Submit Query:

    Figure 1.15: Request Parameters Example before submitting query
    Figure 1.15: Request Parameters Example before submitting query

    When the result appears, we can stop our navigation session:

    Figure 1.16: Request Parameters Example after submitting query
    Figure 1.16: Request Parameters Example after submitting query
  5. In JMeter, the scenario tree is the following:
    Figure 1.17: Result of our recording in JMeter
    Figure 1.17: Result of our recording in JMeter
  6. Let us observe what has been recorded:
    Figure 1.18: Observation table
  7. As we can see, thanks to the trick of filling the Server Name or IP and Port Number sections of the HTTP Request Defaults element, these fields remain empty in the HTTP Request elements.

    This will allow us to change the URL and port of the tested site in only one location (HTTP Request Defaults) if necessary (for example, if the script was run on a development environment, and the final test will run on the pre-production environment):

    Figure 1.19: Result of filling in the Server Name or IP and Port Number sections of the HTTP Request Defaults element
    Figure 1.19: Result of filling in the Server Name or IP and Port Number sections of the HTTP Request Defaults element
  8. Similarly, the waiting time between each action (Think time) was recorded:
    Figure 1.20: Recorded think time
    Figure 1.20: Recorded think time
  9. To make it easier to read the results, it is preferable to rename HTTP requests. The automatically chosen name, by default, corresponds to the called URI, but you can control it in the little popup and give it a meaningful name before clicking on the button that will issue the request(s).

    The result of the renaming:

    Figure 1.21: Renaming result
    Figure 1.21: Renaming result
  10. As the last step to the development of the scenario, we are going to add assertions to each HTTP request. These will make it possible to verify that the response received is indeed the expected one.
  11. To do this, select the HTTP request that will receive the assertion, then, via the context menu, choose Add > Assertions > Response Assertion:
    Figure 1.22: Add assertion
    Figure 1.22: Add assertion
  12. A new Response Assertion element has been added as a child to the SC01_1 Homepage request.
  13. Let's select the following options:

    Field to Test: Text Response

    Pattern Matching Rules: Substring (default)

    Patterns to Test: Let's click on the Add button, then insert text contained in the answer:

    Figure 1.23: Assertion configuration
    Figure 1.23: Assertion configuration
  14. To find what data we need to check in response, the trick is to use the View Results Tree element, located under our HTTP(S) Test Script Recorder, by choosing the desired request and then by selecting the tab Response data > Response Body.
  15. We can then copy the text and use Add from clipboard button in the Response Assertion:
    Figure 1.24: Result in Results Tree
    Figure 1.24: Result in Results Tree
  16. Repeat the operation for all the requests in the same way as you did for the home page.

    In the end, we get this JMeter scenario tree:

Figure 1.25: Our JMeter scenario
Figure 1.25: Our JMeter scenario

Now our scenario is ready, let's proceed to the validation of our script.