Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- describe("Video Player", () => {
- it("does not have any errors on the page", () => {
- browser.manage().logs().get("browser")
- .then(logs => {
- expect(utils.filterLogs(logs)).toEqual([])
- })
- })
- it("fires google analytics beacons", () => {
- browser.executeScript("return window.performance.getEntries()")
- .then((entries) => {
- const ga = utils.getGoogleAnalyticsBeacons(entries)
- const firstEvent = ga[0]
- expect(ga.length).toBeGreaterThan(5)
- expect(firstEvent.cd10).toBeDefined()
- expect(firstEvent.cd11).toBeDefined()
- expect(firstEvent.cd12).toBeDefined()
- expect(firstEvent.cd14).toEqual("ksbw") // our default data layer
- })
- })
- });
- /**
- * this method returns the logs with known, safe logs removed
- */
- filterLogs: function (logs) {
- const filter = (log) => !(
- log.level.name !== "SEVERE" || // remove WARNINGs and below
- /favicon/.test(log.message) || // remove the favicon warning if present
- /development build of React/.test(log.message) // remove react dev warning
- )
- return logs.filter(filter)
- }
- /**
- * This method parses the window.performance.getEntries() result for google analytics beacons.
- * We explicitly filter out the initial call to the analytics.js file.
- *
- * @params {[PerformanceQuery]} performance the result of browser.performance.getEntries()
- */
- getGoogleAnalyticsBeacons: function (performance) {
- const ga = performance.filter(entry => /www.google-analytics.com(?!\/analytics.js)/.test(entry.name))
- return ga.map(e => this.fromQuerystring(e.name.substring(e.name.indexOf("?") + 1)))
- }
- /**
- * Convert a querystring and convert it to a hash of the parameters.
- *
- * @param {String} urlParamString - URL parameter string to be converted.
- * @return {{}} - URL parameter hash.
- */
- fromQuerystring: function (urlParamString) {
- const result = {}
- const urlParamArr = urlParamString.split("&")
- let i
- for (i of urlParamArr) {
- const a = i.split("=")
- result[a[0]] = decodeURIComponent(a[1] || "")
- if (result[a[0]].indexOf("=") > 0) {
- result[a[0]] = this.fromQuerystring(result[a[0]])
- }
- }
- return result
- }
Add Comment
Please, Sign In to add comment