JMeter API Testing Basics查询各大城市天气情况

API Keys

First off, we’ll need an API Key from the Open Weather API.

You can quickly get a free Open Weather API key by creating a basic account on their signup page.


Break the API

Examples of API calls:
api.openweathermap.org/data/2.5/weather?q=London,uk&appid=xxxxxxxxxxx


Protocol-http
IP———api.openweathermap.org
Path-——/data/2.5/weather # this is before Question mark


parameters-
q=suzhou
appid=4e0f6be15c95005cfa5820249166033a

Create Http Request in Jmeter

Add a Listener

Before running we need to add a listener.Listener would show the request and the respense.
Right click on the TestPlan > Select Listener > Add Results in a Tree Listener

run the plan

green means that you have got a success.
So here you see the request made was-
GET
http://api.openweathermap.org/data/2.5/weather?q=suzhou&appid=4e0f6be15c95005cfa5820249166033a

Respons

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
{
: "coord":
: {
: : "lon":120.62,
: : "lat":31.31
: },
: "weather":
: [
: : {
: : : "id":800,
: : : "main":"Clear",
: : : "description":"clear sky",
: : : "icon":"01d"
: : }
: ],
: "base":"stations",
: "main":
: {
: : "temp":292.15,
: : "pressure":1027,
: : "humidity":42,
: : "temp_min":292.15,
: : "temp_max":292.15
: },
: "visibility":10000,
: "wind":
: {
: : "speed":2,
: : "deg":170
: },
: "clouds":
: {
: : "all":0
: },
: "dt":1509418800,
: "sys":
: {
: : "type":1,
: : "id":7452,
: : "message":0.0049,
: : "country":"CN",
: : "sunrise":1509401534,
: : "sunset":1509440973
: },
: "id":1886760,
: "name":"Suzhou",
: "cod":200
}

Put an assertion

in the respense you need to get type=1 for this test case to pass.

Right click on the Test plan and from the assertion list select Response Assertion.

From the response select - “type”:1 and add this to the response assertion.

Now run the test plan again.

You can also add an assertion listener to see the assertion results.then run it again.