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
test(WESTEAMA-1180): update topicPage tests to not use BFF #11554
Conversation
0345d1c
to
8aef79a
Compare
cypress/e2e/pages/topicPage/tests.js
Outdated
describe(`Pagination`, () => { | ||
it('should show pagination if there is more than one page', () => { | ||
// First return to the topics page. Last test has page on article | ||
cy.go('back'); | ||
if (pageCount === undefined) { |
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.
Do we need this conditional here to skip the test?
If we do, do we want to have a log to say why the pageCount might be undefined? It could be undefined because we are on the wrong page, like how we saw when we looked at the test failures from being still on an article page. You visiting the pages in the BeforeEach in the describe block above should ensure this doesn't happen. Is there another reason why it could happen, and if so, should be log something so we don't start skipping the first test without knowing? (although, the following tests would fail anyway if the pagination isn't present).
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.
I don't think we need this - we check below whether pageCount is > 1, and will only run the pagination assertions if that's the case. Let's remove this.
const selector = '[data-testid="topic-promos"]:first > li'; | ||
const promoCount = Cypress.$(selector).length; | ||
cy.log(`Number of promos on the page${promoCount}`); | ||
|
||
if (promoCount !== numberOfItems) { | ||
cy.window().then(win => { | ||
const pageData = win.SIMORGH_DATA; |
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.
If we want to keep this log (I think we should, especially as we are seeing if this helps flakiness), shall we use the data we got on line 35?
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.
@LilyL0u I think we agreed that we no longer needed this log, because the number of items should always be consistent with the promoCount since the data is coming from window.SIMORGH_DATA and not potentially outdated / "too new" (i.e. data is newer than the page being tests) BFF data
But, we can leave it as is, and monitor it in Live for a while, and remove at a later date?
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.
Nice work @MeriemMechri, thanks for fixing this up, this will hopefully bring stability to these tests going forward!
const selector = '[data-testid="topic-promos"]:first > li'; | ||
const promoCount = Cypress.$(selector).length; | ||
cy.log(`Number of promos on the page${promoCount}`); | ||
|
||
if (promoCount !== numberOfItems) { | ||
cy.window().then(win => { | ||
const pageData = win.SIMORGH_DATA; |
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.
@LilyL0u I think we agreed that we no longer needed this log, because the number of items should always be consistent with the promoCount since the data is coming from window.SIMORGH_DATA and not potentially outdated / "too new" (i.e. data is newer than the page being tests) BFF data
But, we can leave it as is, and monitor it in Live for a while, and remove at a later date?
cypress/e2e/pages/topicPage/tests.js
Outdated
describe(`Pagination`, () => { | ||
it('should show pagination if there is more than one page', () => { | ||
// First return to the topics page. Last test has page on article | ||
cy.go('back'); | ||
if (pageCount === undefined) { |
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.
I don't think we need this - we check below whether pageCount is > 1, and will only run the pagination assertions if that's the case. Let's remove this.
export const getPageDataFromWindow = () => { | ||
cy.window().then(win => { | ||
const pageData = win.SIMORGH_DATA; | ||
return pageData; | ||
}); | ||
}; | ||
|
||
Cypress.Commands.add('testResponseCodeAndType', testResponseCodeAndType); | ||
Cypress.Commands.add('testResponseCodeAndTypeRetry', testResponseCodeAndType); | ||
Cypress.Commands.add('getPageData', getPageData); | ||
Cypress.Commands.add('getPageDataFromWindow', getPageDataFromWindow); |
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.
Just a note that we might need to be careful of a conflict if Lily's article fetching PR is merged first (but we can figure that out depending on which PR is merged first)
I'm not sure about having it in a position where it runs for all the tests, as the pagination tests are a sequential user journey (e.g go to second page by clicking number 2, check page number, go to third page by clicking the next arrow, check page number. Next/Previous button tests won't have the same results if we go back to the same page before each test). For the page content tests this is fine, but not the pagination ones. |
// Checks number of items on page | ||
cy.get('[data-testid="topic-promos"]') | ||
.first() | ||
.children() | ||
.its('length') | ||
.should('eq', numberOfItems); | ||
}); | ||
it.skip('First item has correct headline', () => { | ||
|
||
it('First item has correct headline', () => { |
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.
The reason I skipped this test originally was because sometimes the promo headline is different from the full article headline, which causes a failure, but it is expected as sometimes there is a shortHeadline which is different from the longer one used in the article.
I am thinking maybe we either remove this test or just leave it to see if this still happens. What do you think @karinathomasbbc ?
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.
I think that's a good shout - add logging if it doesn't exist, and keep an eye on the channel so that we can quickly disable / fix if it becomes an issue?
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.
Yes, that makes sense .. I already added a cy.log
, let me know if that's enough to monitor the test
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.
Ah yes - in fact, the test won't fail anymore because you're checking if firstItemHeadline
has a value and then exiting, so the tests won't be "flaky" anymore, but there is no guarantee that it will always run the assertions.
c375d4d
to
2907160
Compare
test(WESTEAMA-1180): update topicPage tests to not use BFF refactor: fix failing test by adding goBack(() function and reomve any unecessary spaces/ console logs Refactor: removed console log refactor: fix failing test by adding BeforeEach function that will take us back each time to the current path that being tested fix: fix linting issues refactor: move to async/await instead of promise refactor(pr-feedback): remove unnecessary conditon
2907160
to
0b9393f
Compare
Resolves JIRA [WSTEAMA-1180]
Overall changes
Refactor and stabilise tests for topic page.
Code changes
cy.getPageData function
and replaced it withgetPageDataFromWindow
BeforeEach()
function, to ensure we always start from the path being tested and make the tests deterministicTesting
Helpful Links
Add Links to useful resources related to this PR if applicable.
Coding Standards
Repository use guidelines