Skip to content

Commit

Permalink
Create example visreg test using Playground
Browse files Browse the repository at this point in the history
  • Loading branch information
WunderBart committed Jun 21, 2024
1 parent bb73da7 commit 3c2989a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@
"test:e2e:playwright:debug": "npm run test:e2e:debug",
"test:e2e:storybook": "playwright test --config test/storybook-playwright/playwright.config.ts",
"test:e2e:watch": "npm run test:e2e -- --watch",
"test:visreg": "npx playwright test test/visreg/example.spec.js",
"test:native": "cross-env NODE_ENV=test jest --config test/native/jest.config.js",
"test:native:watch": "npm run test:native -- --watch",
"test:native:clean": "jest --clearCache --config test/native/jest.config.js; rm -rf $TMPDIR/jest_*",
Expand Down
37 changes: 37 additions & 0 deletions test/visreg/example.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* External dependencies
*/
import { test, expect } from '@playwright/test';

test( 'WP Editor default view', async ( { context, page } ) => {
// 1. Go to the Gutenberg PR Preview page and submit the PR number.
await page.goto( 'https://playground.wordpress.net/gutenberg.html' );

const prInput = page.getByLabel( 'Pull request number or URL:' );

await prInput.fill( process.env.PR_NUMBER );
await prInput.press( 'Enter' );

// 2. Get the URL of the iframed WordPress instance so we can strip the
// Playground UI off.
await page.waitForFunction( 'window?.playground?.absoluteUrl' );
const wpIframeURL = await page.evaluate(
async () => await window.playground.absoluteUrl
);

// 3. Open WordPress in a new page in the same context. We need to keep the
// original page open so the Playground instance is not destroyed.
const wpPage = await context.newPage();

await wpPage.goto( wpIframeURL + '/wp-admin/post-new.php' );
await wpPage.getByLabel( 'Close', { exact: true } ).click();

// 4. Add an extra wait for the UI to stabilize.
await wpPage.waitForTimeout( 5_000 );

// 5. Here, some UI manipulation can be done. For example:
await wpPage.keyboard.type( 'Hello, World!' );

// 6. Compare the screenshot of the full page.
await expect( wpPage ).toHaveScreenshot( { fullPage: true } );
} );
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3c2989a

Please sign in to comment.