From 46b7531e208877e597ab3bacaf11d6ec5e26b40d Mon Sep 17 00:00:00 2001 From: Kristijan Vizi Date: Tue, 23 Jul 2024 15:32:38 +0200 Subject: [PATCH 1/2] New: added mapc sign in flow tests --- envs/envs.js | 2 +- features/dme/signin.spec.js | 38 ++++++++++++++ selectors/dme/signin.page.js | 24 +++++++++ tests/dme/signin.test.js | 97 ++++++++++++++++++++++++++++++++++++ 4 files changed, 160 insertions(+), 1 deletion(-) create mode 100644 features/dme/signin.spec.js create mode 100644 selectors/dme/signin.page.js create mode 100644 tests/dme/signin.test.js diff --git a/envs/envs.js b/envs/envs.js index 6685bdaa..66a1f4fa 100644 --- a/envs/envs.js +++ b/envs/envs.js @@ -22,5 +22,5 @@ module.exports = { '@local6456': 'http://localhost:6456', '@helpx_live': 'https://helpx-internal.stage.adobe.com', '@dx_stage': 'https://stage--dx-partners--adobecom.hlx.live', - '@dme_stage': 'https://partners.stage.adobe.com', + '@dme_stage': 'https://stage--dme-partners--adobecom.hlx.live', }; diff --git a/features/dme/signin.spec.js b/features/dme/signin.spec.js new file mode 100644 index 00000000..01e63d93 --- /dev/null +++ b/features/dme/signin.spec.js @@ -0,0 +1,38 @@ +module.exports = { + FeatureName: 'DME sign in flow page', + features: [ + { + tcid: '1', + name: '@login-sign-in-sign-out-public-page', + path: 'https://partners.stage.adobe.com/channelpartners/drafts/automation/regression/public-page', + tags: '@dme-signin @regression @login @nopr', + data: { + partnerLevel: 'cpp-spain-platinum:', + expectedProtectedHomeURL: 'https://partners.stage.adobe.com/channelpartners/drafts/automation/regression/protected-home', + expectedPublicPageURL: 'https://partners.stage.adobe.com/channelpartners/drafts/automation/regression/public-page', + }, + }, + { + tcid: '2', + name: '@login-accessing-public-home-page-with-member-user-logged-in-to-adobe', + path: 'https://partners.stage.adobe.com/channelpartners/drafts/automation/regression/public-page', + baseURL: 'https://www.stage.adobe.com/partners.html', + tags: '@dme-signin @regression @login @nopr', + data: { + partnerLevel: 'cpp-spain-platinum:', + expectedToSeeInURL: 'https://partners.stage.adobe.com/channelpartners/drafts/automation/regression/protected-home', + }, + }, + { + tcid: '3', + name: '@login-accessing-restricted-home-page-with-member-user-logged-in-to-adobe', + path: 'https://partners.stage.adobe.com/channelpartners/drafts/automation/regression/protected-home', + baseURL: 'https://www.stage.adobe.com/partners.html', + tags: '@dme-signin @regression @login @nopr', + data: { + partnerLevel: 'cpp-spain-platinum:', + expectedToSeeInURL: 'https://partners.stage.adobe.com/channelpartners/drafts/automation/regression/protected-home', + }, + }, + ], +}; diff --git a/selectors/dme/signin.page.js b/selectors/dme/signin.page.js new file mode 100644 index 00000000..60cbc2f4 --- /dev/null +++ b/selectors/dme/signin.page.js @@ -0,0 +1,24 @@ +export default class SignInPage { + constructor(page) { + this.page = page; + this.signInButton = page.locator('button[daa-ll="Sign In"].feds-signIn'); + this.signInButtonStageAdobe = page.locator('.profile-comp.secondary-button'); + this.profileIconButton = page.locator('.feds-profile-button'); + this.userNameDisplay = page.locator('.user-name'); + this.logoutButton = page.locator('[daa-ll="Sign Out"]'); + + this.emailField = page.locator('#EmailPage-EmailField'); + this.emailPageContinueButton = page.locator('//button[@data-id="EmailPage-ContinueButton"]'); + this.passwordField = page.locator('#PasswordPage-PasswordField'); + this.passwordPageContinueButton = page.locator('//button[@data-id="PasswordPage-ContinueButton"]'); + } + + async signIn(page, partnerLevel) { + const email = process.env.IMS_EMAIL.split(partnerLevel)[1].split(';')[0]; + await page.waitForLoadState('networkidle'); + await this.emailField.fill(email); + await this.emailPageContinueButton.click(); + await this.passwordField.fill(process.env.IMS_PASS); + await this.passwordPageContinueButton.click(); + } +} diff --git a/tests/dme/signin.test.js b/tests/dme/signin.test.js new file mode 100644 index 00000000..7c31bf50 --- /dev/null +++ b/tests/dme/signin.test.js @@ -0,0 +1,97 @@ +import { test, expect } from '@playwright/test'; +import SignInPage from '../../selectors/dme/signin.page.js'; + +let signInPage; +const signin = require('../../features/dme/signin.spec.js'); + +const { features } = signin; + +test.describe('MAPC sign in flow', () => { + test.beforeEach(async ({ page }) => { + signInPage = new SignInPage(page); + }); + + test(`${features[0].name},${features[0].tags}`, async ({ page }) => { + await test.step('Go to the home page', async () => { + await page.goto(`${features[0].path}`); + await page.waitForLoadState('domcontentloaded'); + await signInPage.signInButton.click(); + }); + + await test.step('Sign in', async () => { + await signInPage.signIn(page, `${features[0].data.partnerLevel}`); + }); + + await test.step('Verify redirection to restricted home after successful login', async () => { + await signInPage.profileIconButton.waitFor({ state: 'visible', timeout: 20000 }); + const pages = await page.context().pages(); + await expect(pages[0].url()).toContain(`${features[0].data.expectedProtectedHomeURL}`); + }); + + await test.step('Logout', async () => { + await signInPage.profileIconButton.click(); + await signInPage.logoutButton.click(); + }); + + await test.step('Verify redirection to public page after logout', async () => { + await signInPage.signInButton.waitFor({ state: 'visible', timeout: 10000 }); + const pages = await page.context().pages(); + await expect(pages[0].url()) + .toContain(`${features[0].data.expectedPublicPageURL}`); + }); + }); + + test(`${features[1].name},${features[1].tags}`, async ({ page, context }) => { + await test.step('Go to stage.adobe.com', async () => { + const url = `${features[1].baseURL}`; + await page.evaluate((navigationUrl) => { + window.location.href = navigationUrl; + }, url); + + await signInPage.signInButtonStageAdobe.click(); + await page.waitForLoadState('domcontentloaded'); + }); + + await test.step('Sign in with cpp spain platinum user', async () => { + await signInPage.signIn(page, `${features[1].data.partnerLevel}`); + await signInPage.userNameDisplay.waitFor({ state: 'visible', timeout: 20000 }); + }); + + await test.step('Open public page in a new tab', async () => { + const newTab = await context.newPage(); + await newTab.goto(`${features[1].path}`); + const newTabPage = new SignInPage(newTab); + await newTabPage.profileIconButton.waitFor({ state: 'visible', timeout: 20000 }); + const pages = await page.context().pages(); + await expect(pages[1].url()) + .toContain(`${features[1].data.expectedToSeeInURL}`); + }); + }); + + test(`${features[2].name},${features[2].tags}`, async ({ page, context }) => { + await test.step('Go to stage.adobe.com', async () => { + const url = `${features[2].baseURL}`; + await page.evaluate((navigationUrl) => { + window.location.href = navigationUrl; + }, url); + + await signInPage.signInButtonStageAdobe.click(); + await page.waitForLoadState('domcontentloaded'); + }); + + await test.step('Sign in with cpp spain platinum user', async () => { + await signInPage.signIn(page, `${features[2].data.partnerLevel}`); + await signInPage.userNameDisplay.waitFor({ state: 'visible', timeout: 20000 }); + }); + + await test.step('Open restricted page in a new tab', async () => { + const newTab = await context.newPage(); + await newTab.goto(`${features[2].path}`); + const newTabPage = new SignInPage(newTab); + await newTabPage.profileIconButton.waitFor({ state: 'visible', timeout: 20000 }); + const pages = await page.context().pages(); + await expect(pages[1].url()) + .toContain(`${features[2].data.expectedToSeeInURL}`); + }); + }); +}); From ce3612acb8dd9fb6bb7fcff68b9cf1fa6580bc7b Mon Sep 17 00:00:00 2001 From: Kristijan Vizi Date: Wed, 24 Jul 2024 14:09:24 +0200 Subject: [PATCH 2/2] Refactor: extracted verify redirection function --- features/dme/signin.spec.js | 2 ++ selectors/dme/signin.page.js | 27 ++++++++++++++++ tests/dme/signin.test.js | 60 +++++++----------------------------- 3 files changed, 40 insertions(+), 49 deletions(-) diff --git a/features/dme/signin.spec.js b/features/dme/signin.spec.js index 01e63d93..1c500e2c 100644 --- a/features/dme/signin.spec.js +++ b/features/dme/signin.spec.js @@ -21,6 +21,7 @@ module.exports = { data: { partnerLevel: 'cpp-spain-platinum:', expectedToSeeInURL: 'https://partners.stage.adobe.com/channelpartners/drafts/automation/regression/protected-home', + page: 'public page', }, }, { @@ -32,6 +33,7 @@ module.exports = { data: { partnerLevel: 'cpp-spain-platinum:', expectedToSeeInURL: 'https://partners.stage.adobe.com/channelpartners/drafts/automation/regression/protected-home', + page: 'restricted page', }, }, ], diff --git a/selectors/dme/signin.page.js b/selectors/dme/signin.page.js index 60cbc2f4..00584c3f 100644 --- a/selectors/dme/signin.page.js +++ b/selectors/dme/signin.page.js @@ -21,4 +21,31 @@ export default class SignInPage { await this.passwordField.fill(process.env.IMS_PASS); await this.passwordPageContinueButton.click(); } + + async verifyRedirectAfterLogin({ + page, test, expect, newTab, newTabPage, feature, + }) { + await test.step('Go to stage.adobe.com', async () => { + const url = `${feature.baseURL}`; + await page.evaluate((navigationUrl) => { + window.location.href = navigationUrl; + }, url); + + await this.signInButtonStageAdobe.click(); + await page.waitForLoadState('domcontentloaded'); + }); + + await test.step('Sign in with cpp spain platinum user', async () => { + await this.signIn(page, `${feature.data.partnerLevel}`); + await this.userNameDisplay.waitFor({ state: 'visible', timeout: 20000 }); + }); + + await test.step(`Open ${feature.data.page} in a new tab`, async () => { + await newTab.goto(`${feature.path}`); + await newTabPage.profileIconButton.waitFor({ state: 'visible', timeout: 20000 }); + const pages = await page.context().pages(); + await expect(pages[1].url()) + .toContain(`${feature.data.expectedToSeeInURL}`); + }); + } } diff --git a/tests/dme/signin.test.js b/tests/dme/signin.test.js index 7c31bf50..54825557 100644 --- a/tests/dme/signin.test.js +++ b/tests/dme/signin.test.js @@ -5,6 +5,7 @@ let signInPage; const signin = require('../../features/dme/signin.spec.js'); const { features } = signin; +const redirectionFeatures = features.slice(1, 3); test.describe('MAPC sign in flow', () => { test.beforeEach(async ({ page }) => { @@ -41,57 +42,18 @@ test.describe('MAPC sign in flow', () => { }); }); - test(`${features[1].name},${features[1].tags}`, async ({ page, context }) => { - await test.step('Go to stage.adobe.com', async () => { - const url = `${features[1].baseURL}`; - await page.evaluate((navigationUrl) => { - window.location.href = navigationUrl; - }, url); - - await signInPage.signInButtonStageAdobe.click(); - await page.waitForLoadState('domcontentloaded'); - }); - - await test.step('Sign in with cpp spain platinum user', async () => { - await signInPage.signIn(page, `${features[1].data.partnerLevel}`); - await signInPage.userNameDisplay.waitFor({ state: 'visible', timeout: 20000 }); - }); - - await test.step('Open public page in a new tab', async () => { + redirectionFeatures.forEach((feature) => { + test(`${feature.name},${feature.tags}`, async ({ page, context }) => { const newTab = await context.newPage(); - await newTab.goto(`${features[1].path}`); const newTabPage = new SignInPage(newTab); - await newTabPage.profileIconButton.waitFor({ state: 'visible', timeout: 20000 }); - const pages = await page.context().pages(); - await expect(pages[1].url()) - .toContain(`${features[1].data.expectedToSeeInURL}`); - }); - }); - - test(`${features[2].name},${features[2].tags}`, async ({ page, context }) => { - await test.step('Go to stage.adobe.com', async () => { - const url = `${features[2].baseURL}`; - await page.evaluate((navigationUrl) => { - window.location.href = navigationUrl; - }, url); - - await signInPage.signInButtonStageAdobe.click(); - await page.waitForLoadState('domcontentloaded'); - }); - - await test.step('Sign in with cpp spain platinum user', async () => { - await signInPage.signIn(page, `${features[2].data.partnerLevel}`); - await signInPage.userNameDisplay.waitFor({ state: 'visible', timeout: 20000 }); - }); - - await test.step('Open restricted page in a new tab', async () => { - const newTab = await context.newPage(); - await newTab.goto(`${features[2].path}`); - const newTabPage = new SignInPage(newTab); - await newTabPage.profileIconButton.waitFor({ state: 'visible', timeout: 20000 }); - const pages = await page.context().pages(); - await expect(pages[1].url()) - .toContain(`${features[2].data.expectedToSeeInURL}`); + await signInPage.verifyRedirectAfterLogin({ + page, + test, + expect, + newTab, + newTabPage, + feature, + }); }); }); });