【问题标题】:Jmeter - Fetch the Session ID from the Response and pass it next request.Request & Responses are in JSONJmeter - 从响应中获取会话 ID 并将其传递给下一个请求。请求和响应在 JSON 中
【发布时间】:2014-03-05 10:04:18
【问题描述】:

场景:- 我使用 API 执行负载测试

HTTP 请求 1

我使用http://cabhound.com:1000/v2/driver/login 登录并收到以下回复

{"statusCode":200,"statusMessage":"Success","errorMessage":"","responseData":{"id":0,"userName":"PQeurentraps5S@tarento.com","firstName":"Partner","lastName":"Tarento","phoneNumber":"2641148625","email":"tamvrentrapnsr@tarento.com","password":"","addressOne":"","addressTwo":"","city":"","state":"","zipCode":"","loginCount":156,"welcome":"","smsOptIn":false,"promoCode":"","userNotification":"","errorMessage":"","message":"","sessionId":"6063tnerLt3013951671120oDse18492930#2","osType":"","osVersion":"","deviceType":"","deviceId":"","latitude":"","longitude":"","timeZone":"","appVersion":"","company":"Tarento","licenceNumber":"","vehicleType":"","vehicleFeature":null,"subscriptionType":"unlimited","driverWorkingCity":"Bangalore","vehicleNumber":"","locationUpdateTime":20,"rate":0,"reliable":0,"distance":0.0,"eta":0,"latitudeLongitude":"","status":"ON","payment":{"paymentType":"","cardNumber":"","cvnNumber":"","expDate":""},"vehicleTypeList":["Sedan","Limousine","SUV/Wagon","Minivan","Other"],"vehicleFeatureList":["Navigation System","Eco Friendly","Handicap accessible","Accepts credit cards"],"driverId":582,"currentLocation":null,"companyCode":"tarento","acceptanceRate":0,"like":0,"profileIndicator":0,"payWithCabHound":false,"smsSupport":false,"paymentInfo":false,"geoInfo":"","active":true}}

请查看上面响应中的会话 id,我想在下一个 http 请求数据中使用它

HTTP 请求 2

http://cabhound.com:1000/v2/driver/dutyStatus

下面是我需要发布的数据,这里我想使用 HTTP Request 1 的 session id

{"status":"ON","sessionId":"1311tnerLt9013956793297oDse462783#2","longitude":"77.686700","userName":"erpkrentrapJps@tarento.com","latitude":"12.934487"}

如何将 HTTP Request 1(响应)的 session id 传递给 HTTP Request 2 Post Data

帮助我解决我遇到的问题

【问题讨论】:

    标签: json automation jmeter performance-testing jmeter-plugins


    【解决方案1】:

    我建议使用JMeter Plugin 提供的JSON Path Extractor(您需要带有Libs Set 的Extras。

    正则表达式的开发令人头疼,尤其是对于可以是多行的 JSON 数据。 Beanshell 有已知的性能问题,因此使用插件是最好的选择。

    您的 sessionId 的相关 JSON 路径查询将如下所示:

    $.responseData.sessionId
    

    请参阅使用XPath Extractor in JMeter 指南的Parsing JSON 部分了解更多详细信息和XPath 到JSON 路径映射

    【讨论】:

    • 使用 JSON 路径提取器我已经提取了 sessionId 并存储在 SessionCH 中。现在我必须将它传递给下一个 Http 请求 - 我试图像这样传递 {"status":"ON",${ SessionCH},"longitude":"77.686700","userName":"erpkrentrapJps@tarento.com","latitude":"12.934487"} 但它抛出了错误
    【解决方案2】:

    我可以看到上述问题的 2 个解决方案,

    1. 使用正则表达式提取器提取值(我没有将它与 json 响应一起使用,但我认为它会起作用)
    2. 使用 Beanshell 预处理器或后处理器,您可以在其中获取响应并使用 substr 或 json 解析器或使用简单的 java 代码找到所需的 sessionID。提取所需的值并在下一个请求中使用它。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-18
    • 1970-01-01
    • 2020-07-31
    相关资源
    最近更新 更多