Learn Functional Testing Using JMeter Components
/skill level/
/viewed/
Contents |
Introduction
JMeter is found to be very useful and convenient in support of functional testing. Although JMeter is known more as a performance testing tool, functional testing elements can be integrated within the Test Plan, which was originally designed to support load testing. Many other load-testing tools provide little or none of this feature, restricting themselves to performance-testing purposes. Besides integrating functional-testing elements along with load-testing elements in the Test Plan, you can also create a Test Plan that runs these exclusively. In other words, aside from creating a Load Test Plan, JMeter also allows you to create a Functional Test Plan. This flexibility is certainly resource-efficient for the testing project.
This chapter will give a walkthrough on how to create a Test Plan as we incorporate and/or configure JMeter elements to support functional testing. This chapter assumes that you have successfully gone through Chapter 5, and created a Test Plan for a specific target web server. We will begin the chapter with a quick overview to prepare you with a few expectations about JMeter. Later, we will create a new Test Plan similar to the Test Plan in Chapter 5, only smaller. The Test Plan we will create and run at the end of this chapter will incorporate elements that support functional testing, exclusively. Preparing for Functional Testing
In this regard, I need to highlight that JMeter does not have a built-in browser, unlike many functional-test tools. It tests on the protocol layer, not the client layer (i.e. JavaScripts, applets, etc.) and it does not render the page for viewing. Although, by default that embedded resources can be downloaded, rendering these in the Listener | View Results Tree may not yield a 100% browser-like rendering. In fact, it may not be able to render large HTML files at all. This makes it difficult to test the GUI of an application under testing.
However, to compensate for these shortcomings, JMeter allows the tester to create assertions based on the tags and text of the page as the HTML file is received by the client. With some knowledge of HTML tags, you can test and verify any elements as you would expect them in the browser.
Unlike for a load-testing Test Plan, it is unnecessary to select a specific workload time to perform a functional test. In fact, the application you want to test may even reside locally, with your own machine acting as the "localhost" server for your web application. For this chapter, we will limit ourselves to selected functional aspects of the page that we seek to verify or assert.
What you'll need
Using JMeter Components; Snapshots for each step can be obtained from http://www.packtpub.com/files/JMeter-Sample-Chapter-6-Functional-Testing.pdf
We will create a Test Plan in order to demonstrate how we can confi gure the Test Plan to include functional testing capabilities. The modified Test Plan will include these scenarios:
* 1. Create Account—New Visitor creating an Account * 2. Log in User—User logging in to an Account
Following these scenarios, we will simulate various entries and form submission as a request to a page is made, while checking the correct page response to these user entries. We will add assertions to the samples following these scenarios to verify the 'correctness' of a requested page. In this manner, we can see if the pages responded correctly to invalid data. For example, we would like to check that the page responded with the correct warning message when a user enters an invalid password, or whether a request returns the correct page.
First of all, we will create a series of test cases following the various user actions in each scenario. The test cases may be designed as follows:
With the exception of the Configuration elements, Listeners, and Assertions, which we will add later, our Test Plan will take the form that you see in the following screenshot: Apache JMeter Using HTTP Proxy Server to Record Page Requests
A s in recording requests in Chapter 5, you will need to include the HTTP Proxy Server element in the WorkBench. Some confi guration will be required, as shown in the following snapshot: Apache JMeter Configuring the Proxy Server
Simulating Create Account and Login User scenarios will require JMeter to make requests for the registration and login pages that are exposed via HTTPS. By default, HTTP Proxy Server is unable to record HTTP requests. However, we can override this by selecting (checking) the Attempt HTTPS Spoofing checkbox.
Selecting Add Assertion will be especially useful as we add specifi c patterns of the page that we want to evaluate as a later part of this exercise. The Capture HTTP Headers option is selected to capture the Header information as we begin recording. However, to make the recording neater, we will keep this option unchecked.
In addition, since we do not require images in our testing, in the URL Pattern to Exclude section, add these patterns: .*\.jpg, .*\.js, .*\.png, .*\.gif', .*\.ico, .*\.css, otherwise these image files, which are not necessary for our testing, will be recorded causing unnecessary clutter in our recording. Adding HTTP Request Default
A useful addition to this element is the HTTP Request Default element, a type of Configuration element. Since this Test Plan will employ multiple HTTP request elements targeting the same server and port, this element will be very useful. The web server name will not be captured for each HTTP Request sampler record, since the Request Default element will retain this information. With a little configuration change in this element, it allows the Test Plan to run even when the application is the deployed to a different server and/or port. The following snapshot is the HTTP Request Default element that we will use for this exercise. Apache JMeter
As we use this default element, our subsequent recording never needs to append the Server name. The result of our recording of the first page is shown in the following snapshot: Apache JMeter Adding HTTP Header Manager
Another very useful default element is the HTTP Header Manager Configuration element. This element can either be added to the Test Plan and configured manually as an afterthought, or we can simply use the recorded Browser-derived headers element as included in the recording. For convenience, we will choose the latter option. Once the Proxy Server records the homepage request, stop the recording. You will find a Header Manager for this page is being captured, as Browser-derived header. Simply click and drag this element to the top of the current scope of the HTTP Proxy Server. Notice that I have removed the Referer, since we want to create a default for the remaining HTTP Requests. Following is a snapshot of this change. Apache JMeter
Now you may de-select the Capture HTTP Headers option in the Proxy Server element, since we have the default header.
Steps
o Preparing for Functional Testing o Using JMeter Components
+ Using HTTP Proxy Server to Record Page Requests
# Configuring the Proxy Server
# Adding HTTP Request Default
# Adding HTTP Header Manager
+ Let the Recording Begin...
+ Adding User Defined Variables
o Running the Test o Summary
Alternate methods
For other details visit http://www.packtpub.com/beginning-apache-jmeter/book#indetail
Suggested readings
This chapter provided visual means for you to understand the capabilities of JMeter tools that support functional testing, as we directly wrote and implemented a JMeter script. We have demonstrated building a Test Plan to contain functional validations (or assertions) by incorporating various essential JMeter components, particularly the 'Response Assertion' element and 'Assertion Result' Listener. By using the 'User Defi ned Variable' Confi guration element, we have also parameterized several values in order to give our Test Plan better fl exibility. In addition, we have observed the result of these assertions as we performed a 'live' run of the application under test. An HTTP Request sampler may require to be modifi ed, if there are any changes to the parameter(s) that the sampler sends with each request. Once created, a JMeter Test Plan that contains assertions can then be used and modifi ed in subsequent Regression tests for the application. The next chapter will let us see various ways that a JMeter script can be further confi gured and tweaked so that it supports better portability and testability. Chapter 7 will describe various methods and tools available in JMeter that support more advanced and complex testing requirements.
For more information visit http://www.packtpub.com/beginning-apache-jmeter/book
- This page was last modified 07:11, 18 December 2008.