2016-04-22 24 views
1

我想在Gatling加载工具中关联或创建一个“检查”,但不知道如何去做。我通过官方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) 

的peice的在上面的代码我在

.exec动态购买ID(HTTP( “CompleteReservation”) ,其获取生成从服务器和需要相关。

从加特林文档,我明白(纠正我,如果我错了),我们需要检查元素代码来获取CSS路径。(显示H ERE)。 Inspect Element

请让我知道我们如何关联.TIA。

+0

任何答案请:( –

+0

首先你的链接“检查元素”是错误的。下一步,请说明什么是“需要相关”..你的意思是它需要从响应中读取?那么,响应是怎么样的?基本上指定你想要做什么 – Teliatko

+0

好的,简单来说,我们如何关联Gatling中的动态值。例如: - 在Load runner中,我们将LB和RB从反应和相关,但在加特林,我们在哪里看到的反应,我们如何关联的动态值。 –

回答

1

在加特林你必须使用检查从响应中提取一个值。看看documentation

您可以选择使用regexxpath来提取标记中的值。但在你的情况下,我建议使用简单的regex,因为IMO在你的示例响应中没有标签或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 

我不知道你的提取值的用法,因此它在上面的代码片段中缺少。但是我希望你已经知道如何处理响应以及下一步如何使用提取的值。

我希望它有帮助。