Create a load test plan with JMeter

Related articles:

Become a technical tester while learning JMeter
Performance testing checklist

New posts: 

Selenium Basics



JMeter concepts used in this example:

- controllers: if, simple, foreach

- regular expression extractors

- user defined variables

- dynamic http requests

- response assertions

- duration assertions

- executing javascript functions

- bean shell assertions

- reading and writing user variables in a bean shell script

- writing to the jmeter log

- using listeners (view results tree)



Load Test Plan - requirements



Main URL: http://jmeter.apache.org/

step 1. Open the http://jmeter.apache.org/changes.html

step 2. Do a few validations

         a. check that version number = Version 2.10
        b. check that page load time < 1000ms
 
step 3. At the bottom of the changes.html page, there are many bug fixes links

step 4. Get the ids of all bug fixes

step 5. Go through all bug fix ids and repeat the following actions:

         a. Print the bug order number and bug id in the JMETER log
 
b. If the bug id < 58000
 
b1. Open the bug page

b2. Run a few assertions on the bug page

b2.1 Check that ASF Bugzilla exists in the page

b2.2 Check that the bug id exists in the page




Load Test Plan set up



1. Create a Thread Group with the following settings:


action to be taken after a sampler error = continue
number of threads (users) = 10
ramp-up period = 1
loop count = 1

2. Create a Simple Controller inside of the thread group; name it "Practice Tests"

3. Create a Simple Controller inside of Practice Tests; name it "Open Bug pages based on the results of a regular expression"

4. In the last Simple Controller, create the following:

- User Defined Variables config element

* it will include the variables used in the requests and assertions


- Only Once Controller

* it will be used for opening the changes.html page only once
* name it "Open The Changes page"



- ForEach controller

* it will be used for opening the bug id pages
* name it "Open Bug Id pages"

5. Add a View Results Tree listener at the same level with the "Practice Tests" Controller; this will be used for getting results from the load test



Click the image for the original photo




Create the Tess Plan details

1. in the User Defined Variables section, add the following variables:

BugIds

used for getting all bug fix id values from the changes.html page
the variable will store a list of bug id strings
default value = 0

ResultValue

used for getting the individual bug ids from the BugIds variable
default value = 0

NumberOfBugs

used for getting the bug count in the changes.html page
default value = 0



Click the image for the original photo



2. in the "Open The Changes page" controller, create a http request with the following details:


*** this matches requirement 1
Name = Changes Page
Server Name or IP = jmeter.apache.org
Path = /changes.html


3. Add 2 assertions to the "Changes Page" http request


*** this matches requirement 2


a. response assertion

Name = check version number
Response Field To Test = text response
Patterns to test = Version 2.10



Click the image for the original photo



b. duration assertion

Name = check page load time
Duration to assert = 1000 ms


Click the image for the original photo



4. Add a Regular Expression extractor post-processor to the "Changes Page" http request


*** this matches requirement 4
Name = GetBugsIds

Response Field To Check = body
Reference Name = BugIds (defined in User Defined Variables)
Regular Expression = (id=([0-9]{5}))+ 
Template = $1$
Match = -1 (important if using with foreach controller)
Default Value = nothing

This is how the regular expression will work:

- it will find all id = xxxxx values in the page and add them to the BugIds variable
- the BugIds variable will be a collection of bug ids



Click the image for the original photo




5. Add the following to the "Open Bug Id pages" ForEach controller:

*** this matches requirement 5

- Controller Settings:

input variable prefix = BugIds (defined in User Defined Variables and instanced by the GetBugsIds regular exp extractor)
output variable name = ResultValue (defined in User Defined Variables)

This is how the controller works: 
   for each iteration, it will assign one bugid value from BugIds to the ResultValue variable.


Click the image for the original photo




- Create a bean shell sampler for displaying the bug count and id in the jmeter log:

*** this matches requirement 5a

Name = Print Bug Number and ID (inline)
String myNumberOfBugs = vars.get("NumberOfBugs");
Double myBugNumber = 0; 
myBugNumber = Double.parseDouble(myNumberOfBugs); 
myBugNumber = myBugNumber + 1;
vars.put("NumberOfBugs", myBugNumber.toString()); 
String myResultValue = vars.get("ResultValue"); 
String myBugId = "";
myBugId = myResultValue.substring(3,8);
log.info("bug number: " + myBugNumber.toString() + " - bug id = " + myBugId);

Click the image for the original photo



- Create an If Controller so only specific bug id pages are opened:

*** this matches requirement 5b


Name = Open Bug Details page if bug id < 58000
Condition = ${__javaScript('${ResultValue}'.substring(3\,8))} < 58000
  This condition evaluates if the bug id (xxxxx) is smaller than 5800;
  If the condition is true, then the next http request is executed;
  If the condition is false, then the next http request is not executed;


Click the image for the original photo
    

- In the "Open Bug Details page if bug id < 58000" If Controller, create a http request:

                                                                                                       *** this matches requirement 5b1


Name = Bug Details Page
Server name or IP = issues.apache.org/bugzilla
Path = /show_bug.cgi?${ResultValue}


Click the image for the original photo

 

- In the "Bug Details Page" http request, add a bean shell assertion:

                                                                                                       *** this matches requirement 5b2


Name = assertions
String myResultValue = vars.get("ResultValue"); 
String myBugId = "";
myBugId = myResultValue.substring(3,8); 
String body= new String(ResponseData); 
if(!body.contains("ASF Bugzilla")) 
log.warn("- could not find ASF Bugzilla in the page");
else
log.info("- found ASF Bugzilla in the page");
if(!body.contains(myBugId) ) 
log.warn("- could not find the bug id in the page");
  else    
log.info("- found the bug id in the page");


Click the image for the original photo



Run the load test

0 Response to "Create a load test plan with JMeter"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel