Forum Discussion

lzc's avatar
lzc
Occasional Contributor
9 years ago
Solved

assertion for raw response 200 OK

I am trying to create an assertion for the raw response to verify the 200 OK

 

HTTP/1.1 200 OK

 

it would seem simple enough but i can't get any kind of contains assertion to pass.

 

can't use the nodes because that doesn't show up when creating an assertion.

 

how do i create an assertion for contains 200 OK in the raw response tab which passes?

 

thanks Lee

  • Hi Izc,

     

    you probably have some reason to check the raw response, but I still want to mention the "Valid HTTP Status Codes" assertion that can be used to check response codes.

     

    Regards,

    Anders

    Ready! API developer

4 Replies

  • Hi Izc,

     

    you probably have some reason to check the raw response, but I still want to mention the "Valid HTTP Status Codes" assertion that can be used to check response codes.

     

    Regards,

    Anders

    Ready! API developer

    • nmrao's avatar
      nmrao
      Champion Level 3

      Anders,

       

      Thanks for the simply excellent answer :smileyhappy:, I probably complicated it.

      • lzc's avatar
        lzc
        Occasional Contributor

        Hi ,

         

        yes!, thank you for both the answers!, i was having trouble with the valid http codes assertion, it was grayed out for some reason when i was looking at it previously. now it is there. i also want to use the script assertion method as well. thanks for 2 ways to accomplish this.

         

        Lee

  • nmrao's avatar
    nmrao
    Champion Level 3

    You may use the script assertion with the following code

     

    def expectedHTTPResponse = ['HTTP/1.1 200 OK']
    def headers = messageExchange.response.responseHeaders
    def actualHTTPResponse = headers['#status#']
    assert expectedHTTPResponse == actualHTTPResponse, "HTTP Response code does not match"