From 6e6b94575af346cd831df3ffdb711cacac5e9851 Mon Sep 17 00:00:00 2001 From: juhi123 Date: Fri, 27 Dec 2024 14:33:38 +0530 Subject: [PATCH] Add Playwright E2E test to activate deactivate the plugin --- .../plugin/activate-deactivate-plugin.test.js | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tests/e2e/specs/plugin/activate-deactivate-plugin.test.js diff --git a/tests/e2e/specs/plugin/activate-deactivate-plugin.test.js b/tests/e2e/specs/plugin/activate-deactivate-plugin.test.js new file mode 100644 index 0000000000000..77dccf0f88bb8 --- /dev/null +++ b/tests/e2e/specs/plugin/activate-deactivate-plugin.test.js @@ -0,0 +1,49 @@ +/** + * WordPress dependencies + */ +import { test, expect } from '@wordpress/e2e-test-utils-playwright'; + +test.describe('Activate Deactivate Plugin', () => { + const pluginSlug = 'hello-dolly'; + const pluginRowSelector = `tr[data-slug="${pluginSlug}"]`; + + test.beforeEach(async ({ admin }) => { + await admin.visitAdminPage('plugins.php'); + }); + + test('activates the plugin', async ({ admin, page }) => { + const activateLink = page.locator(`${pluginRowSelector} .activate a`); + const deactivateLink = page.locator(`${pluginRowSelector} .deactivate a`); + + // Check if the plugin is already activated + if (await deactivateLink.isVisible()) { + console.log(`${pluginSlug} is already activated.`); + return; + } + + // Activate the plugin + await activateLink.click(); + + // Verify the plugin is activated + await expect(deactivateLink).toBeVisible(); + console.log(`${pluginSlug} has been activated successfully.`); + }); + + test('deactivates the plugin', async ({ admin, page }) => { + const activateLink = page.locator(`${pluginRowSelector} .activate a`); + const deactivateLink = page.locator(`${pluginRowSelector} .deactivate a`); + + // Check if the plugin is already deactivated + if (await activateLink.isVisible()) { + console.log(`${pluginSlug} is already deactivated.`); + return; + } + + // Deactivate the plugin + await deactivateLink.click(); + + // Verify the plugin is deactivated + await expect(activateLink).toBeVisible(); + console.log(`${pluginSlug} has been deactivated successfully.`); + }); +});