标签:
高级教程
1 package computerdatabase 2 import io.gatling.core.Predef._ 3 import io.gatling.http.Predef._ 4 import scala.concurrent.duration._ 5 classBasicSimulationextendsSimulation{ 6 val httpConf = http 7 .baseURL("http://computer-database.gatling.io") 8 .acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8") 9 .doNotTrackHeader("1") 10 .acceptLanguageHeader("en-US,en;q=0.5") 11 .acceptEncodingHeader("gzip, deflate") 12 .userAgentHeader("Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0") 13 val scn = scenario("BasicSimulation") 14 .exec(http("request_1") 15 .get("/")) 16 .pause(5) 17 setUp( 18 scn.inject(atOnceUsers(1)) 19 ).protocols(httpConf) 20 }
1 object Search{ 2 val search = exec(http("Home")// let‘s give proper names, as they are displayed in the reports 3 .get("/")) 4 .pause(7) 5 .exec(http("Search") 6 .get("/computers?f=macbook")) 7 .pause(2) 8 .exec(http("Select") 9 .get("/computers/6")) 10 .pause(3) 11 } 12 object Browse{ 13 val browse =??? 14 } 15 object Edit{ 16 val edit =??? 17 }
1 val users = scenario("Users").exec(Search.search,Browse.browse) 2 val admins = scenario("Admins").exec(Search.search,Browse.browse,Edit.edit)
1 setUp(users.inject(atOnceUsers(10)).protocols(httpConf))
1 setUp( 2 users.inject(rampUsers(10) over (10 seconds)), 3 admins.inject(rampUsers(2) over (10 seconds)) 4 ).protocols(httpConf)
1 setUp( 2 users.inject(rampUsers(10) over (10 seconds)), 3 admins.inject(rampUsers(2) over (10 seconds)) 4 ).protocols(httpConf)
1 object Search{ 2 val feeder = csv("search.csv").random // 1, 2 3 val search = exec(http("Home") 4 .get("/")) 5 .pause(1) 6 .feed(feeder)// 3 7 .exec(http("Search") 8 .get("/computers?f=${searchCriterion}")// 4 9 .check(css("a:contains(‘${searchComputerName}‘)","href").saveAs("computerURL")))// 5 10 .pause(1) 11 .exec(http("Select") 12 .get("${computerURL}"))// 6 13 .pause(1) 14 }
1 object Browse{ 2 def gotoPage(page:Int)= exec(http("Page "+ page) 3 .get("/computers?p="+ page)) 4 .pause(1) 5 val browse = exec(gotoPage(0), gotoPage(1), gotoPage(2), gotoPage(3), gotoPage(4)) 6 }
1 object Browse{ 2 val browse = repeat(5,"n"){// 1 3 exec(http("Page ${n}") 4 .get("/computers?p=${n}"))// 2 5 .pause(1) 6 } 7 }
1 import java.util.concurrent.ThreadLocalRandom// 1 2 val edit = exec(http("Form") 3 .get("/computers/new")) 4 .pause(1) 5 .exec(http("Post") 6 .post("/computers") 7 .check(status.is(session =>200+ThreadLocalRandom.current.nextInt(2))))// 2
1 val tryMaxEdit = tryMax(2){// 1 2 exec(edit) 3 }.exitHereIfFailed // 2
Gatling官网教程翻译之Advanced Tutorial
标签:
原文地址:http://www.cnblogs.com/dongmu1986/p/5127792.html