What's your preferred way of getting network responses with Selenium? (sorry)

So I’ve mostly used Cypress in the past, which has a (limited) ability to spy on network requests happening in the browser. I haven’t done much with Selenium / WebDriver until the last few months, and it doesn’t seem to be a thing. Which I can understand - it should be used for checking what the user sees and interacts with on the page, and we can use something else for checking functional stuffs against the API.
Buuuuuut we have a particular case where we would like to check the response as well as what happens on the page. What would you suggest for watching network requests in Selenium tests, and allowing us to check statuses and response body stuff? I’ve seen some people online mentioning a proxy called browsermob, but it looks like it hasn’t been updated in a few years. Watchu all using, if anything?

At the moment I do not have a working solution.

I have the following strange suggestion: Selenium 4.
According to https://www.selenium.dev/documentation/en/support_packages/chrome_devtools Selenium 4 will support Chrome Devtools including network.

The Alpha version is available. The download link is contained in https://applitools.com/blog/selenium-4-migration

1 Like

Hey @undevelopedbruce, this is far removed from my area but is this something Charles could help with? Might be worth asking @suman.bala or @sumanbala (sorry not sure which one is her. Or she is @ sumanbala867 on Twitter

1 Like

I don’t think Selenium/Webdriver alone is able to do it. In the machine where you run your tests (and the ci/cd agents) can you install new software?

If yes, then I’d try to google for other tools such as:

If no, then other ideas:

  • call the API request yourself (outside the browser, using things like RestAssured for Java or Requests for Python) and then compare that output with the Browser UI (remember to copy cookies or any other authentication headers from the browser before firing your request)
  • smart-manage your test data so you know what to expect (very context-dependent, but maybe you can create a type of user in your system that always returns what you want, like idk, a user that always return odd numbers in your API request, and use that knowledge/assumption as part of the Browser test)

I can give you a hand with Charles Proxy to intercept calls. You can also use WireMock to test stub and APIs and mock stuff so you know what you expected :slight_smile:

Webdriver has a devtools service you can tap into for useful metrics. See this link for more info:

1 Like