How do you block Google Analytics from Selenium automated visits?
I have found a few approaches:
Editing the hosts file to redirect Google Analytics to localhost (I'm not too happy about this solution since in the past it has broken some of our integration files)
morde last edited by user
Browsermob-proxy could be used to blacklist the GA hosts, so the code isn't even loaded.
It integrates well with Selenium.
Here is a general purpose talk describing using BMP to blacklist cruft that can slow down automation (Facebook & Twitter widgets are specifically mentioned, but I'm sure GA can also be blacklisted):
And here is a great guide for easily using browsermob-proxy with Selenium in C#. And the regex for blacklisting every request except the
ga.jsfile (this way you can test GA are working and pages won't break that assume the file exists).