Jmeter correlation test case (China Weather Network)

Jmeter correlation test case (China Weather Network)

China Weather Net: http://www.weather.com.cn/ Weather in
a certain city: http://www.weather.com.cn/weather1d/101020100.shtml#search

But there is a city code (101020100) that is not fixed. It is necessary to obtain the code numbers of different cities according to the test data, and then query the weather conditions of the city.
The conclusion drawn after the analysis is to first request an interface that can obtain the city code, and pass the obtained code to the address for obtaining weather information.

The request form is:
http://www.weather.com.cn/weather1d/${citycode}.shtml#search, where {citycode} of {citycode}.html is the previous request (to query the citycode of a certain city). Value.

Step1:

1) Add a user variable city.

Insert picture description here

2) Add a thread group to the test plan TestPlan. Add the first HTTP Sampler, named GetCityCode (the purpose of this request is to get the city code).

Add the HTTP header manager http://www.weather.com.cn, the purpose is to "simulate the operation of the user opening the browser as much as possible". Before checking the weather in a certain city, you must first open the China Weather website.
Insert picture description here

Fill in the requested information again.
Server: toy1.weather.com.cn-This website uses names to parse city codes, both Chinese and English are supported.
Path: /search?cityname=${city}

For example: toy1.weather.com.cn/search?cityname=Shanghai
Insert picture description here

3) Add a post processor: BeanShell PostProcessor, used to process the Chinese garbled display of the response result;
Insert picture description here

4) Add a Debug Sampler, add view result tree, used for debugging, view regular extraction results

Insert picture description here

Step2:
Add a post processor and use the regular extractor to take out the obtained city code.
Insert picture description here

Reference name: citycode
Regular expression: (\d{9})~, pay attention to the left and right boundaries
Template: 1 11
matches the number: 1, if it is 0, it is obtained randomly, then it may not match the city...

After sending the request, check the information obtained by the dug sampler.
Insert picture description here

In the result, there are 4 related to citycode obtained, and the latter ones can be used to be called, we just use citycode.

Step3:
Add a second HTTP Sampler and name it GetWeatherInfo. The request information is as follows.
http://www.weather.com.cn/weather1d/${citycode}.shtml#search

Insert picture description here

The city code returned from the first request should be used in the route to bring up the specific value. /weather1d/${citycode}.shtml#search, should be consistent with the reference name in the regular extractor in Step2.

Step6:
View the result tree, showing that the response data returned by the request is correct.

Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_42586933/article/details/108572913