Skip to content

Commit

Permalink
Refactor: extracted verify redirection function
Browse files Browse the repository at this point in the history
  • Loading branch information
Kristijan Vizi authored and Kristijan Vizi committed Jul 24, 2024
1 parent 46b7531 commit ce3612a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 49 deletions.
2 changes: 2 additions & 0 deletions features/dme/signin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
},
{
Expand All @@ -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',
},
},
],
Expand Down
27 changes: 27 additions & 0 deletions selectors/dme/signin.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
});
}
}
60 changes: 11 additions & 49 deletions tests/dme/signin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand Down Expand Up @@ -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,
});
});
});
});

0 comments on commit ce3612a

Please sign in to comment.