From 64166560ebbfcfcc12c942b581736fca03a3f2d7 Mon Sep 17 00:00:00 2001 From: Kristijan Vizi Date: Thu, 8 Aug 2024 15:25:36 +0200 Subject: [PATCH] New: added pagination test for partner news --- features/dx/news.spec.js | 34 +++++++++---- selectors/dx/news.page.js | 8 +++ tests/dx/news.test.js | 102 +++++++++++++++++++++++++------------- 3 files changed, 100 insertions(+), 44 deletions(-) diff --git a/features/dx/news.spec.js b/features/dx/news.spec.js index 19f57d03..ccbdac57 100644 --- a/features/dx/news.spec.js +++ b/features/dx/news.spec.js @@ -17,7 +17,7 @@ module.exports = { }, { tcid: '2', - name: '@desc-regression-news-page-pagination-sort', + name: '@desc-regression-news-page-load-more-sort', path: '/solutionpartners/drafts/automation/regression/partner-news', data: { cardTitle: 'Automation regression news card SPP', @@ -31,6 +31,22 @@ module.exports = { }, { tcid: '3', + name: '@desc-regression-news-page-pagination', + path: '/solutionpartners/drafts/automation/regression/partner-news-paginated', + tags: '@dx-news @regression @anonymous', + data: { + searchCards: 'Automation regression news card SPP', + firstPageResult: '1 - 3 of 8 results', + secondPageResult: '4 - 6 of 8 results', + thirdPageResult: '7 - 8 of 8 results', + numberOfCardsWithTitle: 8, + numberOfPublicCards: 9, + pageButtonNumber: 2, + totalPageCount: 3, + }, + }, + { + tcid: '4', name: '@desc-regression-news-page-filters', path: '/solutionpartners/drafts/automation/regression/partner-news', tags: '@dx-news @regression @anonymous', @@ -55,7 +71,7 @@ module.exports = { }, }, { - tcid: '4', + tcid: '5', name: '@desc-regression-news-page-read-article', path: '/solutionpartners/drafts/automation/regression/partner-news', data: { @@ -66,7 +82,7 @@ module.exports = { tags: '@dx-news @regression @anonymous', }, { - tcid: '5', + tcid: '6', name: '@desc-news-page-edge-cases', path: '/solutionpartners/drafts/automation/regression/partner-news', data: { @@ -82,7 +98,7 @@ module.exports = { tags: '@dx-news @regression @anonymous', }, { - tcid: '6', + tcid: '7', name: '@login-news-page-platinum-user', path: '/solutionpartners/drafts/automation/regression/partner-news', tags: '@dx-news @regression @anonymous', @@ -99,7 +115,7 @@ module.exports = { }, }, { - tcid: '7', + tcid: '8', name: '@login-news-page-gold-user', path: '/solutionpartners/drafts/automation/regression/partner-news', tags: '@dx-news @regression @anonymous', @@ -115,7 +131,7 @@ module.exports = { }, }, { - tcid: '8', + tcid: '9', name: '@login-news-page-silver-user', path: '/solutionpartners/drafts/automation/regression/partner-news', tags: '@dx-news @regression @anonymous', @@ -131,7 +147,7 @@ module.exports = { }, }, { - tcid: '9', + tcid: '10', name: '@login-news-page-bronze-user', path: '/solutionpartners/drafts/automation/regression/partner-news', tags: '@dx-news @regression @anonymous', @@ -147,7 +163,7 @@ module.exports = { }, }, { - tcid: '10', + tcid: '11', name: '@login-news-page-community-user', path: '/solutionpartners/drafts/automation/regression/partner-news', tags: '@dx-news @regression @anonymous', @@ -163,7 +179,7 @@ module.exports = { }, }, { - tcid: '11', + tcid: '12', name: '@login-news-page-non-member-of-spp-user', path: '/solutionpartners/drafts/automation/regression/partner-news', tags: '@dx-news @regression @anonymous', diff --git a/selectors/dx/news.page.js b/selectors/dx/news.page.js index 8414f408..26479a39 100644 --- a/selectors/dx/news.page.js +++ b/selectors/dx/news.page.js @@ -13,6 +13,10 @@ export default class NewsPage { this.loadMore = page.locator('[aria-label="Load more"]'); this.firstCardDate = page.locator('.card-date').nth(0); this.lastCardDate = page.locator('.card-date').nth(5); + this.paginationPrevButton = page.locator('button.pagination-prev-btn'); + this.paginationNextButton = page.locator('button.pagination-next-btn'); + this.pageNumButton = page.locator('button.page-btn'); + this.pageCount = page.locator('.page-btn'); this.signInButton = page.locator('button[daa-ll="Sign In"].feds-signIn'); this.profileIconButton = page.locator('.feds-profile-button'); @@ -38,4 +42,8 @@ export default class NewsPage { async clearFilter(filter, number) { await this.page.locator(`[aria-label="${filter}"] + [aria-label="${number}"]`).click(); } + + async clickPageNumButton(pageNum) { + await this.page.locator(`button[aria-label="Page ${pageNum}"]`).click(); + } } diff --git a/tests/dx/news.test.js b/tests/dx/news.test.js index 8561c0eb..d1be711d 100644 --- a/tests/dx/news.test.js +++ b/tests/dx/news.test.js @@ -42,10 +42,9 @@ test.describe('Validate news block', () => { } test(`${features[0].name},${features[0].tags}`, async ({ page, baseURL }) => { - const { data } = features[0]; + const { data, path } = features[0]; await test.step('Go to News page', async () => { - console.log('url: ', baseURL + features[0].path); - await page.goto(`${baseURL}${features[0].path}`); + await page.goto(`${baseURL}${path}`); await page.waitForResponse(chimeraApi); const result = await newsPage.resultNumber.textContent(); await expect(parseInt(result.split(' ')[0], 10)).toBe(data.numberOfPublicCards); @@ -83,9 +82,9 @@ test.describe('Validate news block', () => { }); test(`${features[1].name},${features[1].tags}`, async ({ page, baseURL }) => { - const { data } = features[1]; + const { data, path } = features[1]; await test.step('Go to News page', async () => { - await page.goto(`${baseURL}${features[1].path}`); + await page.goto(`${baseURL}${path}`); await page.waitForResponse(chimeraApi); await newsPage.firstCardDate.waitFor({ state: 'visible', timeout: 20000 }); const result = await newsPage.resultNumber.textContent(); @@ -118,9 +117,42 @@ test.describe('Validate news block', () => { }); test(`${features[2].name},${features[2].tags}`, async ({ page, baseURL }) => { - const { data } = features[2]; + const { data, path } = features[2]; await test.step('Go to News page', async () => { - await page.goto(`${baseURL}${features[2].path}`); + await page.goto(`${baseURL}${path}`); + await newsPage.firstCardDate.waitFor({ state: 'visible', timeout: 15000 }); + const result = await newsPage.resultNumber.textContent(); + await expect(parseInt(result.split(' ')[0], 10)).toBe(data.numberOfPublicCards); + await newsPage.searchField.fill(data.searchCards); + const filteredCards = await newsPage.resultNumber.textContent(); + await expect(parseInt(filteredCards.split(' ')[0], 10)).toBe(data.numberOfCardsWithTitle); + }); + + await test.step('Verify pagination buttons', async () => { + let paginationText = await newsPage.paginationText.textContent(); + await expect(paginationText.toLowerCase()).toBe(data.firstPageResult); + const paginationPrevButton = await newsPage.paginationPrevButton; + await expect(paginationPrevButton).toHaveClass(/disabled/); + const paginationNextButton = await newsPage.paginationNextButton; + await expect(paginationNextButton).not.toHaveClass(/disabled/); + await expect(await newsPage.pageCount.count()).toBe(data.totalPageCount); + await newsPage.clickPageNumButton(data.pageButtonNumber); + paginationText = await newsPage.paginationText.textContent(); + await expect(paginationText.toLowerCase()).toBe(data.secondPageResult); + await expect(paginationPrevButton).not.toHaveClass(/disabled/); + await expect(paginationNextButton).not.toHaveClass(/disabled/); + await paginationNextButton.click(); + paginationText = await newsPage.paginationText.textContent(); + await expect(paginationText.toLowerCase()).toBe(data.thirdPageResult); + await expect(paginationPrevButton).not.toHaveClass(/disabled/); + await expect(paginationNextButton).toHaveClass(/disabled/); + }); + }); + + test(`${features[3].name},${features[3].tags}`, async ({ page, baseURL }) => { + const { data, path } = features[3]; + await test.step('Go to News page', async () => { + await page.goto(`${baseURL}${path}`); await page.waitForResponse(chimeraApi); await newsPage.firstCardDate.waitFor({ state: 'visible', timeout: 20000 }); const result = await newsPage.resultNumber.textContent(); @@ -174,10 +206,10 @@ test.describe('Validate news block', () => { }); }); - test(`${features[3].name},${features[3].tags}`, async ({ page, baseURL }) => { - const { data } = features[3]; + test(`${features[4].name},${features[4].tags}`, async ({ page, baseURL }) => { + const { data, path } = features[4]; await test.step('Go to News page', async () => { - await page.goto(`${baseURL}${features[3].path}`); + await page.goto(`${baseURL}${path}`); await page.waitForLoadState('domcontentloaded'); await newsPage.searchField.fill(data.cardTitle); await newsPage.firstCardTitle.waitFor({ state: 'visible', timeout: 10000 }); @@ -193,10 +225,10 @@ test.describe('Validate news block', () => { }); }); - test(`${features[4].name},${features[4].tags}`, async ({ page, baseURL }) => { - const { data } = features[4]; + test(`${features[5].name},${features[5].tags}`, async ({ page, baseURL }) => { + const { data, path } = features[5]; await test.step('Go to News page', async () => { - await page.goto(`${baseURL}${features[4].path}`); + await page.goto(`${baseURL}${path}`); await page.waitForResponse(chimeraApi); const result = await newsPage.resultNumber.textContent(); await expect(parseInt(result.split(' ')[0], 10)).toBe(data.numberOfPublicCards); @@ -224,10 +256,10 @@ test.describe('Validate news block', () => { }); }); - test(`${features[5].name},${features[5].tags}`, async ({ page, context, baseURL }) => { - const { data } = features[5]; + test(`${features[6].name},${features[6].tags}`, async ({ page, context, baseURL }) => { + const { data, path } = features[6]; await test.step('Click Sign In', async () => { - await page.goto(`${baseURL}${features[5].path}`); + await page.goto(`${baseURL}${path}`); await page.waitForLoadState('domcontentloaded'); await page.waitForResponse(chimeraApi); const result = await newsPage.resultNumber.textContent(); @@ -235,7 +267,7 @@ test.describe('Validate news block', () => { await newsPage.searchField.fill(data.platinumCard); const resultPlatinum = await newsPage.resultNumber.textContent(); await expect(parseInt(resultPlatinum.split(' ')[0], 10)).toBe(data.noCards); - await signInPage.addCookie(data.partnerPortal, data.partnerLevel, baseURL + features[5].path, context); + await signInPage.addCookie(data.partnerPortal, data.partnerLevel, baseURL + path, context); await page.reload(); await page.waitForLoadState('domcontentloaded'); @@ -258,60 +290,60 @@ test.describe('Validate news block', () => { }); }); - test(`${features[6].name},${features[6].tags}`, async ({ page, context, baseURL }) => { - const { data } = features[6]; + test(`${features[7].name},${features[7].tags}`, async ({ page, context, baseURL }) => { + const { data, path } = features[7]; await findCardsForPartnerLevel( page, - baseURL + features[6].path, + baseURL + path, data, context, ); }); - test(`${features[7].name},${features[7].tags}`, async ({ page, context, baseURL }) => { - const { data } = features[7]; + test(`${features[8].name},${features[8].tags}`, async ({ page, context, baseURL }) => { + const { data, path } = features[8]; await findCardsForPartnerLevel( page, - baseURL + features[7].path, + baseURL + path, data, context, ); }); - test(`${features[8].name},${features[8].tags}`, async ({ page, context, baseURL }) => { - const { data } = features[8]; + test(`${features[9].name},${features[9].tags}`, async ({ page, context, baseURL }) => { + const { data, path } = features[9]; await findCardsForPartnerLevel( page, - baseURL + features[8].path, + baseURL + path, data, context, ); }); - test(`${features[9].name},${features[9].tags}`, async ({ page, context, baseURL }) => { - const { data } = features[9]; + test(`${features[10].name},${features[10].tags}`, async ({ page, context, baseURL }) => { + const { data, path } = features[10]; await test.step('Click Sign In', async () => { await findCardsForPartnerLevel( page, - baseURL + features[9].path, + baseURL + path, data, context, ); }); }); - test(`${features[10].name},${features[10].tags}`, async ({ page, context, baseURL }) => { - const { data } = features[10]; + test(`${features[11].name},${features[11].tags}`, async ({ page, context, baseURL }) => { + const { data, path } = features[11]; await test.step('Go to stage.adobe.com', async () => { - await page.goto(`${baseURL}${features[10].path}`); - await signInPage.addCookie(data.partnerPortal, data.partnerLevel, baseURL + features[10].path, context); + await page.goto(`${baseURL}${path}`); + await signInPage.addCookie(data.partnerPortal, data.partnerLevel, baseURL + path, context); await page.reload(); await page.waitForLoadState('domcontentloaded'); }); - await test.step(`Open ${features[10].path} in a new tab`, async () => { + await test.step(`Open ${path} in a new tab`, async () => { const newTab = await context.newPage(); - await newTab.goto(`${features[10].path}`); + await newTab.goto(`${path}`); const newTabPage = new NewsPage(newTab); await newTab.waitForResponse(chimeraApi); const resultCards = await newTabPage.resultNumber.textContent();