Examples of actual test
Goal: get weather data City:
The first step: Send request to obtain urban city code
http://toy1.weather.com.cn/search?cityname= Shanghai
Obtained from the response to the request of the Shanghai city code such as:
Shanghai area code is 101 020 100
Shanghai Zoo is the area code: 10102010016A
Step 2: Send request to: http://www.weather.com.cn/weather2d/101020100.shtml can get weather data for the city of
Step one: Create a Thread Group
Must create a Thread Group, jmeter all tasks must be handled by a thread, all tasks must be created in the thread group below.
Step Two: Create a HTTP Request
For example, I want to send a http request Get method: http://toy1.weather.com.cn/search?cityname= Shanghai
So to fill in the following diagram
The third step is to add HTTP Head Manager
Select step on the new HTTP request. Right, create a new Http Header manager. Add a header
Step 4: Add the View Results Tree
View Results Tree is used to view the results of the operation
Step five: Run a test to see results
to here. We have successfully up and running.
Step Six: Adding Assertion and Assert Results
Select the HTTP Request, right Add-> Assertions -.> Response Assertion added Patterns To Test
Then add a Assetion Results to view the results Assertion execution.
Select the Thread Group Right Add -> Listener -> Assertion Results.
运行后, 如果HTTP Response中没有包含期待的字符串。 那么test 就会Fail.
第7步: 使用用户自定义变量
我们还可以在Jmeter中定义变量。 比如我定义一个变量叫 city. 使用它的时候用 ${city}
添加一个 User Defined Variables. 选中Thread Group: 右键 Add -> Config Element -> User Defined Variables.
我们添加一个变量: city
然后在Http Request中使用这个变量
第八步:关联
所谓关联, 就是第二个Requst, 使用第一个Request中的数据
我们需要在第一个Http Requst 中新建一个正则表达式,把Response的值提取到变量中,提供给别的Http Request 使用
选择第一个Http Request, 右键 Add -> Post Processors -> Regular Expresstion Extractor
现在新建第二个Http Request, 发送到: http://www.weather.com.cn/weather2d/${citycode}.html
${citycode} 中的数据, 是从Regular Expression Extractor 中取来的
到这, 脚本就全部写好了, 运行下,看下最终结果