1

When I click something on a web page I get a response from the server, but how can I catch and validate that response?

For example if I click the 'Flag' option in my webpage I get the following JSON response, but how can I validate it?

I tried this but it's not showing the full response message:

System.out.println(htmlPage.getWebResponse().toString());

enter image description here

Andrew Regan
  • 4,887
  • 6
  • 35
  • 67
raj kumar
  • 27
  • 2
  • 9

2 Answers2

0

you can use rest-assure library to check the server return response.Currently i use rest-assured library to do this. here is a link from where u will get help.

How to get HTTP Response Code using Selenium WebDriver with Java?

Community
  • 1
  • 1
noor
  • 2,746
  • 2
  • 14
  • 26
0

The problem with using REST tools is that they will only return the response for a new, non-interactive request, i.e. outside the interactive Selenium flow. This won't give you access to the response for a click that Selenium has already initiated, which is most likely what you want.

If what you want to do is automatically capture the actual responses for all of the clicks you ask Selenium to do, e.g. upon the Flag, then @noor's link has a higher-rated answer that recommends using a proxy server to capture all requests and responses in a queriable form:

https://stackoverflow.com/a/19091306/954442

https://github.com/lightbody/browsermob-proxy#using-with-selenium

Using that technique, you will be able to query the complete response for the request you want, and you'll have access to all parameters, headers, response codes etc.

Community
  • 1
  • 1
Andrew Regan
  • 4,887
  • 6
  • 35
  • 67