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

Playwright #1153

Merged
merged 38 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
6c6f66e
Initialise playwright
microbit-grace Mar 13, 2024
e4a67b0
Downgrade to @playwright/test v1.30.0
microbit-grace Mar 13, 2024
3b1e7f4
Configure Playwright
microbit-grace Mar 13, 2024
dadd592
Upgrade playwright/test to v1.32.0
microbit-grace Mar 13, 2024
0f212a5
Add settings.spec.ts
microbit-grace Mar 13, 2024
be55bc4
Add reset.spec.ts
microbit-grace Mar 13, 2024
09f20ab
Add more test files WIP
microbit-grace Mar 14, 2024
cdd14bf
Add rest of playwright tests
microbit-grace Mar 15, 2024
c7a9bc0
Add accessibility.spec.ts
microbit-grace Mar 15, 2024
3c61a54
Rename *.spec.ts -> *.test.ts
microbit-grace Mar 15, 2024
83f8bf6
Remove playwright test match for *.spec.ts
microbit-grace Mar 15, 2024
bf32765
Update README.md
microbit-grace Mar 15, 2024
db74dbc
Add navigation to app into fixture
microbit-grace Mar 15, 2024
9a58c4e
Update package-lock.json
microbit-grace Mar 15, 2024
abc1a3e
Remove test examples from playwright init
microbit-grace Mar 15, 2024
9d15e4d
Refactoring (renaming and tidying) WIP
microbit-grace Mar 15, 2024
a6c75dd
Update package-lock.json
microbit-grace Mar 18, 2024
627a0e0
Replace app.ts with app-playwright.ts
microbit-grace Mar 18, 2024
499e1b2
Use `npm run serve` to serve editor
microbit-grace Mar 18, 2024
cadbe54
Configure webServer for CI
microbit-grace Mar 18, 2024
373dd28
Upgrade playwright to 1.33
microbit-grace Mar 19, 2024
32519c5
Refactoring
microbit-grace Mar 19, 2024
1cb5d93
Make playwright versions the same in package.json
microbit-grace Mar 19, 2024
d560992
Update build.yml
microbit-grace Mar 19, 2024
b86d830
Fix build.yml
microbit-grace Mar 19, 2024
731fe3e
Rerun CI
microbit-grace Mar 19, 2024
6a98602
Upgrade to playwright@latest
microbit-grace Mar 19, 2024
918d530
Upgrade to v1.42.1-jammy
microbit-grace Mar 19, 2024
be59f1d
Tweak tests to be less flaky
microbit-grace Mar 19, 2024
89c6abb
Add timeout minutes to build time
microbit-grace Mar 19, 2024
c580a85
Remove puppeteer and pptr-testing-library
microbit-grace Mar 19, 2024
179e918
Rename last `findXXX` to `expectXXX`
microbit-grace Mar 19, 2024
8c5684f
Use playwright instead of vitest for E2E
microbit-grace Mar 19, 2024
d6ea1ee
Remove playwright from package.json
microbit-grace Mar 19, 2024
55117e1
Refactor getSimulatorIframe
microbit-grace Mar 19, 2024
2339e62
Refactor typeInEditor
microbit-grace Mar 19, 2024
8962bb4
Tweak typeInEditor comment
microbit-grace Mar 19, 2024
4a7c055
Add playwright to dev
microbit-grace Mar 19, 2024
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ __pycache__
*.pyc
/reports/*
/crowdin/*
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ These are excluded from the normal test run.

The tests expect the app to already be running on http://localhost:3000, for example via `npm start`.

We use [Puppeteer](https://pptr.dev/) and the helpers provided by [Testing Library](https://testing-library.com/docs/pptr-testing-library/intro/).
We use [Playwright](https://playwright.dev/).

The CI tests run these end-to-end tests against a production build.

Expand Down
88 changes: 88 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"lzma": "^2.3.2",
"marked": "^4.0.15",
"mobile-drag-drop": "^2.3.0-rc.2",
"playwright": "^1.42.1",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-icons": "^4.8.0",
Expand All @@ -59,6 +60,7 @@
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
"@chakra-ui/cli": "^2.4.1",
"@formatjs/cli": "^6.2.7",
"@playwright/test": "1.33.0",
microbit-matt-hillsdon marked this conversation as resolved.
Show resolved Hide resolved
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "^14.0.0",
Expand Down Expand Up @@ -99,7 +101,7 @@
"serve": "npx serve --no-clipboard -l 3000 -- build/",
"start": "vite dev",
"test:e2e:headless": "cross-env E2E_HEADLESS=1 vitest --mode e2e",
microbit-matt-hillsdon marked this conversation as resolved.
Show resolved Hide resolved
"test:e2e": "cross-env E2E_HEADLESS=0 vitest --mode e2e",
"test:e2e": "npx playwright test --ui",
"test": "vitest",
"theme:watch": "chakra-cli tokens src/deployment/default/theme.ts --watch",
"theme": "chakra-cli tokens src/deployment/default/theme.ts",
Expand Down
38 changes: 38 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { defineConfig, devices } from "@playwright/test";

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: "./src/e2e",
fullyParallel: true,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
workers: process.env.CI ? 1 : undefined,
reporter: "html",
use: {
trace: "on-first-retry",
},

/* Configure projects for major browsers */
projects: [
{
name: "chromium",
use: { ...devices["Desktop Chrome"] },
},
],

/* Run your local dev server before starting the tests */
webServer: {
...(process.env.CI
? {
command: `npx vite preview --port 3000 --base ${process.env.BASE_URL}`,
url: `http://localhost:3000${process.env.BASE_URL}`,
}
: {
command: "npm run start",
url: "http://localhost:3000",
}),
reuseExistingServer: !process.env.CI,
},
});
40 changes: 20 additions & 20 deletions src/e2e/accessibility.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,36 @@
* (c) 2022, Micro:bit Educational Foundation and contributors
*
* SPDX-License-Identifier: MIT
*/

Check failure on line 5 in src/e2e/accessibility.test.ts

View workflow job for this annotation

GitHub Actions / build

src/e2e/accessibility.test.ts

Error: Playwright Test did not expect test.describe() to be called here. Most common reasons include: - You are calling test.describe() in a configuration file. - You are calling test.describe() in a file that is imported by the configuration file. - You have two different versions of @playwright/test. This usually happens when one of the dependencies in your package.json depends on @playwright/test. ❯ TestTypeImpl._currentSuite node_modules/@playwright/test/lib/common/testType.js:69:13 ❯ TestTypeImpl._describe node_modules/@playwright/test/lib/common/testType.js:87:24 ❯ Function.describe node_modules/@playwright/test/lib/common/transform.js:217:12 ❯ src/e2e/accessibility.test.ts:5:28
import { App } from "./app";
import { test } from "./app-test-fixtures.js";
import { expect } from "@playwright/test";

describe("accessibility", () => {
const app = new App();
beforeEach(app.reset.bind(app));
afterEach(app.screenshot.bind(app));
afterAll(app.dispose.bind(app));

it("focuses the correct element on tabbing after load", async () => {
await app.assertFocusOnLoad();
test.describe("accessibility", () => {
test("focuses the correct element on tabbing after load", async ({ app }) => {
await app.expectFocusOnLoad();
});

it("focuses the correct elements on collapsing and expanding the simulator", async () => {
await app.collapseSimulator();
await app.assertFocusOnExpandSimulator();
test("focuses the correct elements on collapsing and expanding the simulator", async ({
app,
}) => {
await app.simulator.collapseButton.click();
await expect(app.simulator.expandButton).toBeFocused();

await app.expandSimulator();
await app.assertFocusOnSimulator();
await app.simulator.expandButton.click();
await expect(app.simulator.iframe).toBeFocused();
});

it("focuses the correct elements on collapsing and expanding the sidebar", async () => {
await app.collapseSidebar();
await app.assertFocusOnExpandSidebar();

await app.expandSidebar();
test("focuses the correct elements on collapsing and expanding the sidebar", async ({
app,
}) => {
await app.sidebar.expandButton.click();
await app.assertFocusOnSidebar();

await app.sidebar.collapseButton.click();
await expect(app.sidebar.expandButton).toBeFocused();
});

it("allows tab out of editor", async () => {
test("allows tab out of editor", async ({ app }) => {
await app.tabOutOfEditorForwards();
await app.assertFocusAfterEditor();

Expand Down
35 changes: 35 additions & 0 deletions src/e2e/app-test-fixtures.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { test as base } from "@playwright/test";
import { App } from "./app.js";

type MyFixtures = {
app: App;
};

export const test = base.extend<MyFixtures>({
app: async ({ page, context }, use) => {
const app = new App(page, context);
await context.grantPermissions(["clipboard-read", "clipboard-write"]);
await context.addCookies([
{
// See corresponding code in App.tsx.
name: "mockDevice",
value: "1",
url: app.baseUrl,
},
// Don't show compliance notice for Foundation builds
{
name: "MBCC",
value: encodeURIComponent(
JSON.stringify({
version: 1,
analytics: false,
functional: true,
})
),
url: app.baseUrl,
},
]);
await app.goto();
await use(app);
},
});
Loading
Loading