@dynatrace/rum-javascript-sdk-playwright
v1.343.7
Published
Playwright testing framework for Dynatrace Real User Monitoring (RUM)
Readme
@dynatrace/rum-javascript-sdk-playwright
Playwright testing framework for Dynatrace Real User Monitoring (RUM).
This package provides Playwright fixtures and utilities for testing your application's RUM integration in end-to-end tests.
Migration from @dynatrace/rum-javascript-sdk/test
This package was extracted from the @dynatrace/rum-javascript-sdk package. If you were previously using the /test export, follow these steps:
1. Install the new package
npm install --save-dev @dynatrace/rum-javascript-sdk-playwright2. Update your imports
// Before
import { test } from "@dynatrace/rum-javascript-sdk/test";
// After
import { test } from "@dynatrace/rum-javascript-sdk-playwright";All APIs remain the same — only the import path changes.
Setup Instructions
1. Create an Access Token
- Navigate to the Access Tokens app in Dynatrace.
- Create a new token with the following permission:
- Permission:
Read RUM manual insertion tags - Scope:
API V2
- Permission:
- Copy the generated token for use in the next steps.
2. Provide Required Parameters
To use the framework, you need to provide the following details:
- Environment URL: The URL of the Dynatrace API endpoint to connect to, see RUM manual insertion tags API for details.
- Application ID: The application ID to identify the correct RUM JavaScript to fetch.
- Token: The API token created in Step 1.
import { test } from "@dynatrace/rum-javascript-sdk-playwright";
test.describe("my suite", () => {
test.use({
dynatraceConfig: {
appId: process.env.DT_APP_ID!,
token: process.env.DT_TOKEN!,
endpointUrl: process.env.DT_ENDPOINT_URL!
}
});
test("expect specific event", async ({ page, dynatraceTesting }) => {
await page.goto("http://127.0.0.1:3000/ui");
await page.getByText("Explore data").first().click();
await dynatraceTesting.expectToHaveSentEvent(
expect.objectContaining({
"event_properties.component_rendered": "Data"
})
);
});
});API Reference
See docs/testing.md for the full API reference including:
test— Playwright test fixture withdynatraceTestinganddynatraceConfigwaitForBeacons()— Wait for beacon requestsexpectToHaveSentEvent()— Assert specific events were sentexpectToHaveSentEventTimes()— Assert events were sent N timesclearEvents()— Clear captured eventstoMatchEventSnapshot()— Snapshot testing for RUM events
Exports
| Export | Description |
|--------|-------------|
| test | Playwright test fixture with Dynatrace testing utilities |
| DEFAULT_IGNORED_EVENTS | Default event patterns filtered from snapshots |
| DEFAULT_IGNORED_FIELDS | Default fields with values replaced in snapshots |
| DEFAULT_REMOVED_FIELDS | Default fields removed from snapshots |
| IGNORED_PLACEHOLDER | Placeholder string used for ignored field values |
Types
| Type | Description |
|------|-------------|
| DynatraceConfig | Configuration for Dynatrace connection |
| DynatraceTesting | Testing fixture API interface |
| DynatraceTestingFixture | Playwright fixture type |
| DynatraceTestingWorkerFixture | Playwright worker fixture type |
| BeaconRequest | Beacon request data structure |
| WaitForBeaconsOptions | Options for waitForBeacons() |
| ExpectOptions | Options for expect methods |
| SnapshotOptions | Options for toMatchEventSnapshot() |
| EventIgnorePattern | Pattern for filtering events |
