From 6d3499f025600446c3fa7bbcea4c2847996e3e0e Mon Sep 17 00:00:00 2001 From: "adam.zakrzewski" Date: Tue, 19 Dec 2023 09:28:42 +0100 Subject: [PATCH 1/5] [ACS-6269] update create file from template tests --- .../create/create-file-from-template.spec.ts | 176 ++++++++++++------ 1 file changed, 121 insertions(+), 55 deletions(-) diff --git a/e2e/playwright/actions/src/tests/create/create-file-from-template.spec.ts b/e2e/playwright/actions/src/tests/create/create-file-from-template.spec.ts index 1b8391b3c0..71406cd9b1 100644 --- a/e2e/playwright/actions/src/tests/create/create-file-from-template.spec.ts +++ b/e2e/playwright/actions/src/tests/create/create-file-from-template.spec.ts @@ -25,19 +25,21 @@ import { expect } from '@playwright/test'; import { AcaHeader, + ApiClientFactory, ContentNodeSelectorDialog, CreateFromTemplateDialogComponent, DataTableComponent, NodeContentTree, NodesApi, + SitesApi, Utils, errorStrings, - getUserState, test } from '@alfresco/playwright-shared'; -test.use({ storageState: getUserState('hruser') }); test.describe('Create file from template', () => { + const apiClientFactory = new ApiClientFactory(); + let nodesApi: NodesApi; let selectFileTemplateDialog: ContentNodeSelectorDialog; let createFileFromTemplateDialog: CreateFromTemplateDialogComponent; let dataTable: DataTableComponent; @@ -46,7 +48,6 @@ test.describe('Create file from template', () => { let randomFileTitle: string; let randomFileDescription: string; let fileLink: string; - let fileId: string; const selectDialogTitle = 'Select a document template'; const dialogBreadcrumb = 'Node Templates'; const nameLabel = 'Name *'; @@ -58,6 +59,7 @@ test.describe('Create file from template', () => { const spaceString = ' '; const commandKey = 'Meta'; const random = Utils.random(); + const username = `user-${Utils.random()}`; const restrictedTemplateFolder = `restricted-templates-${random}`; const templateInRestrictedFolder = `template-restricted-${random}.txt`; @@ -100,25 +102,73 @@ test.describe('Create file from template', () => { }; test.beforeAll(async ({ nodesApiAction }) => { - await nodesApiAction.createContent(templates, `Data Dictionary/Node Templates`); - await nodesApiAction.removeUserAccessOnNodeTemplate(restrictedTemplateFolder); - fileLink = (await nodesApiAction.createLinkToFileName(template2InRoot, await nodesApiAction.getNodeTemplatesFolderId())).entry.name; + try { + await apiClientFactory.setUpAcaBackend('admin'); + await apiClientFactory.createUser({ username: username }); + await nodesApiAction.createContent(templates, `Data Dictionary/Node Templates`); + await nodesApiAction.removeUserAccessOnNodeTemplate(restrictedTemplateFolder); + fileLink = (await nodesApiAction.createLinkToFileName(template2InRoot, await nodesApiAction.getNodeTemplatesFolderId())).entry.name; + } catch (error) { + console.error(`Main beforeAll failed : ${error}`); + } }); - test.beforeEach(async ({ personalFiles }) => { - await personalFiles.navigate(); + test.beforeEach(async ({ loginPage, personalFiles }) => { + try { + await loginPage.loginUser( + { username: username, password: username }, + { + withNavigation: true, + waitForLoading: true + } + ); + await personalFiles.navigate(); + } catch (error) { + console.error(`Main beforeEach failed : ${error}`); + } }); test.afterAll(async ({ nodesApiAction }) => { - await nodesApiAction.cleanupNodeTemplatesItems([templatesFolder1, templatesFolder2, restrictedTemplateFolder, template1InRoot, template2InRoot]); + try { + await nodesApiAction.cleanupNodeTemplatesItems([ + templatesFolder1, + templatesFolder2, + restrictedTemplateFolder, + template1InRoot, + template2InRoot + ]); + } catch (error) { + console.error(`Main afterAll failed : ${error}`); + } }); test.describe('Personal Files page', () => { + test.beforeAll(async () => { + try { + nodesApi = await NodesApi.initialize(username, username); + } catch (error) { + console.error(`Personal Files page, beforeAll failed : ${error}`); + } + }); + test.beforeEach(async ({ personalFiles }) => { - selectFileTemplateDialog = personalFiles.contentNodeSelector; - dataTable = personalFiles.dataTable; - toolbar = personalFiles.acaHeader; - await toolbar.clickCreateFileFromTemplate(); + try { + selectFileTemplateDialog = personalFiles.contentNodeSelector; + dataTable = personalFiles.dataTable; + toolbar = personalFiles.acaHeader; + await toolbar.clickCreateFileFromTemplate(); + await selectFileTemplateDialog.loadMoreNodes(); + } catch (error) { + console.error(`Personal Files page, beforeEach failed : ${error}`); + } + }); + + test.afterAll(async () => { + try { + await nodesApi.deleteCurrentUserNodes(); + } catch (error) { + console.error(`Personal Files page, afterAll failed : ${error}`); + } }); test.describe('Select Template dialog', () => { @@ -196,18 +246,21 @@ test.describe('Create file from template', () => { test.describe('Create document from template dialog', () => { test.beforeAll(async () => { - const nodesApi = await NodesApi.initialize('hruser'); - fileId = (await nodesApi.createFolder(commonFileName)).entry.id; + try { + await nodesApi.createFile(commonFileName); + } catch (error) { + console.error(`Create document from template dialog, beforeAll failed : ${error}`); + } }); test.beforeEach(async ({ personalFiles }) => { - createFileFromTemplateDialog = personalFiles.createFromTemplateDialogComponent; - await dataTable.getRowByName(template1InRoot).click(); - await selectFileTemplateDialog.actionButton.click(); - }); - - test.afterAll(async ({ nodesApiAction }) => { - await nodesApiAction.deleteNodeById(fileId); + try { + createFileFromTemplateDialog = personalFiles.createFromTemplateDialogComponent; + await dataTable.getRowByName(template1InRoot).click(); + await selectFileTemplateDialog.actionButton.click(); + } catch (error) { + console.error(`Create document from template dialog, beforeEach failed : ${error}`); + } }); test('[C325020] Create file from template - dialog UI', async () => { @@ -315,18 +368,16 @@ test.describe('Create file from template', () => { test.describe('File created from template on Personal Files', () => { test.beforeEach(async ({ personalFiles }) => { - randomFileName = `playwright-file-${Utils.random()}`; - randomFileTitle = `file-title-${Utils.random()}`; - randomFileDescription = `file-description-${Utils.random()}`; - createFileFromTemplateDialog = personalFiles.createFromTemplateDialogComponent; - await dataTable.getRowByName(template1InRoot).click(); - await selectFileTemplateDialog.actionButton.click(); - }); - - test.afterEach(async () => { - const nodesApi = await NodesApi.initialize('hruser'); - fileId = await nodesApi.getNodeIdFromParent(randomFileName, '-my-'); - await nodesApi.deleteNodeById(fileId); + try { + randomFileName = `playwright-file-${Utils.random()}`; + randomFileTitle = `file-title-${Utils.random()}`; + randomFileDescription = `file-description-${Utils.random()}`; + createFileFromTemplateDialog = personalFiles.createFromTemplateDialogComponent; + await dataTable.getRowByName(template1InRoot).click(); + await selectFileTemplateDialog.actionButton.click(); + } catch (error) { + console.error(`File created from template on Personal Files, beforeEach failed : ${error}`); + } }); test('[C325030] Create a file from a template - with a new Name', async () => { @@ -351,32 +402,47 @@ test.describe('Create file from template', () => { test.describe('File created from template on Personal Files Libraries', () => { const randomLibraryName = `playwright-library-${Utils.random()}`; - - test.beforeAll(async ({ sitesApiAction, nodesApiAction }) => { - await sitesApiAction.createSite(randomLibraryName); - const libraryGuId = await sitesApiAction.getDocLibId(randomLibraryName); - await nodesApiAction.createFolder(commonFileName, libraryGuId); + let sitesApi: SitesApi; + + test.beforeAll(async () => { + try { + sitesApi = await SitesApi.initialize(username, username); + await sitesApi.createSite(randomLibraryName); + const libraryGuId = await sitesApi.getDocLibId(randomLibraryName); + await nodesApi.createFolder(commonFileName, libraryGuId); + } catch (error) { + console.error(`File created from template on Personal Files Libraries, beforeAll failed : ${error}`); + } }); test.beforeEach(async ({ myLibrariesPage }) => { - randomFileName = `playwright-file-${Utils.random()}`; - randomFileTitle = `file-title-${Utils.random()}`; - randomFileDescription = `file-description-${Utils.random()}`; - await myLibrariesPage.navigate(); - selectFileTemplateDialog = myLibrariesPage.contentNodeSelector; - createFileFromTemplateDialog = myLibrariesPage.createFromTemplateDialogComponent; - dataTable = myLibrariesPage.dataTable; - toolbar = myLibrariesPage.acaHeader; - await dataTable.goThroughPagesLookingForRowWithName(randomLibraryName); - await dataTable.getRowByName(randomLibraryName).dblclick(); - await dataTable.spinnerWaitForReload(); - await toolbar.clickCreateFileFromTemplate(); - await dataTable.getRowByName(template1InRoot).click(); - await selectFileTemplateDialog.actionButton.click(); + try { + randomFileName = `playwright-file-${Utils.random()}`; + randomFileTitle = `file-title-${Utils.random()}`; + randomFileDescription = `file-description-${Utils.random()}`; + await myLibrariesPage.navigate(); + selectFileTemplateDialog = myLibrariesPage.contentNodeSelector; + createFileFromTemplateDialog = myLibrariesPage.createFromTemplateDialogComponent; + dataTable = myLibrariesPage.dataTable; + toolbar = myLibrariesPage.acaHeader; + await dataTable.goThroughPagesLookingForRowWithName(randomLibraryName); + await dataTable.getRowByName(randomLibraryName).dblclick(); + await dataTable.spinnerWaitForReload(); + await toolbar.clickCreateFileFromTemplate(); + await selectFileTemplateDialog.loadMoreNodes(); + await dataTable.getRowByName(template1InRoot).click(); + await selectFileTemplateDialog.actionButton.click(); + } catch (error) { + console.error(`File created from template on Personal Files Libraries, beforeEach failed : ${error}`); + } }); - test.afterAll(async ({ sitesApiAction }) => { - await sitesApiAction.deleteSites([randomLibraryName]); + test.afterAll(async () => { + try { + await sitesApi.deleteSites([randomLibraryName]); + } catch (error) { + console.error(`File created from template on Personal Files Libraries, afterAll failed : ${error}`); + } }); test('[C325023] Create a file from a template from library - with Name, Title and Description', async () => { From f7601087629b214850f9a7c1092e7efab7eb91ca Mon Sep 17 00:00:00 2001 From: "adam.zakrzewski" Date: Tue, 19 Dec 2023 11:51:34 +0100 Subject: [PATCH 2/5] update error messages --- .../create/create-file-from-template.spec.ts | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/e2e/playwright/actions/src/tests/create/create-file-from-template.spec.ts b/e2e/playwright/actions/src/tests/create/create-file-from-template.spec.ts index 71406cd9b1..4fb094b305 100644 --- a/e2e/playwright/actions/src/tests/create/create-file-from-template.spec.ts +++ b/e2e/playwright/actions/src/tests/create/create-file-from-template.spec.ts @@ -38,7 +38,6 @@ import { } from '@alfresco/playwright-shared'; test.describe('Create file from template', () => { - const apiClientFactory = new ApiClientFactory(); let nodesApi: NodesApi; let selectFileTemplateDialog: ContentNodeSelectorDialog; let createFileFromTemplateDialog: CreateFromTemplateDialogComponent; @@ -102,14 +101,15 @@ test.describe('Create file from template', () => { }; test.beforeAll(async ({ nodesApiAction }) => { + const apiService = new ApiClientFactory(); try { - await apiClientFactory.setUpAcaBackend('admin'); - await apiClientFactory.createUser({ username: username }); + await apiService.setUpAcaBackend('admin'); + await apiService.createUser({ username: username }); await nodesApiAction.createContent(templates, `Data Dictionary/Node Templates`); await nodesApiAction.removeUserAccessOnNodeTemplate(restrictedTemplateFolder); fileLink = (await nodesApiAction.createLinkToFileName(template2InRoot, await nodesApiAction.getNodeTemplatesFolderId())).entry.name; } catch (error) { - console.error(`Main beforeAll failed : ${error}`); + console.error(`Main beforeAll failed: ${error}`); } }); @@ -124,7 +124,7 @@ test.describe('Create file from template', () => { ); await personalFiles.navigate(); } catch (error) { - console.error(`Main beforeEach failed : ${error}`); + console.error(`Main beforeEach failed: ${error}`); } }); @@ -138,7 +138,7 @@ test.describe('Create file from template', () => { template2InRoot ]); } catch (error) { - console.error(`Main afterAll failed : ${error}`); + console.error(`Main afterAll failed: ${error}`); } }); @@ -147,7 +147,7 @@ test.describe('Create file from template', () => { try { nodesApi = await NodesApi.initialize(username, username); } catch (error) { - console.error(`Personal Files page, beforeAll failed : ${error}`); + console.error(`Personal Files page, beforeAll failed: ${error}`); } }); @@ -159,7 +159,7 @@ test.describe('Create file from template', () => { await toolbar.clickCreateFileFromTemplate(); await selectFileTemplateDialog.loadMoreNodes(); } catch (error) { - console.error(`Personal Files page, beforeEach failed : ${error}`); + console.error(`Personal Files page, beforeEach failed: ${error}`); } }); @@ -167,7 +167,7 @@ test.describe('Create file from template', () => { try { await nodesApi.deleteCurrentUserNodes(); } catch (error) { - console.error(`Personal Files page, afterAll failed : ${error}`); + console.error(`Personal Files page, afterAll failed: ${error}`); } }); @@ -249,7 +249,7 @@ test.describe('Create file from template', () => { try { await nodesApi.createFile(commonFileName); } catch (error) { - console.error(`Create document from template dialog, beforeAll failed : ${error}`); + console.error(`Create document from template dialog, beforeAll failed: ${error}`); } }); @@ -259,7 +259,7 @@ test.describe('Create file from template', () => { await dataTable.getRowByName(template1InRoot).click(); await selectFileTemplateDialog.actionButton.click(); } catch (error) { - console.error(`Create document from template dialog, beforeEach failed : ${error}`); + console.error(`Create document from template dialog, beforeEach failed: ${error}`); } }); @@ -376,7 +376,7 @@ test.describe('Create file from template', () => { await dataTable.getRowByName(template1InRoot).click(); await selectFileTemplateDialog.actionButton.click(); } catch (error) { - console.error(`File created from template on Personal Files, beforeEach failed : ${error}`); + console.error(`File created from template on Personal Files, beforeEach failed: ${error}`); } }); @@ -411,7 +411,7 @@ test.describe('Create file from template', () => { const libraryGuId = await sitesApi.getDocLibId(randomLibraryName); await nodesApi.createFolder(commonFileName, libraryGuId); } catch (error) { - console.error(`File created from template on Personal Files Libraries, beforeAll failed : ${error}`); + console.error(`File created from template on Personal Files Libraries, beforeAll failed: ${error}`); } }); @@ -433,7 +433,7 @@ test.describe('Create file from template', () => { await dataTable.getRowByName(template1InRoot).click(); await selectFileTemplateDialog.actionButton.click(); } catch (error) { - console.error(`File created from template on Personal Files Libraries, beforeEach failed : ${error}`); + console.error(`File created from template on Personal Files Libraries, beforeEach failed: ${error}`); } }); @@ -441,7 +441,7 @@ test.describe('Create file from template', () => { try { await sitesApi.deleteSites([randomLibraryName]); } catch (error) { - console.error(`File created from template on Personal Files Libraries, afterAll failed : ${error}`); + console.error(`File created from template on Personal Files Libraries, afterAll failed: ${error}`); } }); From 771f3b32eb740cd610ad9e96a9df853c50f65d8e Mon Sep 17 00:00:00 2001 From: "adam.zakrzewski" Date: Tue, 19 Dec 2023 13:52:49 +0100 Subject: [PATCH 3/5] update beforeAll of personal files --- .../src/tests/create/create-file-from-template.spec.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/e2e/playwright/actions/src/tests/create/create-file-from-template.spec.ts b/e2e/playwright/actions/src/tests/create/create-file-from-template.spec.ts index 4fb094b305..2ebf936043 100644 --- a/e2e/playwright/actions/src/tests/create/create-file-from-template.spec.ts +++ b/e2e/playwright/actions/src/tests/create/create-file-from-template.spec.ts @@ -144,11 +144,7 @@ test.describe('Create file from template', () => { test.describe('Personal Files page', () => { test.beforeAll(async () => { - try { - nodesApi = await NodesApi.initialize(username, username); - } catch (error) { - console.error(`Personal Files page, beforeAll failed: ${error}`); - } + nodesApi = await NodesApi.initialize(username, username); }); test.beforeEach(async ({ personalFiles }) => { From af832199982c5f760d2a0b9bc6ad70a6f71b0960 Mon Sep 17 00:00:00 2001 From: "adam.zakrzewski" Date: Tue, 19 Dec 2023 15:15:12 +0100 Subject: [PATCH 4/5] move nodesApi initialize and delete --- .../tests/create/create-file-from-template.spec.ts | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/e2e/playwright/actions/src/tests/create/create-file-from-template.spec.ts b/e2e/playwright/actions/src/tests/create/create-file-from-template.spec.ts index 2ebf936043..0b5d87e915 100644 --- a/e2e/playwright/actions/src/tests/create/create-file-from-template.spec.ts +++ b/e2e/playwright/actions/src/tests/create/create-file-from-template.spec.ts @@ -108,6 +108,7 @@ test.describe('Create file from template', () => { await nodesApiAction.createContent(templates, `Data Dictionary/Node Templates`); await nodesApiAction.removeUserAccessOnNodeTemplate(restrictedTemplateFolder); fileLink = (await nodesApiAction.createLinkToFileName(template2InRoot, await nodesApiAction.getNodeTemplatesFolderId())).entry.name; + nodesApi = await NodesApi.initialize(username, username); } catch (error) { console.error(`Main beforeAll failed: ${error}`); } @@ -137,16 +138,13 @@ test.describe('Create file from template', () => { template1InRoot, template2InRoot ]); + await nodesApi.deleteCurrentUserNodes(); } catch (error) { console.error(`Main afterAll failed: ${error}`); } }); test.describe('Personal Files page', () => { - test.beforeAll(async () => { - nodesApi = await NodesApi.initialize(username, username); - }); - test.beforeEach(async ({ personalFiles }) => { try { selectFileTemplateDialog = personalFiles.contentNodeSelector; @@ -159,14 +157,6 @@ test.describe('Create file from template', () => { } }); - test.afterAll(async () => { - try { - await nodesApi.deleteCurrentUserNodes(); - } catch (error) { - console.error(`Personal Files page, afterAll failed: ${error}`); - } - }); - test.describe('Select Template dialog', () => { test('[C325043] Select template - dialog UI - with existing templates', async () => { await expect.soft(selectFileTemplateDialog.getDialogTitle(selectDialogTitle)).toBeVisible(); From 86ef670c99ca929cfcc9547fef77a4cbf62c3731 Mon Sep 17 00:00:00 2001 From: "adam.zakrzewski" Date: Tue, 19 Dec 2023 15:39:31 +0100 Subject: [PATCH 5/5] removing unnecessary try catch blocks --- .../create/create-file-from-template.spec.ts | 56 +++++-------------- 1 file changed, 15 insertions(+), 41 deletions(-) diff --git a/e2e/playwright/actions/src/tests/create/create-file-from-template.spec.ts b/e2e/playwright/actions/src/tests/create/create-file-from-template.spec.ts index 0b5d87e915..90ed1f1111 100644 --- a/e2e/playwright/actions/src/tests/create/create-file-from-template.spec.ts +++ b/e2e/playwright/actions/src/tests/create/create-file-from-template.spec.ts @@ -102,16 +102,13 @@ test.describe('Create file from template', () => { test.beforeAll(async ({ nodesApiAction }) => { const apiService = new ApiClientFactory(); - try { - await apiService.setUpAcaBackend('admin'); - await apiService.createUser({ username: username }); - await nodesApiAction.createContent(templates, `Data Dictionary/Node Templates`); - await nodesApiAction.removeUserAccessOnNodeTemplate(restrictedTemplateFolder); - fileLink = (await nodesApiAction.createLinkToFileName(template2InRoot, await nodesApiAction.getNodeTemplatesFolderId())).entry.name; - nodesApi = await NodesApi.initialize(username, username); - } catch (error) { - console.error(`Main beforeAll failed: ${error}`); - } + + await apiService.setUpAcaBackend('admin'); + await apiService.createUser({ username: username }); + await nodesApiAction.createContent(templates, `Data Dictionary/Node Templates`); + await nodesApiAction.removeUserAccessOnNodeTemplate(restrictedTemplateFolder); + fileLink = (await nodesApiAction.createLinkToFileName(template2InRoot, await nodesApiAction.getNodeTemplatesFolderId())).entry.name; + nodesApi = await NodesApi.initialize(username, username); }); test.beforeEach(async ({ loginPage, personalFiles }) => { @@ -130,18 +127,8 @@ test.describe('Create file from template', () => { }); test.afterAll(async ({ nodesApiAction }) => { - try { - await nodesApiAction.cleanupNodeTemplatesItems([ - templatesFolder1, - templatesFolder2, - restrictedTemplateFolder, - template1InRoot, - template2InRoot - ]); - await nodesApi.deleteCurrentUserNodes(); - } catch (error) { - console.error(`Main afterAll failed: ${error}`); - } + await nodesApiAction.cleanupNodeTemplatesItems([templatesFolder1, templatesFolder2, restrictedTemplateFolder, template1InRoot, template2InRoot]); + await nodesApi.deleteCurrentUserNodes(); }); test.describe('Personal Files page', () => { @@ -232,11 +219,7 @@ test.describe('Create file from template', () => { test.describe('Create document from template dialog', () => { test.beforeAll(async () => { - try { - await nodesApi.createFile(commonFileName); - } catch (error) { - console.error(`Create document from template dialog, beforeAll failed: ${error}`); - } + await nodesApi.createFile(commonFileName); }); test.beforeEach(async ({ personalFiles }) => { @@ -391,14 +374,10 @@ test.describe('Create file from template', () => { let sitesApi: SitesApi; test.beforeAll(async () => { - try { - sitesApi = await SitesApi.initialize(username, username); - await sitesApi.createSite(randomLibraryName); - const libraryGuId = await sitesApi.getDocLibId(randomLibraryName); - await nodesApi.createFolder(commonFileName, libraryGuId); - } catch (error) { - console.error(`File created from template on Personal Files Libraries, beforeAll failed: ${error}`); - } + sitesApi = await SitesApi.initialize(username, username); + await sitesApi.createSite(randomLibraryName); + const libraryGuId = await sitesApi.getDocLibId(randomLibraryName); + await nodesApi.createFile(commonFileName, libraryGuId); }); test.beforeEach(async ({ myLibrariesPage }) => { @@ -411,7 +390,6 @@ test.describe('Create file from template', () => { createFileFromTemplateDialog = myLibrariesPage.createFromTemplateDialogComponent; dataTable = myLibrariesPage.dataTable; toolbar = myLibrariesPage.acaHeader; - await dataTable.goThroughPagesLookingForRowWithName(randomLibraryName); await dataTable.getRowByName(randomLibraryName).dblclick(); await dataTable.spinnerWaitForReload(); await toolbar.clickCreateFileFromTemplate(); @@ -424,11 +402,7 @@ test.describe('Create file from template', () => { }); test.afterAll(async () => { - try { - await sitesApi.deleteSites([randomLibraryName]); - } catch (error) { - console.error(`File created from template on Personal Files Libraries, afterAll failed: ${error}`); - } + await sitesApi.deleteSites([randomLibraryName]); }); test('[C325023] Create a file from a template from library - with Name, Title and Description', async () => {