无法使用加特林在 If 条件中添加多个参数

Unable to add multiple parameters in If condition using gatling

我从供给文件中获取称为产品 ID、产品类型和重量的值。 我正在使用这些产品将商品添加到购物车,根据添加到购物车的产品类型请求进行更改。 我在下面添加了 if 条件来检查产品是否有重量和产品类型,但它给出了编译问题,有人可以帮我解决这个问题吗?

if(v_c_maxWeightValue > 0) && (p_ProductType == "CatchWeight") {
                   var requestBodyAddToBasket="{\"items\":[{\"id\":\""+v_c_ProductId+"\",\"newValue\":"+v_newValue+",\"oldValue\":"+v_oldValue+",\"newUnitChoice\":\"pcs\",\"oldUnitChoice\":\"pcs\",\"catchWeight\":"+v_c_maxWeightValue+"}],\"loggedInAction\":\"update-trolley-item\"}"
       

                }else if (v_c_maxWeightValue > 0) && (p_ProductType == "LooseQuantity") {
                   var requestBodyAddToBasket="{\"items\":[{\"id\":\""+v_c_ProductId+"\",\"newValue\":"+v_newValue+",\"oldValue\":"+v_oldValue+",\"newUnitChoice\":\"kg\",\"oldUnitChoice\":\"kg\"}],\"loggedInAction\":\"update-trolley-item\"}"          

                } 
                else{
                   var requestBodyAddToBasket="{\"items\":[{\"id\":\""+v_c_ProductId+"\",\"newValue\":"+v_newValue+",\"oldValue\":"+v_oldValue+",\"newUnitChoice\":\"pcs\",\"oldUnitChoice\":\"pcs\"}],\"loggedInAction\":\"update-trolley-item\"}"
           
            }

编译错误-

11:30:42.634 [ERROR] i.g.c.ZincCompiler$ - /home/ec2-user/gatling/user-files/simulations/addToBasket.scala:94:31: not found: value &&
            if(v_c_maxWeightValue > 0) && (p_ProductType == "CatchWeight") {
                                       ^
11:30:42.637 [ERROR] i.g.c.ZincCompiler$ - /home/ec2-user/gatling/user-files/simulations/addToBasket.scala:94:35: not found: value p_ProductType
            if(v_c_maxWeightValue > 0) && (p_ProductType == "CatchWeight") {
                                           ^
11:30:42.639 [ERROR] i.g.c.ZincCompiler$ - /home/ec2-user/gatling/user-files/simulations/addToBasket.scala:99:39: not found: value &&
                }else if (v_c_maxWeightValue > 0) && (p_ProductType == "LooseQuantity") {
                                                  ^
11:30:42.642 [ERROR] i.g.c.ZincCompiler$ - /home/ec2-user/gatling/user-files/simulations/addToBasket.scala:99:43: not found: value p_ProductType
                }else if (v_c_maxWeightValue > 0) && (p_ProductType == "LooseQuantity") {

这样做:

if((v_c_maxWeightValue > 0) && (p_ProductType == "CatchWeight")) {

您需要将整个条件括在 () 括号中。像 if ( A && B) 一样 A 在你的情况下是 (v_c_maxWeightValue > 0)B(p_ProductType == "CatchWeight").

其他 else if 语句也是如此。将它们放在一个主要括号中。