Guest User

Untitled

a guest
Feb 23rd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. describe("Video Player", () => {
  2. it("does not have any errors on the page", () => {
  3. browser.manage().logs().get("browser")
  4. .then(logs => {
  5. expect(utils.filterLogs(logs)).toEqual([])
  6. })
  7. })
  8.  
  9. it("fires google analytics beacons", () => {
  10. browser.executeScript("return window.performance.getEntries()")
  11. .then((entries) => {
  12. const ga = utils.getGoogleAnalyticsBeacons(entries)
  13. const firstEvent = ga[0]
  14.  
  15. expect(ga.length).toBeGreaterThan(5)
  16.  
  17. expect(firstEvent.cd10).toBeDefined()
  18. expect(firstEvent.cd11).toBeDefined()
  19. expect(firstEvent.cd12).toBeDefined()
  20. expect(firstEvent.cd14).toEqual("ksbw") // our default data layer
  21. })
  22. })
  23. });
  24.  
  25. /**
  26. * this method returns the logs with known, safe logs removed
  27. */
  28. filterLogs: function (logs) {
  29. const filter = (log) => !(
  30. log.level.name !== "SEVERE" || // remove WARNINGs and below
  31. /favicon/.test(log.message) || // remove the favicon warning if present
  32. /development build of React/.test(log.message) // remove react dev warning
  33. )
  34.  
  35. return logs.filter(filter)
  36. }
  37.  
  38. /**
  39. * This method parses the window.performance.getEntries() result for google analytics beacons.
  40. * We explicitly filter out the initial call to the analytics.js file.
  41. *
  42. * @params {[PerformanceQuery]} performance the result of browser.performance.getEntries()
  43. */
  44. getGoogleAnalyticsBeacons: function (performance) {
  45. const ga = performance.filter(entry => /www.google-analytics.com(?!\/analytics.js)/.test(entry.name))
  46. return ga.map(e => this.fromQuerystring(e.name.substring(e.name.indexOf("?") + 1)))
  47. }
  48.  
  49. /**
  50. * Convert a querystring and convert it to a hash of the parameters.
  51. *
  52. * @param {String} urlParamString - URL parameter string to be converted.
  53. * @return {{}} - URL parameter hash.
  54. */
  55. fromQuerystring: function (urlParamString) {
  56. const result = {}
  57. const urlParamArr = urlParamString.split("&")
  58. let i
  59. for (i of urlParamArr) {
  60. const a = i.split("=")
  61. result[a[0]] = decodeURIComponent(a[1] || "")
  62. if (result[a[0]].indexOf("=") > 0) {
  63. result[a[0]] = this.fromQuerystring(result[a[0]])
  64. }
  65. }
  66.  
  67. return result
  68. }
Add Comment
Please, Sign In to add comment