Search code examples
gatlingscala-gatling

Unable to add multiple parameters in If condition using gatling


From a feeder file i am taking values called product id, product type and weight. I am using these products to add items to basket, Based on product type add to basket request gets changes. I added if condition as below to check whether product have weight and type of the product, but it is giving compilation issues, can someone please help me in resolving this issue?

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\"}"
           
            }

Compilation error -

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") {


Solution

  • DO this:

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

    You need to enclose whole condition in () parenthesis. Like if ( A && B) where A in your case is (v_c_maxWeightValue > 0) and B is (p_ProductType == "CatchWeight").

    Same goes for other else if statements. Enclose them in one main paranthesis.