目标: 获取城市的天气数据:html
第一步: 发送request 获取城市的城市代号
http://toy1.weather.com.cn/search?cityname=上海 正则表达式
从这个请求的response 中获取到上海的城市代码. 线程
第二步: 发送request 到: http://www.weather.com.cn/weather2d/101020100.shtml 能够获得该城市的天气数据3d
必须新建一个Thread Group, jmeter的全部任务都必须由线程处理,全部任务都必须在线程组下面建立。code
好比要发送一个Get 方法的http 请求: http://toy1.weather.com.cn/search?cityname=上海 以下图:htm
选中上一步新建的HTTP request. 右键,新建一个Http Header manager. 添加一个headerblog
View Results Tree 用来看运行的结果ci
至此,运行已成功字符串
选择HTTP Request, 右键 Add-> Assertions -> Response Assertion. 添加 Patterns To Testit
添加一个Assetion Results 用来查看Assertion执行的结果.
选中Thread Group 右键 Add -> Listener -> Assertion Results.
运行后, 若是HTTP Response中没有包含期待的字符串。 那么test 就会Fail
咱们能够在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 中取来的
到这, 就所有写好了, 运行看最终结果