Let's know the way how do we use the JMeter briefly.

1. Install the ‘Tomcat’

Download apache-tomcat-8.5.50.zip

Let’s move this ‘.zip’ file into your project directory. and please unzip the file. then You can see the directory named same with the ‘.zip’ file.

1
unzip apache-tomcat-8.5.50.zip

Download jmeter.war

Let’s download the ‘jmeter.war’ file. It will help you to understand about the way how it works. This file isn’t special just You can approach the web service more easily. After completing, You should move the file to ‘apache-tomcat-8.5.50/webapps’ directory.

1
apache-tomcat-8.5.50/webapps> move jmeter.war

Let’s execute your tomcat service using ‘apache-tomcat-8.5.50/bin/startup.sh’ from the ‘terminal’

1
2
apache-tomcat-8.5.50> cd ./bin
apache-tomcat-8.5.50/bin> sudo ./startup.sh

Sometimes you may need the ‘chmod’ command for changing the authority of the ‘startup.sh’ file. otherwise It’s not working.

http://127.0.0.1:8080/jmeter/search/index.html

If you enter the above link then you can see the below picture, Your ‘Tomcat’ was installed perfectly.

2. Install the ‘JMeter’

Download apache-jmeter-5.2.1.zip

Let’s download the ‘jmeter’ from the above link. and unzip the file.

Download jmeter-plugins-manager-1.3.jar

It will show the graphical the status about your test request. You should put down this file into ‘/lib/ext’

1
apache-jmeter-5.2.1/lib/ext> move meter-plugins-manager-1.3.jar

Let’s execute your jmeter service using ‘apache-jmeter-5.2.1/bin/jmeter.sh’ from the ‘terminal’

1
2
apache-jmeter-5.2.1> cd ./bin
apache-jmeter-5.2.1> sudo ./jmeter.sh

3. JMeter simple test.

First of all, We will test your service is well or not just using the response code. like ‘200’, ‘404’ and The below is our test scenario.

1
2
3
4
5

- 1. http://127.0.0.1:8080/jmeter/index.html GET

- 2. http://127.0.0.1:8080/jmeter/search/search?key=jmeter POST

Let’s make the ‘Thread Group’. It’s the collection of something like the users. These thread will request to your service as your configuration. and You can configure the number of the thread and the time for setting …

1
Test plan > Right click > Add > Threads (Users) > Thread Group
1
2
3
4
5

- Number of Threads : 10

- Loop Count : 10

Secondly, We should create the ‘HTTP Request Default’. in here, You can control the overall setting associated to the HTTP Connection. like Server IP, Domain, Port, Url…

1
Thread Group > Right Click > Add > Config Element > HTTP Request Defaults
1
2
3
4
5

- Server Name or IP : 127.0.0.1

- Port Number : 8080

Additionally, If you want to control the Header and the Cookie, then you can use ‘HTTP Header Manager’, ‘HTTP Cookie Manager’ at that time.

It’s actual the task to request some service to your project. You should create two things of this.

1
Thread Group > Right Click > Add > Sampler > HTTP Request
1
2
3
4
5
6
7
8
9
10
// First One
- Name : /jmeter/index.html
- Path : /jmeter/index.html
- Method : GET

// Second One
- Name : /jmeter/search/search?key=jmeter
- Path : /jmeter/search/search?key=jmeter
- Method : POST

Importantly, Your ‘HTTP Request Defaults’ setting should be located more higher than the ‘HTTP Request’ because all of the settings are applied only to the lower things.

And you have to add the listeners to two ‘HTTP Request’. They are for the monitoring your test.

1
2
3
4
5

1. Thread Group > Right Click > Add > Listener > View Result Tree

2. Thread Group > Right Click > Add > Listener > Summary Report

Let’s execute the test

4. If you want to put the parameters dynamically using ‘.csv’

Please move the ‘HTTP Request Defaults’ item to outside of ‘Thread Group’. because It will use continuously. and We should disable about the above codes ‘Thread Group’ for this coding except ‘HTTP Request Defaults’. and Let’s make new one. Finally Copy and pase the ‘/jmeter/search/search?key=jmeter’ without parameter.

1
2
3
4
5
6
7
8
9

Thread Group > Right Click > Disable

Test plan > Right click > Add > Threads (Users) > Thread Group

Copy and Paste '/jmeter/search/search'

And change the Number of Thread option to '10' from new 'Thread Group'

‘JMeter’ offer the function to change the parameters when you test your project. For that, You have to create the ‘.csv’ file. It’s named ‘search_keyword.csv’

1
2
3
4
5
6
7
8
9
10
11
12
13
14
// search_keyword.csv

number, search_keyword
0, 0keyword
1, 1keyword
2, 2keyword
3, 3keyword
4, 4keyword
5, 5keyword
6, 6keyword
7, 7keyword
8, 8keyword
9, 9keyword

This file should save into the directory having the save file(.jmx) of this. In my case, It’s root directory. and We should get this file into the JMeter program.

1
'/jmeter/search/search' > Add > Config Element > CSV Data Set Config

Configure like the below.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

Filename : Find your 'search_keyword.csv' file using browser.

File encoding :

Variable Names : number,search_keyword

Ignore first line : True

Delimeter : ,

Allow quoted data : False

Recycle on EOF ? : True

Stop Thread on EOF ? : False

Sharing mode : All Threads

And Add the parameter from the ‘/jmeter/search/search’.

1
2
3
4
5
6
7
Press Add Button.

Name: Key

Value : ${search_keyword}

URL_Encode : clicked

Let’s execute the test.

You have to compare between the parameters of the above codes. First one has the ‘2keyword’, and Second one have the ‘5keyword’.

5. If you want to redirect dynamically after page.

Before doing this step, You should disable your previous task like the above. and Create new ‘Thread Group’

1
2
3
4
5
6
7
8
9

Thread Group > Right Click > Disable

Test plan > Right click > Add > Threads (Users) > Thread Group

Copy and Paste '/jmeter/search/search', And please empty the value of parameter without key

And change the Number of Thread option to '10' from new 'Thread Group'

Let’s see the response of the ‘/jmeter/search/search’. It has a lot of url so we will redirect that url using regular expression extractor.

1
'/jmeter/search/search' > Add > Post Processors > Regular Expression Extractor 
1
2
3
4
5
6
7
8
9
- Name of created variable : next_url

- Regular Expression : class="url">\( <a href="(.+?)://([^:]+?):*([0-9]*?)/(.*?)"

- Template ($i$ ...) : $2$

- Match No. : 0

- Default Value

And We have to create to connect for the next url. that is we need ‘HTTP Request’ one more.

1
2
3
4
5
Thread Group > Add > Sampler > HTTP Request

HTTP Request > Add > Listener > View Result Tree

HTTP Request > Add > Listener > Summary Report

Follow the below setting.

1
2
3
4
5
6
7
8
9
Name : next_url - ${next_url}

Protocol : ${next_url_g1}

Server Name or IP : ${next_url_g2}

Port Number : ${next_url_g3}

Path : ${next_url_g4}

Let’s execute the test

You can see the ‘next_url’ variable is different when it happened.

6. If you want to make the custom error on 200 response.

Let do disable your previous things. and Create new one. and It’s really different. We will create 4 ‘HTTP Request’ items.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

- Create 4 'HTTP Request'

Each name is the below.

- No Assertion

- Duration Assertion

- Size Assertion

- Response Assertion

- Create Listeners.

We should modify the ‘HTTP Request defaults’ file. please add the below url into the ‘path’

1
path : /jmeter/index.html

And We will give the Assertion to each ‘HTTP Request’

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

Duration Assertion

- Add > Assertions > Duration Assertion

- Duration in milliseconds : 1000

Size Assertion

- Add > Assertions > Size Assertion

- 500 and pres '>' button

Response Assertion

- Add > Assertions > Response Assertion

- Write 'Error occur!!'

- Press 'Contains' button and 'Not'

Let’s execute the test

JMeter Lecture

Share