I am working on Google Analytics automation test with Selenium WebDriver java bindings. Our site has Google Analytics tracking events set on important elements on the site. I need to verify that on clicking a certain element under test, the Google Analytic event is in fact fired.
I'm testing it on FireFox. When I click F12, I can see in the console that a Google Analytics is fired with message GET http://www.google-analytics.com/__utm.gif
on each element click event.
SampleCode :-
WebDriver wd = new FirefoxDriver();
wd.get("http://www.dummyExample.com/");
wd.findElement(By.linkText("Document Referece")).click();
wd.findElement(By.id("Ex2vc2")).click();
How can I achieve this task? I have googled it but could not find good answers. If anyone can help me with some references or sample code I would be very Thankful.
http://viget.com/extend/testing-google-analytics-with-phantomjs
Second way is to use HttpProxy. AFAIK there was tool - BrowserMobProxy. You'll be able to sniff all requests on testing website, but they in HAR format. So the algorithm is simple, enable proxy, open website, do actions, sniff requests, parse them and assert the values.
Change endpoint and save all requests to assert them. So usually analytics sends requests to the same url, like 'http://google.com/analytics' or whatever. So, you can change this behavior on testing webserver. F.e. add this url to /etc/hosts with localhost address. And then all requests on webserver which are sent to GA domain will be received by webserver.
That will require extra programming. But it's the cleanest way for testing IMHO.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With