0% found this document useful (0 votes)
38 views273 pages

Ruben Getting Started

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views273 pages

Ruben Getting Started

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 273

Getting started with JMeter

A short and sweet introduction

Ruben Olsen Lærk – [email protected] – http://www.lku.no/ - http://www.knowit.no/ 1


Ruben Olsen Lærk
Stuff I do SQL SIP
Cats
Lean  Agile  Kanban coaching & training
OpenSource IAX
Java
PHP Log management
OSX
perl Board games
Automatic Build & Deploy GO lang
(Modular) (Analogue) Synthesizers
Unix & derivates
Load testing
Quality Assurance
4
Our agenda

Ruben Olsen Lærk – [email protected] – http://www.lku.no/ - http://www.knowit.no/ 5


In part 1, I am going to cover

• JMeter in a nutshell • Test Data


• Running JMeter • Plugins
• Hardware and scaling • Extracting data
JMeter
• Assertions
• The JMeter testplan
• Reporting in the Cloud
• JMeter functions
• Organizing your test
plan

6
In part 2, we do a (simple) exercise
… to get you started on monday

1. Introduction to the application


2. Record the test using a browser
3. Cleaning up the recorded testplan
4. Parametrization
5. Adding test data
6. Using thread groups
7. Testing the testplan
8. Running the testplan 7
What I am not going to cover

• What performance testing is (and is not)


• The (idiotic) demand from management: Our
application must support 100 000 users!
• Different performance test types
• What constitutes a bottleneck in the system
• Performance testing methodology (unless we have
time at the end)

8
Skillset to using JMeter
JMeter is tech – you need some technical skills to survive

• Know how to download and install Java


• Know how to download, and unpack, a ZIP-file
• Know how to navigate the command line

9
Skillset to using JMeter
Testing web application require “web knowledge”

• You must know HTML – or at least understand HTML


• It’s good to know regular expression syntax
• It’s good if you know how to read JSON and XML
• It’s a plus if you know XQuery/Xpath
• It’s a plus if you know JSONPath
• It’s a BIG plus if you speak HTTP, or at least
understand how the HTTP protocol functions
(RFCs: 2616, 7230 – 7235, 5789, 6455 (WebSocket), and 7504 (HTTP/2))

10
Skillset to using JMeter
JMeter is tech – you need some technical skills to survive

• Know how to use a text editor


(Notepad is fine, Notepad++ is better, Sublime Text is cool – MS Word,
Excel, PowerPoint, WordPad, or TextEdit is not, but vi/Emacs For The Win)

• Know how to use the debug functionality in your web


browser
• Better: Know how to use a 3rd party proxy-tool

11
Introduction to JMeter

Ruben Olsen Lærk – [email protected] – http://www.lku.no/ - http://www.knowit.no/ 12


Tool – a lot of tools

• Load Runner (commercial from HP) • Qengine (AdventNet)

• RPT (commercial from HP) • Flood (Open Source)

• Microsoft Visual Studio • Web Application Testing tool


(commercial)
• OpenLoad (commercial)
• WatchMouse (commercial)
• OpenSTA (Open Source)
• WebKing, (commercial)
• PureLoad (commercial)
• WebServer Stress Tool
• PushToTest TestMaker (Open (commercial / free from
Source) Paessler)

13
How JMeter works

Start Simulated user The End


requests are
sent to the
server

Data is collected
Server sends
for statistical
replies back
purposes

JMeter saves all


responses
Reports

14
Distributed (scaled) setup

Load controller App. server RådServer

Load generators

15
JMeter in a nutshell

16
JMeter in a nutshell

• Open Source (Apache Foundation)


• More than one kind of testing
• HTTP/HTTPS

• SOAP

• Databases via JDBC

• JMS

• POP3(S)/IMAP(S)

• Extend by creating your own

17
JMeter in a nutshell – 2

• (More or less) user friendly GUI


• Full multithreading
• Cache and cookie-control
• Server monitoring
• Several built in reports available

18
JMeter in a nutshell – 2
übercool

Pack & Go
19
20
The JMeter Toolbar

21
JMeter lingo

22
JMeter functionality linguistics
The Big Picture

• Default configurations (variables)


• Thread Groups (number of concurrent users)
• Logical Controllers (test plan logic)
• Timers (human behaviour or think-time)
• Samplers (request-/responses – a.k.a. “the test” )
• Pre / Post Processing (data amendment / data extraction)
• Assertions (response testing)
• Listeners (reports)
• Functional Test Mode (optional) 23
Elements of a test plan
Our most important building blocks

• Thread Group
• Number of concurrent users, ramp up time, number of
iterations, etc
• Controllers
• The test plan logic

• Samplers
• Testing something, and getting a response

24
Elements of a test plan - 2
You do not really need these – but they will save your ass

• Configuration elements
• Default values, setups, variables, test data feeds, etc
• Pre processors
• Amend data before sending a request

• Post processors
• Extract data after receiving a response

25
Elements of a test plan - 3
Our nice to have building blocks

• Listener
• Reports and graphs
• Timers
• Emulate human behavior / think time

• Assertions
• Control and compare responses

26
A test plan example

• • Configuration elements
• Thread Group
• Controller + sampler
• Sampler
• Controller
• Override configuration
• Samplers
• Assertion
• Listeners
27
Test plan inheritance

28
Building blocks

29
Samplers
What’s possible to query

• HTTP/HTTS Request
• JDBC Request
• TCP Request
• Reading and sending Mail
• … and many others ...

30
Controllers
Logical building blocks for your test plan

• Transaction Controller • While Controller


• If Controller • Switch Controller
• ForEach Controller • Module Controller
• Include Controller • Recording Controller
• Once Only Controller • Random Controller
• Simple Controller • Random Order Controller
• Loop Controller • Throughput Controller
• Interleave Controller • Runtime Controller

31
Data parameterization

• CSV file(s)
• User defined variables
• Randomized values
• Amending existing data by pre processing
• Extracting data by parsing responses

... and several other ways

32
Data parameterization
Pre Processors

• RegEx User Parameters


• User Parameters
• BeanShell
• BSF
• HTML Link Parser
• HTTP URL Rewrite
• JDBC PreProcessor
• JSR223 PreProcessor 33
Data parameterization
Post Processors

• XPath Extractor
• Regular Expression Extractor
• JSON Path Extractor
• Results Expression Extractor
• JSON Format Post Processor
• CSS/JQuery Extractor
• JDBC Post Processor
• JSR233 & BeanShell Post Processor 34
Assertions
Sanity checking your responses

• Response Assertion • XML Schema Assertion


• Duration Assertion • BSF Assertion
• Size Assertion • JSR223 Assertion
• XPath Assertion • SMIME Assertion
• Compare Assertion • Bean Shell Assertion
• XML Assertion • MD5Hex Assertion
• HTML Assertion

35
Odd – but very important

36
Server Side Resource Monitoring

1. Place an agent on a remote server

2. Java monitoring ”out of the box”

37
38
Java Application Server Monitoring

39
Java Application Server Monitoring

40
Plugins

41
http://jmeter-plugins.org/

42
Part 2 of the workshop
Practial session

Ruben Olsen Lærk – [email protected] – http://www.lku.no/ - http://www.knowit.no/ 43


This is how we are going to play
The kinder garden variety ;-)

1. I show you a step on the screen


2. You repeat the step on your computer

There will be exercises!

44
What we are going to play with
The 95% usage pattern

We are going to use JMeter to test a


web-application through it’s front end

45
What you need to participate
(unfortunately, we cannot assist you during the break)

1. JMeter up and running


2. A web browser with proxy set to localhost, port 8080
3. Another web browser without any proxy set
4. A WIFI connection to
Network: JMeter Workshop
WPA password: jmeteriscool
5. Test by pointing the other web browser (#3) to
http://10.0.1.100/

46
Our demonstration application

47
The Spring PetClinic Application
Please go ahead and
play
• List owners and animals
• Add animal visit
• Add owner
• Add animal
• List veterinarians
• Home Page
http://10.0.1.100/petclinic/
• (ERROR)
Download from https://github.com/spring-projects/spring-petclinic
48
Tools for developing a JMeter test plan

49
A few ways to achieve the goal

• Manually build the test plan inside JMeter


• Talk with a developer
• Record your steps manually (i.e. using the web
browsers built in debug / addon functionality)
• Record your steps using 3rd party proxy tools
• Record your steps using JMeter as a proxy

50
Web browser tools
Avoid if you can, use if you must

• Firefox Addons
(FireBug, HttpFox, FireFox Live HTTP Headers, etc)

• FirefoxDeveloperEdition
• Internet Explorer F12
• Safari Web Inspector
• Chrome Developer Tools

51
A few 3rd party tools of the trade
Use if you can

• Betwixt – github.com/kdzwinel/betwixt
• Burp Suite – www.portswigger.net
• Charles – www.charlesproxy.com
• Fiddler – www.telerik.com/fiddler
• HTTP Scoop – www.tuffcode.com
• ZAP - www.owasp/index.php/ZAP

52
Using Blazemeter Chrome Extension
https://blazemeter.com/

53
Workshop method

54
This is how we are going to work

1. Record your interaction with the application


2. Remove unwanted “junk”
3. Mangle the test plan
4. Parameterize the test plan
5. Test the test plan

55
Recording a session with JMeter

56
How we are going to do it

1. Create a JMeter project as a HTTP(S) proxy


2. Configure a browser to use JMeter as a proxy

57
Start JMeter

58
Start JMeter

59
Save the test plan as ”recorder”

60
All test plans needs a Thread Group
Threads == Number of Concurrent Users

61
Thread Group Options

62
Thread Group Basics

• Set the number of threads (users)


• Configure Ramp-up time (time before full speed ahead)
• Set the number of times to execute the test

 Pro Tip:
Initial Ramp-up period == number of threads

63
Different Thread Groups

• Thread Group
• jp@gc – Stepping Thread Group
• jp@gc – Ultimate Thread group
• setUp Thread Group
• tearDown Thread Group

64
Stepping Thread Group

65
Ultimate Thread Group

66
We need a recording controller

67
This is where we store our recordings
(an exceptionally boring controller)

68
Let’s set up the Proxy

69
The Test Script Recorder Controller

Consider changing
this to port 9090

 Pro Tip:
You can record to any place in the test plan

70
Add include/exclude patterns

71
We want to see what’s happening
Add the View Results Tree Listener

72
The View Results Tree Controller

73
Remember to

SAVE
your plan!
74
Starting the JMeter proxy

75
Recording with your browser

76
Configuring the browser proxy settings

77
 Pro Tip:
Use a Proxy selector or switcher

• Firefox: Proxy Selector by Michele Pezza


• Chrome: Proxy SwitchyOmega by FelisCatus

78
What shall we test today?
How will the PetClinic application perform when we
1. Search for an pet owner
2. Add a visit to
one of owners
animals

79
Our Test Plan

1. Goto http://10.0.1.100/petclinic Owner names


1. Betty Davis
2. Click on menu “Find Owners”
2. Carlos Estaban
3. Enter a name 3. Davis Schroeder
4. Eduardo Rodriquez
4. Click on “Add Visit” on the owners
5. George Franklin
first animal
6. Harold Davis
5. Enter “<your name> haircut” 7. Jean Coleman
8. Jeff Black
6. Click on button “Add Visit”
9. Maria Escobito
10.Peter McTavis
80
Step 1
Goto http://10.0.1.100/petclinic

81
Step 2 – Click on Find Owners

82
Step 3a – Enter an owners name

83
Step 3b – Click on

84
Step 3b – Click on

85
Step 3b – Click on

86
Step 3b – Structured request

87
Step 3b – Raw or structured?

88
Step 3b – The Response

89
Enough with Step 3b!

Let’s continue!

90
Step 3c – Owner info + pets

91
Step 4 – Add a visit
Click on the Add Visit link

92
Step 4a – fill out the visitation form

93
Step 4b – click on

94
Step 4c – Back to the owner + pet
How this this happen?!

95
Step 4c – HTTP Redirect
Status code 302 + Location: header

96
Step 4c – HTTP Redirect
Status code 302 + Location: header

Follow Redirect creates


new separate HTTP requests

 Pro Tip: Redirect Automatically will


You want Follow
not Redirects most of the time
create new separate
HTTP requests

97
Step 4d – The Real McCoy
Nothing special

98
Step 4d – The Real McCoy
This Is The Place

99
Congratulation!
You have a successful recording!

100
Remember to
save your plan
with a new name!
Name: step1
101
Examples of other proxy tools

102
A few 3rd party tools of the trade
Use if you can

• Betwixt – github.com/kdzwinel/betwixt
• Burp Suite – www.portswigger.net
• Charles – www.charlesproxy.com
• Fiddler – www.telerik.com/fiddler
• HTTP Scoop – www.tuffcode.com
• ZAP - www.owasp/index.php/ZAP

103
Charles – charlesproxy.com

104
Burp Suite – Portswigger.net

105
Removing unwanted junk

106
This is how we are going to work

1. Record your interaction with the application


2. Remove unwanted “junk”
3. Mangle the test plan
4. Parameterize the test plan

107
What is unwanted junk?

Unwanted junk is everything (i.e. All Embedded


Resources) that is automatically fetched by the web
browser

• JavaScript (.js)
• Images (.png, .jpg, .gif)
• CSS (.css)

108
What to keep and what to junk

.CSS

.JS

.PNG

109
Remove this!

110
What about the HTTP Redirect?

BTW – we do not
need these anymore
111
This is where you should end up

DO IT NOW

112
Congratulation!
You have cleaned your plan!

113
Remember to
save your plan
with a new name!
Name: step2
114
Mangle the test plan

115
This is how we are going to work

1. Record your interaction with the application


2. Remove unwanted “junk”
3. Mangle the test plan
4. Parameterize the test plan
5. Test the test plan

116
Our starting point

These are config elements:


HTTP Header Manager

We only need one


HTTP Header Manager

117
Keep some some config elements

Delete the Referer property

Remove the other HTTP


Header Managers
Move one HTTP Header Manager
right under the Test Plan
118
The HTTP Request Sampler
Where the magic happens

119
Anatomy of the HTTP Reqeust Sampler

120
HTTP POST Request

121
What do all HTTP Request have in
comon?
• HTTP host
• HTTP port
• HTTP protocol

The solution is to use a HTTP Request Default


configuration element

122
Add a HTTP Request Default config

123
HTTP Request Default config element

Add whatever default


configurations you need

You need to change the


Server Name or IP

124
Amending the HTTP Request – part 1
We need to do this for all HTTP Request samplers

Remove everything that is in


the HTTP Request Default

125
Amending the HTTP Request – part 2
Drag the sampler directly under the Thread Group

126
Amending the HTTP Request – part 3
Rename the sampler to a logical name (home page)

 Pro Tip:
Prefix the name with a sequence number

127
Let’s repeat for all HTTP samplers

1. Remove any values we find in the HTTP Request


Defaults
2. Move sampler directly under the Thread Group
3. Rename sampler to a logical name
Keep the samplers in the correct order

128
The web form

Remove any Session IDs

Move below 100


Remove default values
Rename to
200 Find Owners

129
The search results

Remove any Session IDs

Move below 200


Remove default values
Rename to
300 Search Result

130
Parameterization

131
The search result is based on input

132
We need to parameterize
JMeter variables

• Syntax ${VariableName}
• Several sources
• User Defined Variables
• Data from CSV files
• Extracted from sampler responses

• Can be used almost everywhere

133
Adding Test Plan variables

 Pro Tip:
Never add variables here, it’s confusing

134
Test data

Rename to
Test Data Variables

 Pro Tip:
Add variable sets for the environment(s)
Add variable: OwnerLastName
Value: Davies
135
Environment Variables

136
Parameterizing the search results page

137
Parameterizing the HTTP defaults

138
 Pro Tip:
Try to identify all variables before you start

139
Let’s mangle some more

140
Show owner

Parameterize
Remove this IDs
any Session

Move below 300


Remove default values
Rename to
400 Show owner info

${OwnerID}

141
Show visitation form

Parameterize this
Move below 400
Remove default values
Rename to
500 Show visitation form

Exercise:
/petclinic/owners/2/pets/2/visits/new
1) Rename form to 500 Show visitation form
2) Remove default values ${OwnerID}
/petclinic/owners/${OwnerID}/pets/${PetID}/visits/new
3) Move to correct position below the Thread Group
4) Parameterize the Path (hint: you already have ${OwnerID})
142
Save visitation

Parameterize this
Move below 500
Remove default values
Rename to
… and these
500 Show visitation form

Exercise:
1) Rename request to 600 Save visitation data
2) Remove default values ${OwnerID}
3) Move to correct position below the Thread Group
4) Parameterize what ever needs to be parameterized
143
Remove the Recording Controller

144
Congratulation!
You have created your Test Plan!

145
Remember to
save your plan
with a new name!
Name: step3
146
Testing the Test Plan

147
This is how we are going to work

1. Record your interaction with the application


2. Remove unwanted “junk”
3. Mangle the test plan
4. Parameterize the test plan
5. Test the test plan

148
Debug with Results Tree Sampler

149
Test the plan – press Play

150
Inspect the results

151
Change sampler, and re-run

152
Inspecting the results

Why two results?

153
Why do this happen?

 Pro Tip:
You want Follow Redirects most of the time

154
Congratulation!
Your plan is free of bugs!

155
Remember to
save your plan
with a new name!
Name: step4
156
Next steps

157
Where to go next

• Dynamic visitation date


• Iterate over a file with test data

We will also:
• Extracting data from a response
• Using the extracted data as input to a test step

158
But first – a new exercise
Extend the current test plan by:

1. Creating a new owner – use your own name


2. Add a pet to the new owner

Hints:
1. Disable all the test steps you have so far
2. Start a new JMeter, and record the steps
3. Use the recorded steps in your primary test plan

159
Recording stuff
Two interesting screens:
Add Owner and Add New Pet

160
The recorded owner

Rename to
Remove
Copydefault
to the values
other JMeter
700 Add New Owner
Ctrl-C (win) Cmd-C (Mac)

161
The recorded owner

Paste into the Thread Group


Ctrl-V (win) Cmd-V (Mac)

162
The recorded pet

Rename to
Remove default values 800 Add New Pet
Copy to the other JMeter
Ctrl-C (win) Cmd-C (Mac)

163
The recorded pet

Paste into the Thread Group


Ctrl-V (win) Cmd-V (Mac)

164
There is a slight problem here!

We really do not know if our


new owner always had this ID

Solution – let’s extract some


data by adding a new owner
165
Let’s investigate - 1

Then clear and execute the test

Start by disabling
800 Add New Pet to Owner

166
Let’s investigate - 2
Investigating the data

167
Let’s investigate - 3
Extracting data from the results

168
Let’s investigate - 4
Data extraction using Regular Expressions

 Pro Tip:
9 out 10 times you want the extraction to
apply to Main samples and sub-samples

169
Let’s investigate - 5
We need a debugger

170
Let’s investigate - 6
Clean-up and run

171
Let’s fix 800 Add New Pet to Owner

${OwnerID}

172
Clean up and run 3 times

173
Congratulation!
Your plan is even cooler now!

174
Remember to
save your plan
with a new name!
Name: step5
175
The last preparations

176
This is what we are going to do

• Dynamic visitation date


• Iterate over a file with test data

177
Disable / enable stuff
We need to get back to sane configuration

DO IT NOW

178
Dynamic date

179
We want to use the current date
… by using a JMeter function

180
Built in JMeter functions
Kind of function Function name Description
Information threadNum get thread number

Information samplerName get the sampler name (label)

Information machineIP get the local machine IP address

Information machineName get the local machine name

Information time return current time in various formats

Information log log (or display) a message (and return the value)

Information
Java SimpleDateFormat
logn log (or display) a message (empty return value)

Input StringFromFile read a line from a file

Input FileToString read an entire file

Input CSVRead read from CSV delimited file

Input XPath Use an XPath expression to read from a file

Calculation counter generate an incrementing number

Calculation intSum add int numbers

Calculation longSum add long numbers


181
Built in JMeter functions
Kind of function Function name Description
Calculation Random generate a random number

Calculation RandomString generate a random string

Calculation UUID generate a random type 4 UUID

Scripting BeanShell run a BeanShell script

Scripting javaScript process JavaScript (Mozilla Rhino)

Scripting jexl, jexl2 evaluate a Commons Jexl expression

Properties property read a property

Properties P read a property (shorthand method)

Properties setProperty set a JMeter property

Variables split Split a string into variables

Variables V evaluate a variable name

Variables eval evaluate a variable expression

Variables evalVar evaluate an expression stored in a variable

String regexFunction parse previous response using a regular expression


182
Built in JMeter functions
Kind of function Function name Description
String escapeOroRegexpChars quote meta chars used by ORO regular expression

String char generate Unicode char values from a list of numbers

String unescape Process strings containing Java escapes (e.g. \n & \t)

String unescapeHtml Decode HTML-encoded strings

String escapeHtml Encode strings using HTML encoding

String urldecode Decode a application/x-www-form-urlencoded string

Encode a string to a application/x-www-form-urlencoded


String urlencode
string

String TestPlanName Return name of current test plan

183
Dynamic date

${__time(yyyy/MM/DD)}

184
Let’s run this
Clear your plan – and press Play

We clearly need to debug this!

185
Debug your plan – part II

1. We need to add the Debug Post Processor


(at the correct place in the plan)

2. We need to se all traffic that goes on during the test

186
Adding some debugging
… but also prepare the plan for real load testing

 Pro Tip:
Always add the debugger on the thread,
or on the plan level – then you have control

187
Let’s run again

188
Let’s run again

${__time(yyyy/MM/DD)}
${__time(yyyy/MM/dd)}

189
Let’s run again

190
Test data from a file

191
petclinic_data.csv
Owner, ID, Owner Name, Pet ID

1,Franklin,1 6,Coleman,7
2,Davis,2 7,Black,9
3,Rodriquez,3 8,Escobito,10
3,Rodriquez,4 9,Schroeder,11
4,Davis,5 10,Estaban,12
5,McTavish,6 10,Estaban,13
6,Coleman,8

192
What we are going to do

• Set up JMeter to read from the petclinic_data.csv file


• Iterate over the plan using the Owner ID and Pet ID to
add a visit

193
1. Duplicate our Test Data Variables

194
2. Rename the Config Element
DEVELOPMENT Test Data Variables

195
3. Rename the other Config Element
TEST RUN Test Data Variables

 Pro Tip:
use INITIAL
Always declare VALUE
all variables

196
4. Add the CSV data reader

197
5. Configure the CSV Data Set Config

 Pro Tip:
Parameterize this – do not hard code name

198
6. Getting ready to test

199
7. Adding another debugging element

200
8. Clean test plan, then Run Plan

201
9. More reports
=> more Listeners
What do you need to measure?
• Response times (over time)
• Response Times Percentiles
• Response Time Distribution
• Response Codes Per Second
• Response Latencies over Time
• Transaction Troughput vs Threads
• Simple Data Writer 202
You add some listeners

• Summary Report
• Response Time over Time
• Response Times Percentiles
• Response Time Distribution

203
Congratulation!
Your plan is done!

204
Remember to
save your plan
with a new name!
Name: final
205
Let’s do some testing!

206
Let’s run and look at reports

 Pro Tip:
When performing real testing, disable all
debugging

207
Let’s re-run and look at reports
Summary report

208
Response Time Distribution
The Main View

209
Response Time Distribution
Selecting rows

210
Response Time Distribution
Back to the Main View

211
Response Time Distribution
Settings view

212
Response Time Distribution
Back to the Main View

213
Response Times Over Time

214
Response Time Percentile

215
A real test run example

216
Stepping Thread Group

217
Active Threads Over Time

218
Simple Data Writer

219
Summary Report

 Pro Tip:
Look for errors, consistency and outliers

220
Response Times Distribution

221
Response Times Over Times - 200

222
Response Times Over Times - 300

223
Response Times Over Times – ex 300

 Pro Tip:
Requests that follow each others are good

224
Response Times Percentiles - 1

 Pro Tip:
Start big, then drill down

225
Response Times Percentiles - 2

226
Response Times Percentiles - 3

227
Response Times vs Threads - 1

 Pro Tip:
We hate fluctuations!
Fluctuations == Broken software

228
Response times vs Threads – 2

 Pro Tip:
Stable response times with increased
threads => we have a stable application

229
Response times vs Threads – 3

230
Response Codes per Second

231
Transaction Throughput vs Threads

 Pro Tip:
Look for correlations in the data

232
Transactions per Second

233
Transactions per Second

234
Testing REST APIs

Ruben Olsen Lærk – [email protected] – http://www.lku.no/ - http://www.knowit.no/ 235


This is what we are going to do

1. Fetch a list of employees and their vacations


2. Create a new vacation for <insert your name>
3. Change the vacation time for <your name>
4. Fetch a list of employees and their vacation times
5. Delete <your name>’s vacation

236
Some technical data

• REST endpoint is at http://10.0.1.100/rest/


• Fetch all vacations GET /rest/holiday-request
• Create new vacation POST /rest/holiday-request
• Change vacation PUT /rest/holiday-request
• Delete holiday DELTE /rest/holiday-request/${ID}

237
Some technical data

• REST endpoint is at http://10.0.1.100/rest/


• Fetch all vacations GET /rest/holiday-request

• Create new vacation POST /rest/holiday-request

• Change vacation PUT /rest/holiday-request

• Delete holiday DELETE /rest/holiday-request/${ID}

238
User Defined Variables
For test data

• EmployeeName Ruben Olsen Lærk


• EmployeeID 681124
• VacationDateStart 2016-08-01T00:00:00
• VacationDateEnd 2016-08-01T00:00:00

239
User Defined Variables
For the test environment

• HTTPServerName http://10.0.1.100
• HTTPServerPort 80
• HTTPServerProtocol http
• ContextRoot /rest/holiday-requests
GET /rest/holiday-request

POST /rest/holiday-request

PUT /rest/holiday-request

DELETE /rest/holiday-request/${ID}

240
Start a new JMeter project
Copy your last JMX and delete what you do not need

• Thread Group with 1 user, and 1 loop-


count
• HTTP Request Defaults
• User Defined Variables for test data
EmployeeName, EmployeeID,
VacationDateStart, VacationDateEnd
• User Defined Variables for environment
HTTPServerName, HTTPProtocol, HTTPPort,
ContextRoot
241
The Thread Group

242
The HTTP Request Defaults

GET /rest/holiday-request

POST /rest/holiday-request

PUT /rest/holiday-request

DELETE /rest/holiday-request/${ID}

243
User Defined Variables
For test data

• EmployeeName Ruben Olsen Lærk


• EmployeeID 681124
• VacationDateStart 2016-08-01T00:00:00
• VacationDateEnd 2016-08-01T00:00:00

244
User Defined Variables
For the test environment

• HTTPServerName http://10.0.1.100
• HTTPServerPort 80
• HTTPServerProtocol http
• ContextRoot /rest/holiday-requests
GET /rest/holiday-request

POST /rest/holiday-request

PUT /rest/holiday-request

DELETE /rest/holiday-request/${ID}

245
Let’s build the test

246
Fetch Employee Holidays
GET /rest/holiday-requests

247
Let’s run
Remember to add a View Results Tree Listener

248
A better view

249
Create new vacation
POST /rest/holiday-requests

{
"employeeId": 688,
"employeeName": "Stephen Lee",
"startDate": "2014-07-01T00:00:00Z",
"endDate": "2014-07-08T00:00:00Z"
}

250
Create new vacation
POST /rest/holiday-requests

{
"employeeId": ${EmployeeID},
"employeeName": "${EmployeeName}",
"startDate": "${VacationDateStart}",
"endDate": "${VacationDateEnd}"
}

251
Create a new vacation
Uinsg JSON and POST data

252
Let’s run
HTTP Content Type MAY matter

253
Add a HTTP Header Manager

254
Let’s run
Hmmmm……

255
Let’s run
Yay! Success!

We need to extract the ID = 9

256
Using the JSON Path Extractor
Post Processors for the win

257
Use a proper JSON tool
Power JSON Editor

 Pro Tip:
Get good tools for bulidng JSONPath, Xpath,
and Regular Expressions
258
Using the Regular Expression Extractor
Post Processors for the win

 Pro Tip:
Regular Expr. Extractor is supposedly faster

259
Modify vacations
PUT /rest/holiday-requests

{
"id”:6,
"employeeId": 688,
"employeeName": "Stephen Lee",
"startDate": "2014-07-01T00:00:00Z",
"endDate": "2014-07-08T00:00:00Z"
}

260
Modify vacation
POST /rest/holiday-requests

{
"id":${id},
"employeeId": ${EmployeeId},
"employeeName": ”${EmployeeName}",
"startDate": "2014-07-01T00:00:00Z",
"endDate": "2014-07-08T00:00:00Z"
}

261
Modify vacation request
REST payload are always done as a HTTP body!

262
Let’s run
Yay! Success!

263
List all vacations – once more
GET /rest/holiday-requests

There are two approaches:

1) Copy/paste – thus replicating code – NO! NO! NO! NO!

2) Use a Module Controller

264
The Module Controller
Modularization for the win!

The Module Controller can take


any modules and include those
modules anywhere in the test plan
(modulo creating a infinite loop)
Group by using a
a) Simple Controller – or a
b) Transaction Controller
Let’s add a Simple Controller and
move 100 Fetch Employee
Holidays inside this controller.
265
Adding the simple controller
Rename to 100 Fetch Employee Holidays

266
Reorganize!
Do a test run to see if it’s still produce the expected results!

267
Include the module Controller
What will we name this step?

 Pro Tip:
Continue the number sequence
400 Fetch Employee Holidays

268
Let’s run to see if we are still on track

269
Delete the Employee Holiday request
DELETE /rest/holiday-requests/${id}

270
Another run for success?
JMeter honour HTTP response codes, not the payload!

No Response Data is found!

271
Wrap up with listing all holidays

272
Takk for meg
Ruben Olsen Lærk

Ruben Olsen Lærk – [email protected] – http://www.lku.no/ - http://www.knowit.no/ 273

You might also like