Skip to content
Merged
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Projects that use the library without the test runner replace `playwright` the s
- [Performance](docs/performance.md): optimisations, defaults, opt-in settings and implementation details.
- [Quality-of-life features](docs/features.md): videos, diagnostics, snapshots, project servers and migration tools.
- [Configuration](docs/configuration.md): options, examples and limitations.
- [Integrations](docs/integrations.md): examples for running Flashwright with third-party tools.
- [Agent workflows](docs/agents.md): reporters, JSON summaries, watch mode, warm sessions and MCP.
- [Videos and demos](docs/videos.md): recording, narration and voices.
- [Migration](docs/migration.md): behaviour differences, deprecated APIs, codemod and Bun.
Expand Down
5 changes: 5 additions & 0 deletions docs/integrations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Integrations

## Cloud browser grids

- [Run Flashwright on the TestMu AI cloud grid](../examples/testmu-ai/README.md). The example runs the same tests in local Chromium and in Chrome on the grid.
35 changes: 35 additions & 0 deletions examples/testmu-ai/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Flashwright on the TestMu AI cloud grid

Three TodoMVC tests that run on a local Chromium or on the [TestMu AI](https://www.testmuai.com/playwright-testing/) (formerly LambdaTest) browser cloud, without changing the tests. The grid project uses Playwright's `connectOptions`, so the browser runs on the grid and Flashwright runs on your machine or CI.

## Run locally

```bash
npm install
npx playwright install chromium
npm test
```

## Run on the grid

Set your TestMu AI username and access key, from the account's profile page:

```bash
export LT_USERNAME=<username>
export LT_ACCESS_KEY=<access key>
npm run test:testmu
```

The run shows up as a build named `Flashwright example` in the automation dashboard, with video, network and console logs. Set `LT_BUILD_NAME` to rename it.

## How it works

- `playwright.config.ts` has two projects. `chromium` launches a local browser. `testmu-chrome` builds a capabilities object (browser, version, platform, credentials) and passes it to the grid in the `wsEndpoint` of `connectOptions`.
- Each worker connects once and runs its tests in that grid session. The three tests are in one file and run in one worker by default. To run them in parallel, use `npm run test:testmu -- --fully-parallel --workers=3` if your TestMu AI plan allows three concurrent sessions. `--workers` caps concurrency, and `--fully-parallel` lets tests in the same file run in separate workers.
- `tests/fixtures.ts` tells the grid whether the session passed. A worker's tests share a session, so one failed test marks it failed. If the status update fails, the fixture prints a warning and preserves the Playwright test result.

## What changes on a grid

The grid runs stock Playwright's server and chooses it by the `playwrightClientVersion` capability. The config sends Flashwright's upstream version (`1.64.1`, without the `-flashwright.N` suffix). Without that capability the grid cannot match the fork's version string and refuses the connection with a 500.

Flashwright does not recycle browser contexts in a browser it connects to, because that needs its own server. Every test gets a new context, as with `isolation: 'strict'`. The rest of what Flashwright changes in the test runner and the client still applies.
13 changes: 13 additions & 0 deletions examples/testmu-ai/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "testmu-ai-example",
"version": "0.0.1",
"private": true,
"scripts": {
"test": "playwright test --project=chromium",
"test:testmu": "playwright test --project=testmu-chrome"
},
"license": "Apache-2.0",
"devDependencies": {
"@playwright/test": "npm:flashwright-test@^1.64.1-flashwright.12"
}
}
49 changes: 49 additions & 0 deletions examples/testmu-ai/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { defineConfig, devices } from '@playwright/test';
import { version } from '@playwright/test/package.json';

/**
* Runs the same tests on a local Chromium or on the TestMu AI cloud grid.
* See https://www.testmuai.com/support/docs/playwright-testing/ for every capability.
*/
const capabilities = {
browserName: 'Chrome',
browserVersion: 'latest',
'LT:Options': {
platform: 'Windows 11',
build: process.env.LT_BUILD_NAME || 'Flashwright example',
name: 'TodoMVC',
user: process.env.LT_USERNAME,
accessKey: process.env.LT_ACCESS_KEY,
/* The grid picks its Playwright server from this. It needs the upstream version,
so drop the `-flashwright.N` suffix. */
playwrightClientVersion: version.split('-')[0],
network: true,
video: true,
console: true,
},
};

export default defineConfig({
testDir: './tests',
timeout: 30_000,
forbidOnly: !!process.env.CI,
reporter: 'list',

projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},

{
/* Each worker uses one grid session. Keep the worker limit within your plan's
concurrent session limit when running tests in parallel. */
name: 'testmu-chrome',
use: {
connectOptions: {
wsEndpoint: `wss://cdp.lambdatest.com/playwright?capabilities=${encodeURIComponent(JSON.stringify(capabilities))}`,
},
},
},
],
});
26 changes: 26 additions & 0 deletions examples/testmu-ai/tests/fixtures.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { test as base, expect } from '@playwright/test';

// A worker's tests share one grid session, so the session is marked failed once any of them fails.
let sessionFailed = false;

export const test = base.extend<{ reportToTestMu: void }>({
reportToTestMu: [async ({ page }, use, testInfo) => {
await use();
if (testInfo.project.name !== 'testmu-chrome')
return;
sessionFailed ||= testInfo.status !== testInfo.expectedStatus;
const action = {
action: 'setTestStatus',
arguments: {
status: sessionFailed ? 'failed' : 'passed',
remark: sessionFailed ? `${testInfo.title}: ${testInfo.error?.message ?? testInfo.status}` : '',
},
};
// The grid reads this message from the connection; the page does not run it.
await page.evaluate(() => {}, `lambdatest_action: ${JSON.stringify(action)}`).catch(() => {
console.warn(`Could not update the TestMu AI session status after "${testInfo.title}".`);
});
}, { auto: true }],
});

export { expect };
34 changes: 34 additions & 0 deletions examples/testmu-ai/tests/todomvc.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { test, expect } from './fixtures';

test.beforeEach(async ({ page }) => {
await page.goto('https://demo.playwright.dev/todomvc');
});

test('adds todo items', async ({ page }) => {
const newTodo = page.getByRole('textbox', { name: 'What needs to be done?' });
await newTodo.fill('Buy milk');
await newTodo.press('Enter');
await newTodo.fill('Walk the dog');
await newTodo.press('Enter');

await expect(page.getByRole('listitem').filter({ hasText: 'Buy milk' })).toBeVisible();
await expect(page.getByRole('listitem').filter({ hasText: 'Walk the dog' })).toBeVisible();
await expect(page.getByText('2 items left')).toBeVisible();
});

test('completes a todo item', async ({ page }) => {
const newTodo = page.getByRole('textbox', { name: 'What needs to be done?' });
await newTodo.fill('Buy milk');
await newTodo.press('Enter');

const toggle = page.getByRole('listitem').filter({ hasText: 'Buy milk' }).getByRole('checkbox');
await toggle.check();

await expect(toggle).toBeChecked();
await expect(page.getByText('0 items left')).toBeVisible();
});

test('starts every test with an empty list', async ({ page }) => {
await expect(page.getByRole('textbox', { name: 'What needs to be done?' })).toBeVisible();
await expect(page.getByText('items left')).toHaveCount(0);
});
Loading