Is there a way to save HAR file from browserMobProxy from a custom reporter class?

19 views
Skip to first unread message

AlexB

unread,
Jun 17, 2019, 2:47:25 PM6/17/19
to Geb User Mailing List
Hi All,

I use BrowserMobProxy as a proxy for ChromeDriver to collect data in HAR file and then save it to a file. I use the file as an additional source of information (together with PageSource and Screenshots) when analyzing test results.

Currently If initiate and start an instance of BrowserMobProxy in my Spec class. And I save the HAR to a file in cleanup() method.

I wanted to find a way to move the saving HAR to file code from cleanup() method into a CustomReporter class. So whenever a test fails - this report would save HAR file.
However I wasn't able to understand how to pass the BrowserMobProxy object into the writeReport() method that does everything in CustomReporter classes.

Do you have an idea how this could be done?

Regards, Alex

Marcin Erdmann

unread,
Jun 24, 2019, 5:10:28 PM6/24/19
to geb-...@googlegroups.com
Hi Alex,

Sorry for a late reply.

You wouldn't be really passing anything to writeReport() as it's a method called by Geb internally. What you need is a geb.report.Reporter implementation that has a reference to your proxy. I can see two ways of doing it:
- making your proxy reference a singleton accessible in static context, that way you can start/reset your proxy from setup() method in a base spec class class and access it to save the file from your reporter implementation registered via the config file
- start/instantiate your proxy from setup/setupSpec() method in a base spec, then pass it to a new instance of the reporter which should then be configured to be used by Geb via geb.Configuration#setReporter() (there's a configuration instance available on geb.Browser instances), possibly using geb.report.CompositeReporter if you want to keep the reporters that are shipped with Geb, and finally tear down the proxy in cleanup/cleanupSpec()

I hope that this helps.

--
You received this message because you are subscribed to the Google Groups "Geb User Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to geb-user+u...@googlegroups.com.
To post to this group, send email to geb-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/geb-user/06b5bdbc-fa5b-4529-b9d6-eb798172e936%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages