check.saveAs not saving list param.

35 views
Skip to first unread message

Feng Yu

unread,
Jan 20, 2017, 10:24:21 AM1/20/17
to Gatling User Group
Here is my code:

exec(http("/company-sites/:id/details")
                    .get("/company-sites/${sites_id}/details")
                    .check(status.is(200),
                        jsonPath("$.goods[*].id").saveAs("goods_id_list")))
                .pause(5)
                .repeat(10) {
                    exec(http("/company-sites/goods/:id")
                        .get("/company-sites/goods/${goods_id_list.random()}"))
                    .pause(5)
                }

Here is the json which "/company-sites/${sites_id}/details" returns:
{"site":{"id":1,"logo":"http://9rentest.oss-cn-hangzhou.aliyuncs.com/images/company/1/1/logo.png!cs-m","address":"西安市碑林区长安北路14号省体育商城B-10号","name":"天意体育场店","lng":108.948993,"lat":34.240027,"tel":"029-85569182","score":5.0},"brands":["http://9rentest.oss-cn-hangzhou.aliyuncs.com/images/brand/yonex-icon.png!b-s","http://9rentest.oss-cn-hangzhou.aliyuncs.com/images/brand/rsl-icon.png!b-s"],"goods":[{"id":8,"name":"林丹限量款短裤","img":"http://9rentest.oss-cn-hangzhou.aliyuncs.com/images/goods/8/cf9d24a6-ceae-4b39-9559-b91a0c509b9e.png!g-m","sellPrice":180.0,"originPrice":258.0,"brandImg":"http://9rentest.oss-cn-hangzhou.aliyuncs.com/images/brand/yonex-logo.png!b-m"},{"id":4,"name":"女款翻领速排汗短袖","img":"http://9rentest.oss-cn-hangzhou.aliyuncs.com/images/goods/4/fcaf296d-fc71-4ccc-af8d-7a5f6e1f7761.png!g-m","sellPrice":180.0,"originPrice":258.0,"brandImg":"http://9rentest.oss-cn-hangzhou.aliyuncs.com/images/brand/yonex-logo.png!b-m"},{"id":7,"name":"林丹限量款短袖","img":"http://9rentest.oss-cn-hangzhou.aliyuncs.com/images/goods/7/1d9e7605-23b8-40db-a3ef-a2513512504f.png!g-m","sellPrice":187.0,"originPrice":268.0,"brandImg":"http://9rentest.oss-cn-hangzhou.aliyuncs.com/images/brand/yonex-logo.png!b-m"},{"id":3,"name":"男款翻领速排汗短袖","img":"http://9rentest.oss-cn-hangzhou.aliyuncs.com/images/goods/3/6625e732-804a-40f7-9dce-3cc1873f67d1.png!g-m","sellPrice":187.0,"originPrice":268.0,"brandImg":"http://9rentest.oss-cn-hangzhou.aliyuncs.com/images/brand/yonex-logo.png!b-m"},{"id":6,"name":"李宗伟奥运限量款短裤","img":"http://9rentest.oss-cn-hangzhou.aliyuncs.com/images/goods/6/081d0fb9-2664-4203-8277-42cddd5431f5.png!g-m","sellPrice":208.0,"originPrice":298.0,"brandImg":"http://9rentest.oss-cn-hangzhou.aliyuncs.com/images/brand/yonex-logo.png!b-m"},{"id":9,"name":"男款圆领速排汗短袖","img":"http://9rentest.oss-cn-hangzhou.aliyuncs.com/images/goods/9/e3ace65e-508d-4a98-9225-bc61b0d4cca1.png!g-m","sellPrice":222.0,"originPrice":318.0,"brandImg":"http://9rentest.oss-cn-hangzhou.aliyuncs.com/images/brand/yonex-logo.png!b-m"}]}

I've try the jsonPath parser at https://jsonpath.curiousconcept.com/ with my expressison:
$.goods[*].id

And it works:
 
  8,
  4,
  7,
  3,
  6,
  9
]

But "${goods_id_list.random()}" in my codes return an error:
23:11:14.911 [ERROR] i.g.h.a.s.HttpRequestAction - 'httpRequest-19' failed to execute: 8 named 'goods_id_list' does not support .random function


I try to replace ${goods_id_list.random()} with ${goods_id_list}, the value only contains the first element "8", not a list value.

Why? Am I missing something?

Feng Yu

unread,
Jan 20, 2017, 10:31:42 AM1/20/17
to Gatling User Group
I'm using the latest version 2.2.3.

在 2017年1月20日星期五 UTC+8下午11:24:21,Feng Yu写道:

Vu Nguyen

unread,
Jan 20, 2017, 4:01:34 PM1/20/17
to Gatling User Group

You need to *explicitly* tell check to capture all matches into a list using "findAll":
http://gatling.io/docs/2.2.3/http/http_check.html#extracting

Feng Yu

unread,
Jan 20, 2017, 10:36:17 PM1/20/17
to Gatling User Group
Great, it works.
.get("/company-sites/${sites_id_list.random()}/details")
    .check(status.is(200),
        jsonPath("$.goods[*].id").findAll.saveAs("goods_id_list")))



在 2017年1月21日星期六 UTC+8上午5:01:34,Vu Nguyen写道:
Reply all
Reply to author
Forward
0 new messages