Scala Gatling中动态值的相关性
我试图在Gatling加载工具中关联或创建一个“检查”,但不确定如何做。我查阅了加特林官方网站上的高级教程文档,但并没有找到多少关于动态值相关性的信息 下面是我脚本中的代码清单Scala Gatling中动态值的相关性,scala,performance-testing,correlation,gatling,Scala,Performance Testing,Correlation,Gatling,我试图在Gatling加载工具中关联或创建一个“检查”,但不确定如何做。我查阅了加特林官方网站上的高级教程文档,但并没有找到多少关于动态值相关性的信息 下面是我脚本中的代码清单 .feed(feeder) .exec(http("EnterDetails") .post("/events/review.action") .headers(headers_6) .formParam("userInfo.spgEmail", "")
.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)
在上面的代码中,我在
.exec(http(“CompleteReservation”)
从服务器生成并需要关联的
从Gatling文档中,我理解(如果我错了,请纠正我)我们需要inspect元素代码来获取CSS路径(如图所示)。
请让我知道我们如何关联.TIA。在Gatling中,您必须使用检查从响应中提取值。请查看 您可以选择使用
regex
或xpath
来提取标记中的值。但在您的情况下,我建议使用简单的regex
,因为在您的示例响应中,没有标记或ID可以轻松地与xpath
挂钩。我的意思是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
我不知道您对提取值的用法,因此上面的代码段中缺少了提取值。但我希望您已经知道如何处理响应以及接下来如何使用提取值
我希望这会有所帮助。请回答:(首先,您的链接“Inspect Element”是错误的。接下来,请指定“需要关联”的含义…你的意思是需要从响应中读取它吗?如果是,响应是什么样子的?基本上指定你想对它做什么。好的,简单来说,我们如何关联Gatling中的动态值。例如:-在Load runner中,我们从响应中获取LB和RB并关联它,但在Gatling中,我们在哪里看到响应以及如何关联关联动态值。