This package provides shared E2E testing utilities for Polylang projects.
npm install --save-dev @wpsyntex/e2e-test-utils @playwright/test @wordpress/e2e-test-utils-playwrightPeer dependencies (required in consuming projects):
@playwright/test@wordpress/e2e-test-utils-playwright
When installing from the GitHub repository, the prepare script builds the package automatically. When installing from npm, the published tarball already includes the compiled build/ output.
When working on this package locally:
npm install --omit=peer
npm run build
npm install @playwright/test @wordpress/e2e-test-utils-playwright
npm run lint:js
node -e "require('@wpsyntex/e2e-test-utils')"Run npm run build after changing files in src/. The build/ directory is not committed; it is generated by prepare on install and by prepublishOnly before publishing.
Create a playwright.config.mjs file in your E2E test directory:
import { getPlaywrightConfig } from '@wpsyntex/e2e-test-utils';
export default getPlaywrightConfig( {
globalSetup: './global.setup.mjs',
globalTeardown: './global.teardown.mjs',
} );getPlaywrightConfig() merges your options with sensible defaults (Chromium, HTML reporter, wp-env web server, storage state path, etc.). The default globalSetup points to the packaged build/setup/global.setup.cjs when not overridden.
The getPlaywrightConfig function accepts an options object that can override any of the default configuration:
use: Override default Playwright use optionswebServer: Override default webServer configuration- Any other Playwright configuration options
The default configuration includes:
- Chrome browser setup
- HTML reporter
- CI-specific settings
- Default storage state path
- Local development server configuration
Retrieves a list of all configured languages in Polylang.
- Parameters:
requestUtils: Gutenberg request utils object
- Returns: Promise resolving to the list of languages
Retrieves a specific language by its slug.
- Parameters:
requestUtils: Gutenberg request utils objectslug: Language slug to retrieve
- Returns: Promise resolving to the language data
Creates a new language in Polylang.
- Parameters:
requestUtils: Gutenberg request utils objectlocale: Language locale to create (e.g., 'fr_FR')
- Returns: Promise resolving to the created language
Deletes a specific language by its slug.
- Parameters:
requestUtils: Gutenberg request utils objectslug: Language slug to delete
- Returns: Promise resolving to the deletion result
Deletes all configured languages except the default one.
- Parameters:
requestUtils: Gutenberg request utils object
- Returns: Promise resolving to the deletion results
Retrieves all Polylang plugin settings.
- Parameters:
requestUtils: Gutenberg request utils object
- Returns: Promise resolving to the settings object
Updates a specific plugin setting.
- Parameters:
requestUtils: Gutenberg request utils objectsettingKey: The key of the setting to updatesettingValue: The new value for the setting
- Returns: Promise resolving to the updated setting
Resets all plugin settings to their default values.
- Parameters:
requestUtils: Gutenberg request utils object
- Returns: Promise resolving to the reset operation result
- Note: Preserves the default language setting
Retrieves all terms for a specific taxonomy.
- Parameters:
requestUtils: Gutenberg request utils objecttaxonomy: Taxonomy slug
- Returns: Promise resolving to the list of terms
Retrieves a specific term by its slug within a taxonomy.
- Parameters:
requestUtils: Gutenberg request utils objecttaxonomy: Taxonomy slugslug: Term slug to retrieve
- Returns: Promise resolving to the term data
Deletes all terms within a specific taxonomy.
- Parameters:
requestUtils: Gutenberg request utils objecttaxonomy: Taxonomy slug
- Returns: Promise resolving to the deletion results
Fills in the XLIFF export form for bulk translation export.
- Parameters:
page: Playwright page objectoptions: Configuration objectpostId: Post ID to exportpostTitle: Post title to selectlanguageName: Target language name
- Returns: Promise that resolves when the export form is submitted
- Note: Page should be on the post list table
Returns a regex pattern to match XLIFF file names with the specified locales and timestamp.
- Parameters:
sourceLocale: Source language locale (e.g., 'en_US')targetLocale: Target language locale (e.g., 'fr_FR')
- Returns: RegExp object to match XLIFF file names
- Note: Converts underscores to hyphens in locales and matches timestamp pattern
Returns a download promise by clicking a submit button and waiting for the download to start.
- Parameters:
page: Playwright page objectsubmitButtonOptions: Submit button options (default:{ name: 'Submit' })
- Returns: Promise resolving to the download object
Reads a file and returns its contents as a string.
- Parameters:
filePath: The file path to read
- Returns: String content of the file
Global setup function for Playwright tests. Ensures fixtures are deleted and global context is set up properly.
Creates a translator user, based on the editor role.
- Parameters:
langSlugs: List of language slugs.userName: Optional. A user name. Defaults toXX-YY-translator, whereXXandYYare language slugs.
- Returns: Promise resolving to a user object containing ID, user name, and password.
Switches to the given user.
- Parameters:
user: The user to switch to (an object containing a user name and a password).admin: Instance ofAdmin.requestUtils: Gutenberg request utils object.
- Returns: Promise resolving to the
Pageobject.
import {
createLanguage,
setSetting,
getAllTerms
} from '@wpsyntex/e2e-test-utils';
// Create a new language
await createLanguage( requestUtils, 'fr_FR' );
// Update a setting
await setSetting( requestUtils, 'hide_default', true );
// Get all terms from a taxonomy
const terms = await getAllTerms( requestUtils, 'category' );All these functions are designed to work with the Gutenberg request utils object and follow REST API patterns for interacting with Polylang's functionality. They provide a comprehensive set of tools for managing languages, settings, and taxonomies in E2E tests.
The Publish to npm workflow reuses Static Analysis (build, lint, smoke test) before publishing.
Repository secret required: NPM_TOKEN (npm access token with publish rights for @wpsyntex).
Triggered when a GitHub release is published:
- Bump the version in
package.json. - Create a git tag matching the version (e.g.
v0.2.0). - Publish a GitHub release from that tag.
The workflow checks out the release tag and publishes that exact version to the latest dist-tag.
Triggered manually via workflow_dispatch. The workflow checks out the selected branch (usually master), appends -dev.<git-sha> to the version in package.json (e.g. 0.2.0-dev.a1b2c3d), and publishes to the next dist-tag without modifying git.
Install the bleeding edge build in a consumer project:
npm install --save-dev @wpsyntex/e2e-test-utils@nextStable installs (npm install @wpsyntex/e2e-test-utils) are unaffected.