test(aio): cleaner approach to reliable Google Analytics e2e tests (#20661)

PR Close #20661
This commit is contained in:
Peter Bacon Darwin 2017-11-28 13:35:22 +00:00 committed by Miško Hevery
parent 4ec4a99f16
commit 3def2cc552
3 changed files with 6 additions and 9 deletions

View File

@ -80,8 +80,6 @@ describe('site App', function() {
});
});
// TODO(https://github.com/angular/angular/issues/19785): Activate this again
// once it is no more flaky.
describe('google analytics', () => {
it('should call ga with initial URL', done => {

View File

@ -29,10 +29,7 @@ export class SitePage {
locationPath() { return browser.executeScript('return document.location.pathname') as promise.Promise<string>; }
navigateTo(pageUrl = '') {
return browser.get('/' + pageUrl)
// We need to tell the index.html not to load the real analytics library
// See the GA snippet in index.html
.then(() => browser.executeScript('sessionStorage.setItem("__e2e__", true);'));
return browser.get('/' + pageUrl);
}
getDocViewerText() {

View File

@ -34,11 +34,13 @@
<!-- Google Analytics -->
<script>
// Note this is a customised version of the GA tracking snippet to aid e2e testing
// See the bit between /**/.../**/
// Note this is a customised version of the GA tracking snippet
// See the comments below for more info
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;/**/i.sessionStorage.__e2e__||/**/m.parentNode.insertBefore(a,m)
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;
~i.name.indexOf('NG_DEFER_BOOTSTRAP')|| // only load library if not running e2e tests
m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
</script>
<!-- End Google Analytics -->