-
Notifications
You must be signed in to change notification settings - Fork 236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WORLDSERVICE-122: Cypress E2E tests for ATI Analytics #12412
Merged
Merged
Changes from 46 commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
195852a
Add gahuza fixture data to ensure clicking on links does not render a…
karinathomasbbc b410771
Adding E2E tests for ATI component view & click tracking
karinathomasbbc c6ea155
Update test description
karinathomasbbc 9b008c5
Add assertions for the top stories component to the article tests
karinathomasbbc 423f045
Rename tests
karinathomasbbc 82055f3
Tidy up event interception
karinathomasbbc c360b01
Include assertions for the radio schedule on live radio pages
karinathomasbbc 275d252
Add assertions for message banner on homepages & related topics/relat…
karinathomasbbc ee40daf
Add podcast promo & rename helper functions
karinathomasbbc 1048d44
Set data-e2e attribute on the podcast promo component
karinathomasbbc 3e9fbbb
Attempting to fix the issue with the features/analysis click
karinathomasbbc facb0db
Update podcast promo test
karinathomasbbc aac9fee
Loosen route matcher
karinathomasbbc 1047939
Add test attribute to the podcast promo component
karinathomasbbc 5983cf8
Add podcast promo tests to the article assertions
karinathomasbbc 34a3b28
Add placeholder test for lite site cta
karinathomasbbc c1eef43
Add recent audio episodes for OD Audio page
karinathomasbbc 808453d
Update snapshots
karinathomasbbc 76cc8f4
Add whitespace before assertion
karinathomasbbc ac7e2e3
Tweak URLs for different environments
karinathomasbbc e0796f3
Add assertions for podcast external links to podcast pages
karinathomasbbc a37aba2
Tests for latest media component on media article pages
karinathomasbbc 5053c8c
Add latest media component
karinathomasbbc d794133
Include examples for all express page types in ATI analytics tests
karinathomasbbc 1347601
Merge branch 'latest' into cypress-ati-tracking
karinathomasbbc 261223b
Shorten name of podcast links e2e test ID
karinathomasbbc 8360b40
Exclude TV & most read pages from lite tests, as lite is not currentl…
karinathomasbbc d689b3f
Merge branch 'cypress-ati-tracking' of github.com:bbc/simorgh into cy…
karinathomasbbc ce37c56
Update snapshots
karinathomasbbc 96bc138
Adding tests for recommendations & scrollable promo components
karinathomasbbc 9f59d63
Remove unnecessary filter
karinathomasbbc 0ff8170
Update snapshots
karinathomasbbc 5a78537
Adding coverage for topic page
karinathomasbbc 0b5d154
Adding coverage for topic page
karinathomasbbc 4ec7e73
Merge branch 'latest' of github.com:bbc/simorgh into cypress-ati-trac…
karinathomasbbc 6a7f76e
Add lite tests
karinathomasbbc 0e46d16
Assert that expected fields are set on page view, component view & co…
karinathomasbbc bf537fb
Assert that expected fields are set on page view, component view & co…
karinathomasbbc b38376c
Use regex to intercept events
karinathomasbbc 9f068c6
Additional message to the assertions to include the parameter name & …
karinathomasbbc b76bc3c
Don't check x1 on most read
karinathomasbbc 29edbb3
Tidy up assertions
karinathomasbbc 314a6f9
Move page view interception to after component views & clicks
karinathomasbbc a4b2d40
Use its to get the url from the aliased request
karinathomasbbc 5676351
Update test description
karinathomasbbc d0fd435
Stub the ATI requests to ensure events not fired / send to Piano
karinathomasbbc 8e7dd9c
Merge branch 'latest' of github.com:bbc/simorgh into cypress-ati-trac…
karinathomasbbc 0dc7dc9
Only run lite tests against services which have it enabled (only gahu…
karinathomasbbc c87ef55
Merge branch 'latest' into cypress-ati-tracking
karinathomasbbc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
cypress/e2e/specialFeatures/atiAnalytics/assertions/featuresAnalysis.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { interceptATIAnalyticsBeacons, COMPONENTS } from '../helpers'; | ||
import { assertATIComponentClickEvent, assertATIComponentViewEvent } from '.'; | ||
|
||
const { FEATURES } = COMPONENTS; | ||
|
||
export const assertFeaturesAnalysisComponentView = ({ | ||
pageIdentifier, | ||
contentType, | ||
}) => { | ||
it('should send a view event for the Features & Analysis component', () => { | ||
cy.url().then(url => { | ||
interceptATIAnalyticsBeacons(); | ||
cy.visit(url); | ||
|
||
cy.get('[data-testid="features"]').scrollIntoView({ duration: 1000 }); | ||
|
||
assertATIComponentViewEvent({ | ||
component: FEATURES, | ||
pageIdentifier, | ||
contentType, | ||
}); | ||
}); | ||
}); | ||
}; | ||
|
||
export const assertFeaturesAnalysisComponentClick = ({ | ||
pageIdentifier, | ||
contentType, | ||
}) => { | ||
it.skip('should send a click event for the Features & Analysis component', () => { | ||
cy.url().then(url => { | ||
interceptATIAnalyticsBeacons(); | ||
cy.visit(url); | ||
|
||
cy.get('[data-testid="features"]').scrollIntoView({ duration: 1000 }); | ||
|
||
// Click on first item | ||
cy.get('[data-testid="features"]') | ||
.find('a') | ||
.first() | ||
.click({ force: true }); | ||
|
||
assertATIComponentClickEvent({ | ||
component: FEATURES, | ||
pageIdentifier, | ||
contentType, | ||
}); | ||
|
||
// return to previous page | ||
cy.visit(url); | ||
}); | ||
}); | ||
}; |
156 changes: 156 additions & 0 deletions
156
cypress/e2e/specialFeatures/atiAnalytics/assertions/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
import { | ||
ATI_PAGE_VIEW, | ||
getATIParamsFromURL, | ||
interceptATIAnalyticsBeacons, | ||
} from '../helpers'; | ||
|
||
const assertATIPageViewEventParamsExist = ({ | ||
params, | ||
contentType, | ||
applicationType, | ||
}) => { | ||
expect(params).to.have.property('s'); // destination | ||
expect(params).to.have.property('s2'); // producer | ||
expect(params).to.have.property('p'); // page identifier | ||
expect(params).to.have.property('x2'); // application type | ||
expect(params).to.have.property('x3'); // application name | ||
expect(params).to.have.property('x4'); // language | ||
expect(params).to.have.property('x7'); // content type | ||
expect(params).to.have.property('x8'); // library version | ||
expect(params).to.have.property('x9'); // page title | ||
|
||
if (['responsive', 'amp'].includes(applicationType)) { | ||
expect(params).to.have.property('r'); // screen resolution & colour depth | ||
expect(params).to.have.property('re'); // browser/viewport resolution | ||
expect(params).to.have.property('hl'); // timestamp | ||
expect(params).to.have.property('lng'); // device language | ||
expect(params).to.have.property('x5'); // url | ||
} | ||
|
||
if (contentType !== 'list-datadriven') { | ||
expect(params).to.have.property('x1'); // content ID | ||
} | ||
|
||
if (contentType === 'article') { | ||
expect(params).to.have.property('x11'); // first published | ||
expect(params).to.have.property('x12'); // last published | ||
expect(params).to.have.property('x13'); // ldp things | ||
expect(params).to.have.property('x17'); // category | ||
} | ||
}; | ||
|
||
const assertATIComponentViewEventParamsExist = params => { | ||
expect(params).to.have.property('s'); // destination | ||
expect(params).to.have.property('s2'); // producer | ||
expect(params).to.have.property('p'); // page identifier | ||
expect(params).to.have.property('ati'); // view event | ||
expect(params).to.have.property('type'); | ||
expect(params.type).to.equal('AT', 'params.type'); | ||
}; | ||
|
||
const assertATIComponentClickEventParamsExist = params => { | ||
expect(params).to.have.property('s'); // destination | ||
expect(params).to.have.property('s2'); // producer | ||
expect(params).to.have.property('p'); // page identifier | ||
expect(params).to.have.property('atc'); // click event | ||
expect(params).to.have.property('type'); | ||
expect(params.type).to.equal('AT', 'params.type'); | ||
}; | ||
Comment on lines
+7
to
+58
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note for reviewers: I've added a tests to assert that the query params exist, but we are not asserting on the values as they are often dynamic (and the value of adding them is low). |
||
|
||
export const assertPageView = ({ | ||
pageIdentifier, | ||
applicationType, | ||
contentType, | ||
service, | ||
}) => { | ||
it(`should send a page view event with service = ${service}, page identifier = ${pageIdentifier}, application type = ${applicationType} and content type = ${contentType}`, () => { | ||
cy.url().then(url => { | ||
interceptATIAnalyticsBeacons(); | ||
cy.visit(url); | ||
|
||
cy.wait(`@${ATI_PAGE_VIEW}`).then(({ request }) => { | ||
const params = getATIParamsFromURL(request.url); | ||
|
||
assertATIPageViewEventParamsExist({ | ||
params, | ||
contentType, | ||
applicationType, | ||
}); | ||
|
||
expect(params.p).to.equal(pageIdentifier, 'params.p (page identifier)'); | ||
expect(params.x2).to.equal( | ||
`[${applicationType}]`, | ||
'params.x2 (application type)', | ||
); | ||
expect(params.x3).to.equal( | ||
`[news-${service}]`, | ||
'params.x3 (application name)', | ||
); | ||
expect(params.x7).to.equal( | ||
`[${contentType}]`, | ||
'params.x7 (content type)', | ||
); | ||
}); | ||
}); | ||
}); | ||
}; | ||
|
||
const getViewClickDetailsRegex = ({ contentType, component, pageIdentifier }) => | ||
new RegExp( | ||
`PUB-\\[${contentType}.*?\\]-\\[${component}.*?\\]-\\[.*?\\]-\\[.*?\\]-\\[${pageIdentifier}\\]-\\[.*?\\]-\\[.*?\\]-\\[.*?\\]`, | ||
'g', | ||
); | ||
|
||
export const assertATIComponentViewEvent = ({ | ||
component, | ||
pageIdentifier, | ||
contentType, | ||
}) => | ||
cy | ||
.wait(`@${component}-ati-view`) | ||
.its('request.url') | ||
.then(url => { | ||
const params = getATIParamsFromURL(url); | ||
|
||
assertATIComponentViewEventParamsExist(params); | ||
|
||
expect(params.p).to.equal(pageIdentifier, 'params.p (page identifier)'); | ||
expect(params.ati).to.match( | ||
getViewClickDetailsRegex({ | ||
contentType, | ||
component, | ||
pageIdentifier, | ||
}), | ||
'params.ati (publisher impression)', | ||
); | ||
}); | ||
|
||
export const assertATIComponentClickEvent = ({ | ||
component, | ||
contentType, | ||
pageIdentifier, | ||
applicationType, | ||
}) => | ||
cy | ||
.wait(`@${component}-ati-click`) | ||
.its('request.url') | ||
.then(url => { | ||
const params = getATIParamsFromURL(url); | ||
|
||
assertATIComponentClickEventParamsExist(params); | ||
|
||
if (applicationType === 'lite') { | ||
expect(params.app_type).to.equal(applicationType, 'params.app_type'); | ||
} | ||
|
||
expect(params.p).to.equal(pageIdentifier, 'params.p (page identifier)'); | ||
|
||
expect(params.atc).to.match( | ||
getViewClickDetailsRegex({ | ||
contentType, | ||
pageIdentifier, | ||
component, | ||
}), | ||
'params.atc (publisher click)', | ||
); | ||
}); |
52 changes: 52 additions & 0 deletions
52
cypress/e2e/specialFeatures/atiAnalytics/assertions/latestMedia.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { interceptATIAnalyticsBeacons, COMPONENTS } from '../helpers'; | ||
import { assertATIComponentClickEvent, assertATIComponentViewEvent } from '.'; | ||
|
||
const { LATEST_MEDIA } = COMPONENTS; | ||
|
||
export const assertLatestMediaComponentView = ({ | ||
pageIdentifier, | ||
contentType, | ||
}) => { | ||
it('should send a view event for the Latest Media component', () => { | ||
cy.url().then(url => { | ||
interceptATIAnalyticsBeacons(); | ||
cy.visit(url); | ||
|
||
cy.get('[data-testid="latest-media"]').scrollIntoView({ duration: 1000 }); | ||
|
||
assertATIComponentViewEvent({ | ||
component: LATEST_MEDIA, | ||
pageIdentifier, | ||
contentType, | ||
}); | ||
}); | ||
}); | ||
}; | ||
|
||
export const assertLatestMediaComponentClick = ({ | ||
pageIdentifier, | ||
contentType, | ||
}) => { | ||
it('should send a click event for the Latest Media component', () => { | ||
cy.url().then(url => { | ||
interceptATIAnalyticsBeacons(); | ||
cy.visit(url); | ||
|
||
cy.get('[data-testid="latest-media"]').scrollIntoView({ | ||
duration: 1000, | ||
}); | ||
|
||
// Click on first item | ||
cy.get('[data-testid="latest-media"]').find('a').first().click(); | ||
|
||
assertATIComponentClickEvent({ | ||
component: LATEST_MEDIA, | ||
pageIdentifier, | ||
contentType, | ||
}); | ||
|
||
// return to previous page | ||
cy.visit(url); | ||
}); | ||
}); | ||
}; |
33 changes: 33 additions & 0 deletions
33
cypress/e2e/specialFeatures/atiAnalytics/assertions/liteSiteCta.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { COMPONENTS, interceptATIAnalyticsBeacons } from '../helpers'; | ||
import { assertATIComponentClickEvent } from '.'; | ||
|
||
const { LITE_SITE_CTA } = COMPONENTS; | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export const assertLiteSiteCTAComponentClick = ({ | ||
pageIdentifier, | ||
contentType, | ||
}) => { | ||
it('should send a click event for the Lite Site CTA component', () => { | ||
cy.url().then(url => { | ||
interceptATIAnalyticsBeacons(); | ||
cy.visit(url); | ||
|
||
cy.get('[data-e2e="to-main-site"]').scrollIntoView({ | ||
duration: 1000, | ||
}); | ||
|
||
// Click on first item | ||
cy.get('[data-e2e="to-main-site"]').find('a').first().click(); | ||
|
||
assertATIComponentClickEvent({ | ||
component: LITE_SITE_CTA, | ||
pageIdentifier, | ||
contentType, | ||
}); | ||
|
||
// return to previous page | ||
cy.visit(url); | ||
}); | ||
}); | ||
}; |
54 changes: 54 additions & 0 deletions
54
cypress/e2e/specialFeatures/atiAnalytics/assertions/messageBanner.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { interceptATIAnalyticsBeacons, COMPONENTS } from '../helpers'; | ||
import { assertATIComponentClickEvent, assertATIComponentViewEvent } from '.'; | ||
|
||
const { MESSAGE_BANNER } = COMPONENTS; | ||
|
||
export const assertMessageBannerComponentView = ({ | ||
pageIdentifier, | ||
contentType, | ||
}) => { | ||
it('should send a view event for the Message Banner component', () => { | ||
cy.url().then(url => { | ||
interceptATIAnalyticsBeacons(); | ||
cy.visit(url); | ||
|
||
cy.get('[data-testid="message-banner-1"]').scrollIntoView({ | ||
duration: 1000, | ||
}); | ||
|
||
assertATIComponentViewEvent({ | ||
component: MESSAGE_BANNER, | ||
pageIdentifier, | ||
contentType, | ||
}); | ||
}); | ||
}); | ||
}; | ||
|
||
export const assertMessageBannerComponentClick = ({ | ||
pageIdentifier, | ||
contentType, | ||
}) => { | ||
it('should send a click event for the Message Banner component', () => { | ||
cy.url().then(url => { | ||
interceptATIAnalyticsBeacons(); | ||
cy.visit(url); | ||
|
||
cy.get('[data-testid="message-banner-1"]').scrollIntoView({ | ||
duration: 1000, | ||
}); | ||
|
||
// Click on first item | ||
cy.get('[data-testid="message-banner-1"]').find('a').first().click(); | ||
|
||
assertATIComponentClickEvent({ | ||
component: MESSAGE_BANNER, | ||
pageIdentifier, | ||
contentType, | ||
}); | ||
|
||
// return to previous page | ||
cy.visit(url); | ||
}); | ||
}); | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO try to fix this 🤷♀️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #12421 (need to check what the implications are of this fix)