JMeter study notes 15-How to use JMeter for interface testing

This article introduces how JMeter does web service testing. Generally speaking, web services generally refer to content related to HTTP requests. Here's how to use JMeter to do HTTP-based web interface testing. The interface is also called API (Application Programming Interface). Many of the various APPs we use, the above content shows that most of them call the interface of the background web server, some are the interface of the website, and some are the interface of solr.

What is an interface?

       Here we give an example of a real-life scenario to help you understand the interface. Join you to order food at a restaurant, read the menu, and tell the waiter that you want a gong-pao chicken. After a while, the waiter will bring you a gong-pao chicken for dinner. In this scene, there are three objects, you, the waiter, and the chicken. The specific relationship is that you order the chicken, and the waiter takes the dish you ordered and tells the chef to cook it. After a while, the chef will cook it. Alright, the waiter will serve you the dish of Gong Bao Chicken. To simplify it a little bit, you tell the waiter that you want the chicken fried in the palace, and the waiter will give you the chicken fried in the palace in a while. In this process, the waiter is the function of an interface. You send a request for ordering food, and the waiter gives you the fried chicken, which is a response to the request.

       This kind of thing is called this in the software: when you order food, you send a request to the waiter, and the specific name of the dish is the incoming parameter; when the waiter serves you a dish, it means that it has responded to your request. The content of the response is that the chicken is fried in the palace. Another example of a practical application, our mobile phone desktop generally has a weather forecast, you set a region, it will show you the weather forecast for this region. The general principle of this process is that the mobile phone manufacturer or the weather forecast software, in some organizations that can provide weather services, applies for or simply spends money, and the software adjusts the weather API provided by the business structure of others. The specific weather data comes from these commercial organizations that provide weather services. Today we will test an interface about weather.

       Interface testing, the general process is: get an interface document, analyze what the request method is, mainly POST and GET methods, what is the request URL, how many parameters need to be passed in the request, what is the value of the parameter, and check the request response What is the code, and whether the content of the response has the return parameters described in the interface documentation. Interface testing can be done manually or automatically. The difficulty of automation is how to assert the response list.

 Weather interface service preparation

In order to write this article, I spent a lot of time looking for free weather APIs on the Internet, and basically found the domestic Sina Weather and a foreign website. On foreign websites, I didn't find the code for the Beijing area, so I can't get the weather information in Beijing through the API, so I won't talk about foreign ones here.

1. Open the Sina Weather website: http://php.weather.sina.com.cn/

2. Search for Beijing in the try input box, click the search button, and remember that the current URL is: http://php.weather.sina.com.cn/search.php?city=%B1%B1%BE%A9&dpc=1

Remember that city= %B1%B1%BE%A9

In fact, this field that looks like garbled code is a form of Beijing's escape display. Knowledge of the URI protocol is enough. Shanghai becomes a garbled field similar to the above, but definitely different.

3. Let's take a look at this excuse request address

http://php.weather.sina.com.cn/xml.php?city=%B1%B1%BE%A9&password=DJOYnieT8234jlsK&day=0

 

Explain the split (compared to the JMeter http request interface):

domain: php.weather.sina.com.cn

path: /xml.php

 

There are three parameters in total, namely city, password and day. The password is fixed, day=0 represents the current day, day=1 represents tomorrow, and so on:

参数1:  key:city                   value:%B1%B1%BE%A9

参数2:  key:password         value:DJOYnieT8234jlsK

Parameter 3: kye:day value:0

 

After understanding these, let's take a look at how to use JMeter to implement the interface test of this Beijing weather query.

1) Open the JMeter UI interface

2) Create a new Thread Group

3) Create a new Sampler and select HTTP Request

4) Create a new listener and select View Result Tree

5) HTTP Request interface settings as shown below

 

6) Click to run the test

7) View results

-Click View Results Tree to view the results and find garbled characters

 

- Change text to document and look again

 

You can also go to the Sampler result tab to check whether the response status code is 200.

Well, how to use JMeter to do interface testing is introduced here.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325269271&siteId=291194637