test(aio): cleaner approach to reliable Google Analytics e2e tests (#20661)
PR Close #20661
This commit is contained in:
parent
4ec4a99f16
commit
3def2cc552
|
@ -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', () => {
|
describe('google analytics', () => {
|
||||||
|
|
||||||
it('should call ga with initial URL', done => {
|
it('should call ga with initial URL', done => {
|
||||||
|
|
|
@ -29,10 +29,7 @@ export class SitePage {
|
||||||
locationPath() { return browser.executeScript('return document.location.pathname') as promise.Promise<string>; }
|
locationPath() { return browser.executeScript('return document.location.pathname') as promise.Promise<string>; }
|
||||||
|
|
||||||
navigateTo(pageUrl = '') {
|
navigateTo(pageUrl = '') {
|
||||||
return browser.get('/' + 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);'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getDocViewerText() {
|
getDocViewerText() {
|
||||||
|
|
|
@ -34,11 +34,13 @@
|
||||||
|
|
||||||
<!-- Google Analytics -->
|
<!-- Google Analytics -->
|
||||||
<script>
|
<script>
|
||||||
// Note this is a customised version of the GA tracking snippet to aid e2e testing
|
// Note this is a customised version of the GA tracking snippet
|
||||||
// See the bit between /**/.../**/
|
// See the comments below for more info
|
||||||
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
(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),
|
(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');
|
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
|
||||||
</script>
|
</script>
|
||||||
<!-- End Google Analytics -->
|
<!-- End Google Analytics -->
|
||||||
|
|
Loading…
Reference in New Issue