我试图关联或创建一个" Check"在加特林加载工具,但不知道如何做到这一点。我浏览了Gatling官方网站上的高级教程文档,但对于动态值的相关性并没有多大帮助。
以下是我的脚本中的代码
.feed(feeder)
.exec(http("EnterDetails")
.post("/events/review.action")
.headers(headers_6)
.formParam("userInfo.spgEmail", "")
.formParam("userInfo.title", "")
.formParam("userInfo.firstName", "${FirstName}")
.formParam("userInfo.lastName", "${LastName}")
.formParam("userInfo.address1", "Open")
.formParam("userInfo.address2", "")
.formParam("userInfo.city", "${City}")
.formParam("userInfo.state", "NYY")
.formParam("userInfo.country", "US")
.formParam("userInfo.zipCode", "10016")
.formParam("userInfo.primaryNoInfo.optedIn", "false")
.formParam("userInfo.phoneTwoInfo.optedIn", "false")
.formParam("userInfo.phoneThreeInfo.optedIn", "false")
.formParam("userInfo.primaryNoInfo.validInd", "Y")
.formParam("userInfo.phoneTwoInfo.validInd", "")
.formParam("userInfo.phoneThreeInfo.validInd", "")
.formParam("userInfo.phoneUseType1", "0")
.formParam("userInfo.primaryNoInfo.phoneNumber", "9876543211")
.formParam("userInfo.primaryNoInfo.extension", "")
.formParam("userInfo.country1", "US%28%2B1%29")
.formParam("__checkbox_userInfo.primaryNoInfo.oneTimeOptInPresent", "true")
.formParam("userInfo.phoneUseType2", "-1")
.formParam("userInfo.phoneTwoInfo.phoneNumber", "")
.formParam("userInfo.phoneTwoInfo.extension", "")
.formParam("userInfo.country2", "US%28%2B1%29")
.formParam("__checkbox_userInfo.phoneTwoInfo.oneTimeOptInPresent", "true")
.formParam("userInfo.phoneUseType3", "-1")
.formParam("userInfo.phoneThreeInfo.phoneNumber", "")
.formParam("userInfo.phoneThreeInfo.extension", "")
.formParam("userInfo.country3", "US%28%2B1%29")
.formParam("__checkbox_userInfo.phoneThreeInfo.oneTimeOptInPresent", "true")
.formParam("userInfo.email", "")
.formParam("userInfo.retypeEmail", "")
.formParam("userInfo.nonCCPayment", "true")
.formParam("userInfo.SPGNumber", "")
.formParam("userInfo.arrivalCarrier", "")
.formParam("userInfo.transportationNumber", "")
.formParam("userInfo.transportationArrTime", "")
.formParam("userInfo.hotelArrivalTime", "")
.formParam("userInfo.hotelDepartureTime", "")
.formParam("userInfo.SRequest", "")
.formParam("userInfo.IAgree", "true")
.formParam("__checkbox_userInfo.IAgree", "true")
.formParam("method%3Aexecute", "Review+Your+Reservation+"))
.pause(2)
.exec(http("ReviewREservation")
.get(uri3 + "/s01000706679492?AQB=1&ndh=1&pf=1&t=21%2F3%2F2016%2012%3A45%3A54%204%200&D=D%3D&fid=31A8BC73D5B8ACEB-2B64CD0ACE185774&ce=UTF-8&pageName=Review%20Reservation&g=https%3A%2F%2Fstg.starwoodmeeting.com%2Fevents%2Freview.action&r=https%3A%2F%2Fstg.starwoodmeeting.com%2Fevents%2Fselectcreate%21execute.action%3FselRoom%3D1&cc=USD&ch=StarGroups&server=StarGroups&c2=SOCIAL&c3=1603295001&c4=271&c5=SI&c6=YES&c8=en&s=1600x838&c=24&j=1.6&v=N&k=Y&bw=1042&bh=733&AQE=1")
.headers(headers_3))
.pause(7)
.exec(http("request_13")
.post("/events/confirm.action")
.headers(headers_6)
.formParam("method%3Aexecute", "Complete+Your+Reservation"))
.pause(4)
.exec(http("CompleteReservation")
.get(uri3 + "/s03623649917832?AQB=1&ndh=1&pf=1&t=21%2F3%2F2016%2012%3A46%3A5%204%200&D=D%3D&fid=31A8BC73D5B8ACEB-2B64CD0ACE185774&ce=UTF-8&pageName=Reservation%20Confirmation&g=https%3A%2F%2Fstg.starwoodmeeting.com%2Fevents%2Fconfirm.action&r=https%3A%2F%2Fstg.starwoodmeeting.com%2Fevents%2Freview.action&cc=CAD&purchaseID=20160421_734091125&ch=StarGroups&server=StarGroups&events=purchase&products=%3B271%3B1%3B100.00&c2=SOCIAL&c3=1603295001&c4=271&v4=20160421_734091125&c5=SI&c6=YES&c8=en&s=1600x838&c=24&j=1.6&v=N&k=Y&bw=1042&bh=733&AQE=1")
.headers(headers_3))
setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol)
在上面的代码中,我在
中有一个动态购买ID.exec(HTTP(" CompleteReservation&#34) 从服务器生成并需要关联。
从Gatling文档中,我理解(纠正我,如果我错了)我们需要inspect元素代码来获取CSS路径。(如图所示)。 Inspect Element
请告诉我们如何关联.TIA。
答案 0 :(得分:1)
在Gatling中,你必须使用检查来从响应中提取值。看看documentation。
您可以选择使用regex
或xpath
来提取标记中的值。但在您的情况下,我建议您使用简单的regex
,因为您的示例回复中的IMO没有可以轻松与xpath
挂钩的标记或ID。我的意思是xpath
表达式仍然保持简单易懂的方式。接下来就是将值提取到会话中,然后再使用它。
以下示例场景是从example.com
收到的响应中提取URI的查询路径,然后在控制台中打印:
val scn = scenario("Checks")
.exec(
http("root")
.get("/")
.check(
// Extracting URI query path from response body via regexp and storing into session
regex("""www\.iana\.org/([a-z/]*)""").find.saveAs("queryPath")
)
)
// Printing the value from session
// Important thing to note is how you can access stored value from session
.exec { session =>
println(" QUERY PATH --> " + session("queryPath").as[String])
session
}
在你的情况下,你的最后一部分看起来像这样:
.exec(http("CompleteReservation")
.get(uri3 + "/s03623649917832?AQB=1&ndh=1&pf=1&t=21%2F3%2F2016%2012%3A46%3A5%204%200&D=D%3D&fid=31A8BC73D5B8ACEB-2B64CD0ACE185774&ce=UTF-8&pageName=Reservation%20Confirmation&g=https%3A%2F%2Fstg.starwoodmeeting.com%2Fevents%2Fconfirm.action&r=https%3A%2F%2Fstg.starwoodmeeting.com%2Fevents%2Freview.action&cc=CAD&purchaseID=20160421_734091125&ch=StarGroups&server=StarGroups&events=purchase&products=%3B271%3B1%3B100.00&c2=SOCIAL&c3=1603295001&c4=271&v4=20160421_734091125&c5=SI&c6=YES&c8=en&s=1600x838&c=24&j=1.6&v=N&k=Y&bw=1042&bh=733&AQE=1")
.headers(headers_3))
.check(
regex("""Your confirmation number is (\d+)""") // Regular expression with group which represents confirmation number.
.find
.saveAs("confirmationNumber") // Now the extracted regexp group is stored in session under "confirmationNumber" as name.
)
// Missing, check, transformation or use of value from session
我不知道您对提取值的使用情况,因此它在上面的代码段中缺失了。但我希望您已经知道如何处理响应以及如何使用接下来提取的值。
我希望它有所帮助。