Skip to content

Commit

Permalink
MWPW-153095 Capture Sharepoint Session ID
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon32 committed Jun 21, 2024
1 parent e6aa570 commit d5cd882
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ screenshots/*
axe-reports
/test-results/
/test-html-results/
/test-json-results/
/playwright-report/
/playwright/.cache/
Test.pptx
Expand Down
3 changes: 2 additions & 1 deletion configs/bacom.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ const config = {
: [['html', {
outputFolder: 'test-html-results',
open: 'never',
}], ['list'], ['../utils/reporters/base-reporter.js']],
}], ['list'], ['../utils/reporters/base-reporter.js'],
['json', { outputFile: '../test-json-results/test-results.json' }]],

/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
Expand Down
1 change: 1 addition & 0 deletions data/bacom/stagedBacomUrls.json

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions selectors/bacom-blog/sharepoint.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export default class Sharepoint {
this.dialogText = this.iframe.locator('#WACDialogTextPanel');
this.navButton = this.iframe.locator('#FishBowlNavButton');
this.pageBreaks = this.iframe.locator('span.PageBreakTextSpan');
this.fileButton = this.iframe.getByRole('button', { name: 'File' });
this.aboutButton = this.iframe.getByLabel('About');
this.sessionInfo = this.iframe.getByLabel('Session ID');
this.closeButton = this.iframe.getByLabel('Close', { exact: true });
}

/**
Expand All @@ -31,6 +35,27 @@ export default class Sharepoint {
return '';
}

/**
* Retrieves the session ID from the page.
* @returns {Promise<string>} The session ID.
*/
async getSessionId() {
await expect(async () => {
await this.fileButton.click();
await this.aboutButton.click();
await expect(this.sessionInfo).toBeVisible({ timeout: 1000 });
}).toPass();

const sessionId = await this.sessionInfo.inputValue();

await expect(async () => {
await this.closeButton.click();
await expect(this.aboutButton).not.toBeVisible({ timeout: 1000 });
}).toPass();

return sessionId;
}

/**
* @description Waits for the page to load by checking for key elements.
* @returns {Promise<boolean>} True if the page is loaded, false otherwise.
Expand Down
9 changes: 8 additions & 1 deletion tests/bacom-blog/edit-sharepoint-doc.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ test.describe('Sharepoint editing', { tag: '@sp' }, async () => {
});

testPages.forEach(async (url) => {
await test(`Editing a docx in sharepoint - ${url} `, async () => {
await test(`Editing a docx in sharepoint @ ${url} `, async () => {
await test.setTimeout(1000 * 60 * 2); // Set each test timeout to 2 minutes
const { annotations } = test.info();

await test.step('1. Go to the docx.', async () => {
const { pathname } = new URL(url);
Expand All @@ -43,6 +44,9 @@ test.describe('Sharepoint editing', { tag: '@sp' }, async () => {
.then((req) => (req.ok ? req.json() : Promise.reject(req))), adminPage);
const docxUrl = response?.edit.url;

annotations.push({ type: 'Test Page', description: url });
annotations.push({ type: 'Admin Page', description: adminPage });
annotations.push({ type: 'Docx Url', description: docxUrl });
console.log(`[Test page]: ${url}`);
console.log(`[Admin page]: ${adminPage}`);
console.log(`[Docx Url]: ${docxUrl}\n`);
Expand All @@ -61,6 +65,9 @@ test.describe('Sharepoint editing', { tag: '@sp' }, async () => {
console.log(status);
test.skip(true, status);
}
const sessionId = await sharepoint.getSessionId();
console.log('Session ID:', sessionId);
annotations.push({ type: 'Session ID', description: sessionId });
});

await test.step('3. Make an edit.', async () => {
Expand Down
9 changes: 8 additions & 1 deletion tests/bacom/edit-sharepoint-doc.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ test.describe('Sharepoint editing', { tag: '@sp' }, async () => {
});

testPages.forEach(async (url) => {
await test(`Editing a docx in sharepoint - ${url} `, async () => {
await test(`Editing a docx in sharepoint @ ${url} `, async () => {
await test.setTimeout(1000 * 60 * 2); // Set each test timeout to 2 minutes
const { annotations } = test.info();

await test.step('1. Go to the docx.', async () => {
const { pathname } = new URL(url);
Expand All @@ -49,6 +50,9 @@ test.describe('Sharepoint editing', { tag: '@sp' }, async () => {
const adminPageContent = await page.locator('pre').textContent();
const docxUrl = JSON.parse(adminPageContent).edit.url;

annotations.push({ type: 'Test Page', description: url });
annotations.push({ type: 'Admin Page', description: adminPage });
annotations.push({ type: 'Docx Url', description: docxUrl });
console.log(`[Test page]: ${url}`);
console.log(`[Admin page]: ${adminPage}`);
console.log(`[Docx Url]: ${docxUrl}\n`);
Expand All @@ -67,6 +71,9 @@ test.describe('Sharepoint editing', { tag: '@sp' }, async () => {
console.log(status);
test.skip(true, status);
}
const sessionId = await sharepoint.getSessionId();
console.log('Session ID:', sessionId);
annotations.push({ type: 'Session ID', description: sessionId });
});

await test.step('3. Make an edit.', async () => {
Expand Down

0 comments on commit d5cd882

Please sign in to comment.