How to grab Network data from DevTools using BrowserLibray

Hey everyone,

I’m trying to set up my tests so that they get logs from the Console and Network tabs in DevTools and save them in the log file after execution, when they are failed. I used “Get Console Log” in order to grab Console logs, and it works perfect! Could you help me with grabbing Network data from DevTools, please, can I do it using BrowserLibrary right now?

Hi! Did you manage to find a solution? :slight_smile:

https://marketsquare.github.io/robotframework-browser/Browser.html#New%20Context

there’s option called recordHar. Its not exactly the same has getting the browser network log but it should contain all the information regarding what sort of requests where done while the context was open.

2 Likes

Thank you! I’m able to get the Network Data. However, I also want to parse it during runtime is there a way to do it? I observed that we could only get the updated har after the context is close.

However, I also want to parse it during runtime is there a way to do it?

Thats the reason why i mentioned “its not exactly the same” as there’s the requirement to close the context before the har is available.

In playwright itself, Request | Playwright api does provide a way to catch both requests and responses that could be used. However, there is no “clean way” to integrate those in rf side … Not impossible to a bit cumbersome and would definitely need someone who knows how to write javascript.

My initial approach would be to add javascript code as jsextension (see importing section in the keyword docs) that adds 1 keyword for monitoring request and response events and when those happens, store the objects as json either into memory within the extension itself or to json file. And then another keyword that that returns the data to robot framework side. If you would store the req and resp objects into a file, obviously the second keyword wouldn’t need to be written in the same jsextension file and/or in javascript…

As a side note - ping @aaltat. Would it be big effort to get request callbacks back to RF side ? My guess would be, it would :wink:

2 Likes

Thank you so much, I will try this :slight_smile:

As I read the Browser documentation, I found out that the library already supported request and response events through Wait for Response and Wait for Request. :slight_smile: