Skip to content
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
39 changes: 31 additions & 8 deletions packages/e2e-test-utils-playwright/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,7 @@ npm install @wordpress/e2e-test-utils-playwright --save-dev

## API

### test

The extended Playwright's [test](https://playwright.dev/docs/api/class-test) module with the `admin`, `editor`, `pageUtils` and the `requestUtils` fixtures.

### expect

The Playwright/Jest's [expect](https://jestjs.io/docs/expect) function.
<!-- START TOKEN(Autogenerated API docs) -->

### Admin

Expand All @@ -37,6 +31,10 @@ const admin = new Admin( { page, pageUtils } );
await admin.visitAdminPage( 'options-general.php' );
```

_Type_

- `Admin`

### Editor

End to end test utilities for the WordPress Block Editor.
Expand All @@ -57,10 +55,28 @@ Within a test or test utility, use the `canvas` property to select elements with
await editor.canvas.locator( 'role=document[name="Paragraph block"i]' );
```

_Type_

- `Editor`

### expect

The Playwright/Jest's [expect](https://jestjs.io/docs/expect) function.

### Lighthouse

Undocumented declaration.

### Metrics

Undocumented declaration.

### PageUtils

Generic Playwright utilities for interacting with web pages.

_Usage_

```js
const pageUtils = new PageUtils( { page } );
await pageUtils.pressKeys( 'primary+a' );
Expand All @@ -70,9 +86,10 @@ await pageUtils.pressKeys( 'primary+a' );

Playwright utilities for interacting with the WordPress REST API.

Create a request utils instance.
_Usage_

```js
// Create a request utils instance.
const requestUtils = await RequestUtils.setup( {
user: {
username: 'admin',
Expand All @@ -81,6 +98,12 @@ const requestUtils = await RequestUtils.setup( {
} );
```

### test

The extended Playwright's [test](https://playwright.dev/docs/api/class-test) module with the `admin`, `editor`, `pageUtils`, `snapshotConfig`, `metrics`, `lighthouse` and the `requestUtils` fixtures.

<!-- END TOKEN(Autogenerated API docs) -->

## Contributing to this package

This is an individual package that's part of the Gutenberg project. The project is organized as a monorepo. It's made up of multiple self-contained software packages, each with a specific purpose. The packages in this monorepo are published to [npm](https://www.npmjs.com/) and used by [WordPress](https://make.wordpress.org/core/) as well as other software projects.
Expand Down
8 changes: 8 additions & 0 deletions packages/e2e-test-utils-playwright/src/admin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ type AdminConstructorProps = {
editor: Editor;
};

/**
* End to end test utilities for WordPress admin's user interface.
*
* ```js
* const admin = new Admin( { page, pageUtils } );
* await admin.visitAdminPage( 'options-general.php' );
* ```
*/
export class Admin {
page: Page;
context: BrowserContext;
Expand Down
20 changes: 20 additions & 0 deletions packages/e2e-test-utils-playwright/src/editor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,26 @@ type EditorConstructorProps = {
page: Page;
};

/**
* End to end test utilities for the WordPress Block Editor.
*
* To use these utilities, instantiate them within each test file:
*
* ```js
* test.use( {
* editor: async ( { page }, use ) => {
* await use( new Editor( { page } ) );
* },
* } );
* ```
*
* Within a test or test utility, use the `canvas` property to select elements within the iframe canvas:
*
* ```js
* await editor.canvas.locator( 'role=document[name="Paragraph block"i]' );
* ```
*
*/
export class Editor {
browser: Browser;
page: Page;
Expand Down
9 changes: 9 additions & 0 deletions packages/e2e-test-utils-playwright/src/page-utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ type PageUtilConstructorParams = {
browserName: PlaywrightWorkerOptions[ 'browserName' ];
};

/**
* Generic Playwright utilities for interacting with web pages.
*
* @example
* ```js
* const pageUtils = new PageUtils( { page } );
* await pageUtils.pressKeys( 'primary+a' );
* ```
*/
class PageUtils {
browser: Browser;
page: Page;
Expand Down
14 changes: 14 additions & 0 deletions packages/e2e-test-utils-playwright/src/request-utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ interface StorageState {
rootURL: string;
}

/**
* Playwright utilities for interacting with the WordPress REST API.
* @example
* ```js
* // Create a request utils instance.
* const requestUtils = await RequestUtils.setup( {
* user: {
* username: 'admin',
* password: 'password',
* },
* } );
* ```
*
*/
class RequestUtils {
request: APIRequestContext;
user: User;
Expand Down
17 changes: 16 additions & 1 deletion packages/e2e-test-utils-playwright/src/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* External dependencies
*/
import * as path from 'path';
import { test as base, expect, chromium } from '@playwright/test';
import { test as base, expect as baseExpect, chromium } from '@playwright/test';
import type { ConsoleMessage } from '@playwright/test';
import getPort from 'get-port';

Expand Down Expand Up @@ -121,6 +121,16 @@ function observeConsoleLogging( message: ConsoleMessage ) {
console[ logFunction ]( text );
}

/**
* The extended Playwright's [test](https://playwright.dev/docs/api/class-test) module with the
* `admin`,
* `editor`,
* `pageUtils`,
* `snapshotConfig`,
* `metrics`,
* `lighthouse`
* and the `requestUtils` fixtures.
*/
const test = base.extend<
{
admin: Admin;
Expand Down Expand Up @@ -199,4 +209,9 @@ const test = base.extend<
},
} );

/**
* The Playwright/Jest's [expect](https://jestjs.io/docs/expect) function.
*/
const expect = baseExpect;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is a pointless assignment in order to document the expect export. I'm open to better solutions!


export { test, expect };
Loading