How to use the @wordpress/e2e-test-utils.switchUserToAdmin function in @wordpress/e2e-test-utils

To help you get started, we’ve selected a few @wordpress/e2e-test-utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github getblocklab / block-lab / tests / e2e / config / setup-test-framework.js View on Github external
export async function trashExistingPosts( postType = 'post' ) {
	await switchUserToAdmin();
	// Visit `/wp-admin/edit.php` so we can see a list of posts and delete them.
	const query = addQueryArgs( '', {
		post_type: postType,
	} ).slice( 1 );
	await visitAdminPage( 'edit.php', query );

	// If this selector doesn't exist there are no posts for us to delete.
	const bulkSelector = await page.$( '#bulk-action-selector-top' );
	if ( ! bulkSelector ) {
		return;
	}

	// Select all posts.
	await page.waitForSelector( '[id^=cb-select-all-]' );
	await page.click( '[id^=cb-select-all-]' );
	// Select the "bulk actions" > "trash" option.
github google / site-kit-wp / tests / e2e / utils / deactivate-all-other-plugins.js View on Github external
export async function deactivateAllOtherPlugins() {
	await switchUserToAdmin();

	if ( ! isCurrentURL( 'wp-admin/plugins.php' ) ) {
		await visitAdminPage( 'plugins.php' );
	}

	await page.waitForSelector( 'input[type="checkbox"][value="google-site-kit/google-site-kit.php"]' );
	const activePlugins = await page.$$eval( '.active[data-plugin]', ( rows ) => {
		return rows.map( ( row ) => row.dataset.plugin );
	} );

	// Bail if there are no plugins to deactivate
	if ( 1 === activePlugins.length && 'google-site-kit/google-site-kit.php' === activePlugins[ 0 ] ) {
		return;
	}

	// Select all plugins
github WordPress / gutenberg / packages / e2e-tests / config / setup-test-framework.js View on Github external
async function trashExistingPosts() {
	await switchUserToAdmin();
	// Visit `/wp-admin/edit.php` so we can see a list of posts and delete them.
	await visitAdminPage( 'edit.php' );

	// If this selector doesn't exist there are no posts for us to delete.
	const bulkSelector = await page.$( '#bulk-action-selector-top' );
	if ( ! bulkSelector ) {
		return;
	}

	// Select all posts.
	await page.waitForSelector( '#cb-select-all-1' );
	await page.click( '#cb-select-all-1' );
	// Select the "bulk actions" > "trash" option.
	await page.select( '#bulk-action-selector-top', 'trash' );
	// Submit the form to send all draft/scheduled/published posts to the trash.
	await page.click( '#doaction' );
github Automattic / Edit-Flow / tests / e2e / config / setup-test-framework.js View on Github external
async function trashExistingPosts() {
	await switchUserToAdmin();
	// Visit `/wp-admin/edit.php` so we can see a list of posts and delete them.
	await visitAdminPage( 'edit.php' );

	// If this selector doesn't exist there are no posts for us to delete.
  const bulkSelector = await page.$( '#bulk-action-selector-top' );

	if ( ! bulkSelector ) {
		return;
	}

	// Select all posts.
	await page.waitForSelector( '#cb-select-all-1' );
	await page.click( '#cb-select-all-1' );
	// Select the "bulk actions" > "trash" option.
	await page.select( '#bulk-action-selector-top', 'trash' );
	// Submit the form to send all draft/scheduled/published posts to the trash.
github ampproject / amp-wp / tests / e2e / utils / delete-theme.js View on Github external
export async function deleteTheme( slug, newThemeSlug, newThemeSearchTerm ) {
	await switchUserToAdmin();

	if ( newThemeSlug ) {
		await installTheme( newThemeSlug, newThemeSearchTerm );
		await activateTheme( newThemeSlug );
	} else {
		await visitAdminPage( 'themes.php' );
	}

	if ( ! await themeInstalled( slug ) ) {
		await switchUserToTest();
		return;
	}

	await page.click( `[data-slug="${ slug }"]` );
	await page.waitForSelector( '.theme-actions .delete-theme' );
	await page.click( '.theme-actions .delete-theme' );