码迷,mamicode.com
首页 > 其他好文 > 详细

Gatling入门简单使用

时间:2020-06-09 09:26:06      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:查点   use   rate   场景   check   pre   脚本   接口   入门   

相比loadrunner和Jmeter,gatling录制后没有响应内容的保存,若增加断言,还需在网页上检查响应内如。 但对于纯接口的手动脚本编写,则可根据手动测试时响应的内容进行断言。

1、场景运行配置

setUp(
scn.inject(
nothingFor(4 seconds), // 1
atOnceUsers(10), // 2
rampUsers(10) during (5 seconds), // 3
constantUsersPerSec(20) during (15 seconds), // 4
constantUsersPerSec(20) during (15 seconds) randomized, // 5
rampUsersPerSec(10) to 20 during (10 minutes), // 6
rampUsersPerSec(10) to 20 during (10 minutes) randomized, // 7
heavisideUsers(1000) during (20 seconds) // 8
).protocols(httpProtocol)
)

nothingFor(duration):设置一段停止的时间,这段时间什么都不做
atOnceUsers(nbUsers):立即注入一定数量的虚拟用户
rampUsers(nbUsers) during(duration):在指定时间内,设置一定数量逐步注入的虚拟用户
constantUsersPerSec(rate) during(duration):定义一个在每秒钟恒定的并发用户数,持续指定的时间
constantUsersPerSec(rate) during(duration) randomized:定义一个在每秒钟围绕指定并发数随机增减的并发,持续指定时间
rampUsersPerSec(rate1) to (rate2) during(duration):定义一个并发数区间,运行指定时间,并发增长的周期是一个规律的值
rampUsersPerSec(rate1) to(rate2) during(duration) randomized:定义一个并发数区间,运行指定时间,并发增长的周期是一个随机的值
heavisideUsers(nbUsers) during(duration) :按照延伸到给定持续时间的重阶梯函数的平滑近似值,注入给定数量的用户

 

2、事务

object Search {

val feeder = csv("search.csv").random // 1, 2

val search = exec(http("Home")
.get("/"))
.pause(1)
.feed(feeder) // 3
.exec(http("Search")
.get("/computers?f=${searchCriterion}") // 4
.check(css("a:contains(‘${searchComputerName}‘)", "href").saveAs("computerURL"))) // 5
.pause(1)
.exec(http("Select")
.get("${computerURL}")) // 6
.pause(1)
}
Explanations:
1、val feeder = csv("search.csv").random 从csv创建一个feeder,具体内容见csv文件
2、读取顺序为random,可取值为circle/random/
3、调用feeder读取数据
.queue // default behavior: use an Iterator on the underlying sequence
.random // randomly pick an entry in the sequence
.shuffle // shuffle entries, then behave like queue
.circular // go back to the top of the sequence once the end is reached
4、使用feeder的searchCriterion值
5、用CCC座位检查点,判断包含有searchComputerName的a标签(链接),并保存链接为computerURL供后续使用
6、调用上文存储的computerURL进行发送请求

3、场景

object Browse {

def gotoPage(page: Int) = exec(http("Page " + page)
.get("/computers?p=" + page))
.pause(1)

val scn = scenario("LoginSimulation").exec(gotoPage(0), gotoPage(1), gotoPage(2), gotoPage(3), gotoPage(4))

}
提取出单一的exec作为一个功能块,或者叫方法/函数,供执行时多次调用。

 


4、其他小方法

1、提取session

//提取已保存的session
.exec(addCookie(Cookie("session", "${session}")))
// 打印session
.exec { session =>
println("session:" + session)
session
}

2、断言

.check(status.is(200))
.check(jsonPath("$.SessionID").saveAs("session"))

3、feed

feeder读取数据
.queue // default behavior: use an Iterator on the underlying sequence
.random // randomly pick an entry in the sequence
.shuffle // shuffle entries, then behave like queue
.circular // go back to the top of the sequence once the end is reached

csv存储路径:默认读取resource下的csv,若在更深一级,则需指定时写出深一层的路径,如resources/data/user.csv   则定义时需写为

var userList = csv("data/user.csv")

 





Gatling入门简单使用

标签:查点   use   rate   场景   check   pre   脚本   接口   入门   

原文地址:https://www.cnblogs.com/blessboy51/p/13070241.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!