diff --git a/playwright/e2e/atk_entity/atk_media.spec.js b/playwright/e2e/atk_entity/atk_media.spec.js index d4c9da5dd07496d49ec72e279e3d43974922d063..22c1c8b86d1bd5987f09ec58c1fe1729bf0cdf5b 100644 --- a/playwright/e2e/atk_entity/atk_media.spec.js +++ b/playwright/e2e/atk_entity/atk_media.spec.js @@ -71,15 +71,15 @@ test.describe('Media tests.', () => { // and NaturalHeight properties. let isImageDownloaded = await imageLocator.evaluate((img) => img.naturalWidth > 0 && img.naturalHeight > 0); - // Extract the media id that was added by - // automated_testing_kit_preprocess_image(). - const mid = await imageLocator.getAttribute('data-media-id'); + // Extract the edit and delete hrefs. + const rowLocator = page.locator('tr', { has: imageLocator }); + const mediaEditUrl = await rowLocator.locator('a[href*="edit"]').first().getAttribute('href'); + const mediaDeleteUrl = await rowLocator.locator('a[href*="delete"]').getAttribute('href'); // // Update the media. // - const mediaEditUrl = atkConfig.mediaEditUrl.replace('{mid}', mid); - await page.goto(baseUrl + mediaEditUrl); + await page.goto(mediaEditUrl); await page.getByRole('button', { name: 'Remove' }).click(); await page.setInputFiles('input[name="files[field_media_image_0]"]', image2Filepath); await altField.fill(`${testId}: ${uniqueToken2}`); @@ -101,8 +101,7 @@ test.describe('Media tests.', () => { // // Delete the media entity. // - const mediaDeleteUrl = atkConfig.mediaDeleteUrl.replace('{mid}', mid); - await page.goto(baseUrl + mediaDeleteUrl); + await page.goto(mediaDeleteUrl); await page.getByRole('button', { name: 'Delete' }).click(); }); }); diff --git a/playwright/e2e/atk_entity/atk_node.spec.js b/playwright/e2e/atk_entity/atk_node.spec.js index 95a691b01c586a7cca1fa1eb38a66a69ac8b01a1..a2a499fb47a68f7041339e620616830336cd30f6 100644 --- a/playwright/e2e/atk_entity/atk_node.spec.js +++ b/playwright/e2e/atk_entity/atk_node.spec.js @@ -54,27 +54,15 @@ test.describe('Node tests.', () => { // // Confirm content appears. // - let divContainer = await page.textContent('.text-content'); + let divContainer = await page.textContent('.node__content'); await expect(divContainer).toContain(bodyText); - // Extract the nid placed in the body class by this hook: - // automated_testing_kit.module:automated_testing_kit_preprocess_html(). - // Wait for the page to load - await page.waitForLoadState('domcontentloaded'); - const bodyClass = await page.evaluate(() => document.body.className); - const match = bodyClass.match(/node-nid-(\d+)/); - - // Get the nid. - const nid = parseInt(match[1], 10); - // // Update the node. // - const nodeEditUrl = atkConfig.nodeEditUrl.replace('{nid}', nid); - bodyText = 'Ut eget ex vitae nibh dapibus vulputate ut id lacus.'; - await page.goto(baseUrl + nodeEditUrl); + await page.getByRole('link', { name: 'Edit' }).click(); ckEditor = await page.locator('[aria-label="Editor editing area: main"]'); await ckEditor.fill(bodyText); // Timeouts necessary when running at full speed. @@ -85,14 +73,14 @@ test.describe('Node tests.', () => { // // Confirm content has changed. // - divContainer = await page.locator('.text-content'); + divContainer = await page.locator('.node__content'); const text = await divContainer.textContent(); await expect(text).toContain(bodyText); // // Delete the node. // - await atkCommands.deleteNodeViaUiWithNid(page, context, nid); + await atkCommands.deleteCurrentNodeViaUi(page); }); // @@ -131,7 +119,7 @@ test.describe('Node tests.', () => { // // Confirm content appears. // - let divContainer = await page.textContent('.text-content'); + let divContainer = await page.textContent('.node__content'); await expect(divContainer).toContain(bodyText); // Extract the nid placed in the body class by this hook: @@ -141,17 +129,12 @@ test.describe('Node tests.', () => { const bodyClass = await page.evaluate(() => document.body.className); const match = bodyClass.match(/node-nid-(\d+)/); - // Get the nid. - const nid = parseInt(match[1], 10); - // // Update the node. // - const nodeEditUrl = atkConfig.nodeEditUrl.replace('{nid}', nid); - bodyText = 'Ut eget ex vitae nibh dapibus vulputate ut id lacus.'; - await page.goto(baseUrl + nodeEditUrl); + await page.getByRole('link', { name: 'Edit' }).click(); ckEditor = await page.locator('[aria-label="Editor editing area: main"]'); await ckEditor.fill(bodyText); // Timeouts necessary when running at full speed. @@ -162,13 +145,13 @@ test.describe('Node tests.', () => { // // Confirm content has changed. // - divContainer = await page.locator('.text-content'); + divContainer = await page.locator('.node__content'); const text = await divContainer.textContent(); await expect(text).toContain(bodyText); // // Delete the node. // - await atkCommands.deleteNodeViaUiWithNid(page, context, nid); + await atkCommands.deleteCurrentNodeViaUi(page); }); }); diff --git a/playwright/e2e/atk_entity/atk_taxonomy.spec.js b/playwright/e2e/atk_entity/atk_taxonomy.spec.js index 9828e5171e430e4021928667548c6a2da50c123f..f498e02d81d0dcd703522f12441c7268a5aea0a4 100644 --- a/playwright/e2e/atk_entity/atk_taxonomy.spec.js +++ b/playwright/e2e/atk_entity/atk_taxonomy.spec.js @@ -59,8 +59,7 @@ test.describe('Entity tests.', () => { // Fetch tag id from the list. The new term should be at // or near the top. // - await page.goto(`${baseUrl}admin/structure/taxonomy/manage/tags/overview`); - const termLocator = await page.getByText(termName); // eslint-disable-line no-unused-vars + await page.goto(`admin/structure/taxonomy/manage/tags/overview`); // Get the tid from the edit button. const link = await page.locator("//a[contains(text(),'Edit') and starts-with(@href, '/taxonomy/term')]").first(); diff --git a/playwright/support/atk_commands.js b/playwright/support/atk_commands.js index 523696f57761de4bffa4af515a528691d83f7b2d..4c10ee03c4f33b75ea5345c4e4467b2893a3d9fe 100644 --- a/playwright/support/atk_commands.js +++ b/playwright/support/atk_commands.js @@ -11,6 +11,7 @@ module.exports = { createUserWithUserObject, + deleteCurrentNodeViaUi, deleteNodeViaUiWithNid, deleteUserWithEmail, deleteUserWithUid, @@ -91,6 +92,16 @@ function createUserWithUserObject (user, roles = [], args = [], options = []) { }) } +/** + * Delete currently opened node. + * @param page {object} Page object. + * @returns {Promise<void>} + */ +async function deleteCurrentNodeViaUi(page) { + await page.getByRole('link', { name: 'Delete' }).click(); + await page.getByRole('button', { name: 'Delete' }).click(); +} + /** * Delete node via UI given a nid. *