Jmeter - 从响应中获取会话ID并将其传递给下一个request.Request&回复是JSON

时间:2014-03-05 10:04:19

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

情景: - 我正在使用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的会话ID

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

如何将HTTP请求1(响应)的会话ID传递给HTTP请求2发布数据

帮助我解决这个问题

2 个答案:

答案 0 :(得分:1)

我建议使用JSON Path Extractor提供的JMeter Plugin(你需要附加Libs Set的附加功能。

正则表达式很难开发,特别是对于可以多线的JSON数据。 Beanshell已知性能问题,因此使用插件是最佳选择。

您的sessionId的相关JSON路径查询将显示为:

$.responseData.sessionId

有关详细信息和XPath到JSON路径映射,请参阅使用XPath Extractor in JMeter指南的Parsing JSON部分

答案 1 :(得分:0)

我可以看到针对上述问题的两种解决方案,

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