Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Playwright E2E test to add plugin and remove plugin #8075

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 134 additions & 0 deletions tests/e2e/specs/plugin/plugin.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/**
* WordPress dependencies
*/
import { test, expect } from '@wordpress/e2e-test-utils-playwright';

const oldPluginFilePath = './tests/e2e/test-data/akismet.5.3.4.zip';
const newPluginFilePath = './tests/e2e/test-data/akismet.5.3.5.zip';
const pluginSlug = 'akismet';
const pluginTitle ='Akismet Anti-spam: Spam Protection';

/**
* Uploads a plugin from a zip file.
*/
async function installPluginFromUpload( page, filePath, admin ) {
await admin.visitAdminPage( 'plugin-install.php' );

Check failure on line 15 in tests/e2e/specs/plugin/plugin.test.js

View workflow job for this annotation

GitHub Actions / Test with SCRIPT_DEBUG enabled / Run E2E tests

[chromium] › plugin/plugin.test.js:47:9 › Manage Plugins: Upload and Remove › uploads and installs an older version of the plugin

2) [chromium] › plugin/plugin.test.js:47:9 › Manage Plugins: Upload and Remove › uploads and installs an older version of the plugin Error: Not logged in 13 | */ 14 | async function installPluginFromUpload( page, filePath, admin ) { > 15 | await admin.visitAdminPage( 'plugin-install.php' ); | ^ 16 | await page.click( '.upload' ); 17 | const fileInput = await page.locator( '#pluginzip' ); 18 | await fileInput.setInputFiles( filePath ); at Admin.visitAdminPage (/home/runner/work/wordpress-develop/wordpress-develop/node_modules/@wordpress/e2e-test-utils-playwright/src/admin/visit-admin-page.ts:36:9) at installPluginFromUpload (/home/runner/work/wordpress-develop/wordpress-develop/tests/e2e/specs/plugin/plugin.test.js:15:2) at /home/runner/work/wordpress-develop/wordpress-develop/tests/e2e/specs/plugin/plugin.test.js:53:3
await page.click( '.upload' );
const fileInput = await page.locator( '#pluginzip' );
await fileInput.setInputFiles( filePath );

const installButton = page.locator( '#install-plugin-submit' );
const isDisabled = await installButton.isDisabled();
if ( ! isDisabled ) {
await installButton.click();
await page.waitForLoadState( 'networkidle' );
}
}

/**
* Checks the version of an installed plugin.
*/
async function checkPluginVersion( page, pluginSlug, admin ) {
await admin.visitAdminPage( 'plugins.php' ); // Update with your WordPress site URL
const pluginVersionElement = page.locator(
`tr[data-slug="${ pluginSlug }"] .inactive.second.plugin-version-author-uri`
);
const pluginVersionText = await pluginVersionElement.evaluate( ( el ) => {
const text = el.textContent;
// Extract the version number using a regex
const versionMatch = text.match( /Version\s([\d.]+)/ );
return versionMatch ? versionMatch[ 1 ] : null;
} );
return pluginVersionText;
}

test.describe( 'Manage Plugins: Upload and Remove', () => {

test( 'uploads and installs an older version of the plugin', async ( {
page,
admin,
} ) => {
const expectedVersion = '5.3';

await installPluginFromUpload( page, oldPluginFilePath, admin );
const activateButton = page.locator( '.button.button-primary' );
await expect( activateButton ).toHaveText( 'Activate Plugin' );

const actualVersion = await checkPluginVersion(
page,
pluginSlug,
admin
);
expect( actualVersion ).toContain( expectedVersion );

const updateNotice = page.locator(
`tr.plugin-update-tr[data-slug="${ pluginSlug }"] .update-message`
);
// Assert that the update notice is visible
await expect( updateNotice ).toBeVisible();

// Assert that the update notice contains the expected text
const expectedText =
`There is a new version of ${ pluginTitle } available.`;
await expect( updateNotice ).toHaveText(
new RegExp( expectedText, 'i' )
);

console.log(
'Update notice is visible and contains the expected text.'
);
} );

test( 'uploads and updates to a newer version of the plugin', async ( {
page,
admin,
} ) => {
const expectedVersion = '5.3.5';

await installPluginFromUpload( page, newPluginFilePath, admin );
const replaceButton = page.locator( '.button.button-primary' );
await expect( replaceButton ).toHaveText(
'Replace current with uploaded'
);
await replaceButton.click();

const activateButton = page.locator( '.button.button-primary' );
await expect( activateButton ).toHaveText( 'Activate Plugin' );

const actualVersion = await checkPluginVersion(
page,
pluginSlug,
admin
);
expect( actualVersion ).toContain( expectedVersion );
} );

test( 'removes the installed plugin successfully', async ( {
page,
admin,
} ) => {
await admin.visitAdminPage( 'plugins.php' );
const pluginRowSelector = `tr[data-slug="${ pluginSlug }"]`;
const deactivateLink = page.locator(
`${ pluginRowSelector } .deactivate a`
);
if ( await deactivateLink.isVisible() ) {
await deactivateLink.click();
await page.waitForLoadState( 'networkidle' );
}
page.on( 'dialog', async ( dialog ) => {
console.log('Dialog message:', dialog.message());
await dialog.accept();
} );

const deleteLink = page.locator( `${ pluginRowSelector } .delete a` );
await deleteLink.click();

const deletionMessage = page.locator( 'tr.plugin-deleted-tr' );

// Verify the content of the deletion message
await expect( deletionMessage ).toContainText(
'was successfully deleted'
);
} );
} );
Binary file added tests/e2e/test-data/akismet.5.3.4.zip
Binary file not shown.
Binary file added tests/e2e/test-data/akismet.5.3.5.zip
Binary file not shown.
Loading