serenity-bdd / serenity-core

Serenity BDD is a test automation library designed to make writing automated acceptance tests easier, and more fun.
http://serenity-bdd.info
Other
718 stars 516 forks source link

Serenity Restassured test doesn't fail even when response status code is not the expected one #3373

Open johnysv opened 8 months ago

johnysv commented 8 months ago

What happened?

I have a simple reatassured code which is below. Here it has to fail when response is not 200 as I have used then().Statuscode(200) in checkstatuscode function. But the test passed.

What did you expect to happen?

No response

Serenity BDD version

4.0.15

JDK version

21

Execution environment

Windows,Chrome

How to reproduce the bug.

I have a simple reatassured code which is below. Here it has to fail when response is not 200 as I have used then().Statuscode(200) in checkstatuscode function. But the test passed. Below is the screen shot too.

5.3.2 4.0.15 jdk version - 21 io.rest-assured-5.3.2 **@Step("When I upload Loss Distribution file {0} for the Cons Unit {1}") public void uploadLossDistribution(final String file, final String consUnit,Object... PathParam){ given().contentType("multipart/form-data") .multiPart("file", new File(file)) .multiPart("id",consUnit) .pathParams("latest-hierarchy-rev-information", latestHierarchyRevision.getVersionHierarchy()) .when().post(resourceUrl,PathParam); checkStatusCode(200);** **@Step("Then I expect to see {0} as status code") public void checkStatusCode(final int statusCode) { then().statusCode(statusCode); }** ![image](https://github.com/serenity-bdd/serenity-core/assets/41629868/dabb44cc-3db7-4fcd-9726-0cc1a265a61d) Note: **The same test fails** when I use then().Statuscode(200) as a continuation of post() like below.Not sure why it doesnt fail if I write it as a new method.Please help me to resolve this @Step("When I upload Loss Distribution file {0} for the Cons Unit {1}") public void uploadLossDistribution(final String file, final String consUnit,Object... PathParam){ given().contentType("multipart/form-data") .multiPart("file", new File(file)) .multiPart("id",consUnit) .pathParams("latest-hierarchy-rev-information", latestHierarchyRevision.getVersionHierarchy()) .when().post(resourceUrl,PathParam).**then().statusCode(200);** ![image](https://github.com/serenity-bdd/serenity-core/assets/41629868/6e7bd379-b67a-4142-be58-ce338904ccfb) ### How can we make it happen? Work on this myself and propose a PR (with Serenity BDD team guidance)
johnysv commented 8 months ago

@wakaleo Could you please help here