Skip to content

Commit

Permalink
✅[e2e cbt] add edge and firefox (#196)
Browse files Browse the repository at this point in the history
* 🐛[RUM] edge support for navigation timing

retrieve navigation timing when loaded even if PerformanceObserver is not available

* ✅[e2e cbt] make scenarios compatible with edge

browser.keys -> driver error
browser.deleteCookies -> no effect

* ✅[e2e cbt] add firefox browser

* trigger build
  • Loading branch information
bcaudan authored Dec 10, 2019
1 parent 7e2a995 commit 1178b3f
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 13 deletions.
16 changes: 8 additions & 8 deletions packages/rum/src/performanceCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ declare global {
}

function supportPerformanceObject() {
return window.performance !== undefined && 'getEntries' in performance && 'addEventListener' in performance
return window.performance !== undefined && 'getEntries' in performance
}

function supportPerformanceNavigationTimingEvent() {
return (
window.PerformanceObserver &&
PerformanceObserver.supportedEntryTypes !== undefined &&
PerformanceObserver.supportedEntryTypes.includes('navigation')
)
Expand All @@ -30,19 +31,18 @@ export function startPerformanceCollection(lifeCycle: LifeCycle, session: RumSes
)
observer.observe({ entryTypes: ['resource', 'navigation', 'paint', 'longtask'] })

if (supportPerformanceObject()) {
if (supportPerformanceObject() && 'addEventListener' in performance) {
// https://bugzilla.mozilla.org/show_bug.cgi?id=1559377
performance.addEventListener('resourcetimingbufferfull', () => {
performance.clearResourceTimings()
})

if (!supportPerformanceNavigationTimingEvent()) {
retrieveNavigationTimingWhenLoaded((timing) => {
handlePerformanceEntries(session, lifeCycle, [timing])
})
}
}
}
if (!supportPerformanceNavigationTimingEvent()) {
retrieveNavigationTimingWhenLoaded((timing) => {
handlePerformanceEntries(session, lifeCycle, [timing])
})
}
}

interface FakePerformanceNavigationTiming {
Expand Down
10 changes: 10 additions & 0 deletions test/e2e/browsers.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,14 @@ module.exports = [
browserName: 'Safari',
browser_api_name: 'Safari12',
},
{
os_api_name: 'Win10',
browserName: 'Microsoft Edge 18',
browser_api_name: 'Edge18',
},
{
os_api_name: 'Win10',
browserName: 'Firefox 70',
browser_api_name: 'FF70',
},
]
25 changes: 22 additions & 3 deletions test/e2e/scenario/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,28 @@ export function findLastEvent(events: RumEvent[], predicate: (event: RumEvent) =
}

export async function renewSession() {
// Expire sessionId cookie
await browser.deleteCookies(['_dd'])
await deleteAllCookies()
expect(await findSessionCookie()).not.toBeDefined()
// Cookies are cached for 1s, wait until the cache expires
await browser.pause(1100)
await browser.keys(['f'])
const button = await $('button')
await button.click()
expect(await findSessionCookie()).toBeDefined()
}

// wdio method does not work for some browsers
async function deleteAllCookies() {
return browserExecute(() => {
const cookies = document.cookie.split(';')
for (const cookie of cookies) {
const eqPos = cookie.indexOf('=')
const name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie
document.cookie = `${name}=;expires=Thu, 01 Jan 1970 00:00:00 GMT`
}
})
}

async function findSessionCookie() {
// tslint:disable-next-line: no-unsafe-any
return ((await browser.getCookies()) as any[]).find((cookie: any) => cookie.name === '_dd')
}
4 changes: 3 additions & 1 deletion test/static/bundle-e2e-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,7 @@
})
</script>
</head>
<body></body>
<body>
<button>click me</button>
</body>
</html>
4 changes: 3 additions & 1 deletion test/static/npm-e2e-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@
<title>npm tests page</title>
<script type="text/javascript" src="./app.js"></script>
</head>
<body></body>
<body>
<button>click me</button>
</body>
</html>

0 comments on commit 1178b3f

Please sign in to comment.