Search code examples
rest-assured

"OR" condition for headers in Rest-assured?


My API returns an status header that can be "pending", "done".

For status = "done" it also add two additional header.

I would like to make a (Rest-assured) test that success if either status header is "pending" and the two additional headers are empty OR if the status header is "done" and the two additional headers are present.

I find no way to do that. Looks "OR" conditions are not possible ?

Note: There is no way to force the "pending" or "done" status since it depends on external timeouts.


Solution

  • You can solve this by using Response class to extract header value and validate it. Like this (adjust please):

    Response response = given().when().get("yourapiurl.com/something");
    string header = response.getHeader("statusHeaderName");
    
    Assert.assertTrue(header.equals("pending") || header.equals("done"));