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

E2E Tests: Adding helpers to install/activate/deactivate and remove plugins #5906

Merged
merged 3 commits into from
Apr 3, 2018
Merged
Changes from 2 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
39 changes: 39 additions & 0 deletions test/e2e/support/plugins.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Node dependencies
*/
import { visitAdmin } from './utils';

export async function installPlugin( name, searchTerm ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would be the purpose of the second argument here? Not clear by the included documentation 😉

await visitAdmin( 'plugin-install.php?s=' + encodeURIComponent( searchTerm || name ) + '&tab=search&type=term' );
await page.click( '.install-now[data-slug="' + name + '"]' );
await page.waitForSelector( '.activate-now[data-slug="' + name + '"]' );
}

export async function activatePlugin( name ) {
await visitAdmin( 'plugins.php' );
await page.click( 'tr[data-slug="' + name + '"] .activate a' );
await page.waitForSelector( 'tr[data-slug="' + name + '"] .deactivate a' );
}

export async function deactivatePlugin( name ) {
await visitAdmin( 'plugins.php' );
await page.click( 'tr[data-slug="' + name + '"] .deactivate a' );
await page.waitForSelector( 'tr[data-slug="' + name + '"] .delete a' );
}

export async function uninstallPlugin( name ) {
await visitAdmin( 'plugins.php' );
const confirmPromise = new Promise( resolve => {
const confirmDialog = ( dialog ) => {
dialog.accept();
page.removeListener( 'dialog', confirmDialog );
resolve();
};
page.on( 'dialog', confirmDialog );
} );
await Promise.all( [
page.click( 'tr[data-slug="' + name + '"] .delete a' ),
confirmPromise,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it'll suffer the same race conditions as waitForNavigation, but in that case, the suggested workaround has the "waiting" (event handler binding) arranged to take place before the click itself: https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#pageclickselector-options

] );
await page.waitForSelector( 'tr[data-slug="' + name + '"].deleted' );
}