2016-04-22 22 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 

我不知道你的提取值的用法,因此它在上面的代碼片段中缺少。但是我希望你已經知道如何處理響應以及下一步如何使用提取的值。

我希望它有幫助。