Access Keys:
Skip to content (Access Key - 0)
Log in (Access Key - 5)



Toggle Sidebar

GUI coverage using Google Analytics

Google analytics has this nice feature called website overlaying. It marks those areas being clicked upon in order to visualize the user's behaviour.

Why not use that for test coverage?

As Google Analytics requires Javascript code to be present in the AUT, here's a little Greasemonkey snippet doing just that: injecting javascript code to each and every page being visited:

(the file is attached as well)

// ==UserScript==
// Author          Jonas Kilian
// @name           Google Analytics Reverted
// @namespace      http://molyb.org/google-analytics-reverted
// @include        *
// ==/UserScript==

if (document.body) {
	var gadiv = document.createElement("div");
	gadiv.id = "gadiv";
	gadiv.innerHTML = '<div style="position: absolute; left: 0px; top: 0px;' +
	'border-bottom: 1px solid #000000; margin-bottom: 5px; ' +
	'font-size: small; background-color: #000000; z-index: 100;' +
	'color: #ffffff; width:200px; opacity: .75;"><p style="margin: 2px 0 1px 0;"> ' +
	'<b>Google Analytics injected</b>' +
	'</p></div>';

	document.body.insertBefore( gadiv, document.body.firstChild );

	var trackerCode = "UA-0000000";     // <--- YOUR CODE GOES HERE

	var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
	var gascript1 = document.createElement("script");
	gascript1.setAttribute("type", "text/javascript");
	gascript1.setAttribute("src", gaJsHost + "google-analytics.com/ga.js");

	var gascript2 = document.createElement("script");
	gascript2.setAttribute("type", "text/javascript");
	gascript2.innerHTML = 'try { var pageTracker = _gat._getTracker("' + trackerCode + '"); pageTracker._trackPageview();} catch(err) {}';

	document.body.insertBefore( gascript1, document.body.lastChild );
	document.body.insertBefore( gascript2, document.body.lastChild );
}

Create the following structure, referenced later via "${mydir}/src/main/resources/firefox-profile"

Folder gm_scripts
|_ Folder google_analytics_reverte
   |_ File google_analytics_reverte.user.js
|_ File config.xml

You'll find the Greasemonkey's config.xml attached as well.

This is how you then start Molybdenum using ANT with Greasemonkey enabled:

<molybdenum
		profilename="myprofile"
	        firefoxexec="${firefox.exec}"
	        argument="${env}"	
	        log="target/molybdenum.log"
	        testsuite="${path}"
		report="target/ant-molybdenum-report.html"
		headless="${headless}"
		consolelogging="false"
		additionalFirefoxParams="-console">

		<extension xpi="${basedir}/libs/molybdenum-0.7.2.xpi"/>
		<extension xpi="${basedir}/libs/greasemonkey-0.8.20090123.1-fx.xpi"/>
		<fileset dir="${mydir}/src/main/resources/firefox-profile" includes="**"/>

	</molybdenum>

Does it work for you? Send your screenshots to the mailing list...!

last edited on Jul 07, 2009 15:02
Adaptavist Theme Builder Powered by Atlassian Confluence