1

When I run the POST call through Rest assured framework(Cucumber Examples keyword), first dataset requests run fine but with the second dataset, both first dataset and second dataset values are getting merged. How can this be rectified?

Featurefile:

Given profile details with "name" and "profiletype"

Examples: | name | profiletype |

  | Davian | ADULT        |
  | Kavian | ADULT        |

Stepdefinition:

public void profile_details_with_and(String name, String profiletype) throws IOException {

    config.setProperty("Base.properties");
    testservice.setBaseURI();
    testservice.addQueryParam("at", config.getConfig().getProperty("at"));
    testservice.addHeaderCookie("COOKIE",config.getConfig().getProperty("COOKIE"));
    testservice.callRequestSpec();
    testservice.formParam("profilePic","default");
    testservice.formParam("locale","en");
    testservice.formParam("name",name);
    testservice.formParam("profileType",profiletype);
}

public void formParam(String key, String value) throws IOException{

    requestSpec = given().spec(setBaseURI()).contentType(ContentType.URLENC.withCharset("UTF-8")).formParam(key, value);
}

Logs Output:

Form params:

profilePic=[default, default]

locale=[en, en]

name=[Davian, Kavian]

profileType=[ADULT, ADULT]
lucas-nguyen-17
  • 5,516
  • 2
  • 9
  • 20
Wilson
  • 73
  • 8
  • @lucas-nguyen-17 Am I missing something. – Wilson Apr 06 '22 at 20:48
  • I think there are some similar issues in SO related to re-using RequestSpecification instance. E.g https://stackoverflow.com/questions/69567028/how-to-reset-multipart-content-type-in-a-chain-of-rest-assured-apis/69569031#69569031 My recommendation is DO NOT re-use the `RequestSpecification` – lucas-nguyen-17 Apr 07 '22 at 03:21
  • @lucas-nguyen-17 - Thanks for your quick comment. I am using the above formParam function from the framework Utility. I have lot of requests which are having formParam. Samething is happening for queryParam and the headers if I use the function from framework Utility with requestSpec. The queryParams of the first request is getting clubbed in the second request. – Wilson Apr 07 '22 at 03:44
  • could you send me sample project in github? I'd like to take a look and find out any solutions that solve the problem – lucas-nguyen-17 Apr 07 '22 at 06:32
  • @lucas-nguyen-17 Sure will try it out – Wilson Apr 07 '22 at 14:12

1 Answers1

1

Write a seperate scenario for each example. Then you can isolate the issue. In general keep you scenarios simple even if it means a bit of repition. You don't need to use example groups or scenario outlines to cuke effectively.

diabolist
  • 3,990
  • 1
  • 11
  • 15