@dynatrace/rum-javascript-sdk 1.331.18 → 1.333.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -390
- package/dist/testing/index.d.ts +4 -0
- package/dist/testing/index.js +3 -0
- package/dist/testing/snapshot.d.ts +129 -0
- package/dist/testing/snapshot.js +385 -0
- package/dist/testing/test.d.ts +9 -0
- package/dist/testing/test.js +237 -160
- package/dist/types/index-typedoc.d.ts +3 -0
- package/dist/types/index-typedoc.js +4 -1
- package/dist/types/rum-events/rum-event-keys.d.ts +9 -0
- package/dist/types/rum-events/rum-event-keys.js +11 -1
- package/dist/types/rum-events/rum-internal-selfmonitoring-event.d.ts +5 -1
- package/dist/types/rum-events/rum-internal-selfmonitoring-event.js +5 -1
- package/dist/types/rum-events/rum-web-request-event.d.ts +2 -1
- package/dist/types/rum-events/rum-web-request-event.js +2 -1
- package/dist/types/rum-events/shared-namespaces-and-fields/general-rum-event-fields.d.ts +1 -0
- package/dist/types/rum-events/shared-namespaces-and-fields/general-rum-event-fields.js +1 -1
- package/docs/1-overview.md +405 -0
- package/docs/2-testing.md +424 -0
- package/docs/{types.md → 3-types.md} +8 -2
- package/docs/{USERACTIONS.md → 4-useractions.md} +10 -8
- package/package.json +46 -9
- package/docs/testing.md +0 -215
package/docs/testing.md
DELETED
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
# Dynatrace RUM JavaScript Testing Framework for Playwright
|
|
2
|
-
|
|
3
|
-
This framework provides a Playwright fixture for testing observability by interacting with the Dynatrace Real User Monitoring (RUM) API.
|
|
4
|
-
|
|
5
|
-
## Setup Instructions
|
|
6
|
-
|
|
7
|
-
Follow these steps to configure and use the framework:
|
|
8
|
-
|
|
9
|
-
### 1. Create an Access Token
|
|
10
|
-
1. Navigate to the **Access Tokens** app in Dynatrace.
|
|
11
|
-
2. Create a new token with the following permission:
|
|
12
|
-
- **Permission**: `Read RUM manual insertion tags`
|
|
13
|
-
- **Scope**: `API V2`
|
|
14
|
-
3. Copy the generated token for use in the next steps.
|
|
15
|
-
|
|
16
|
-
### 2. Provide Required Parameters
|
|
17
|
-
To use the framework, you need to provide the following details:
|
|
18
|
-
- **Environment URL**: The URL of the Dynatrace API endpoint to connect to, see
|
|
19
|
-
[RUM manual insertion tags API](https://docs.dynatrace.com/docs/discover-dynatrace/references/dynatrace-api/environment-api/rum/rum-manual-insertion-tags)
|
|
20
|
-
for details. Example: _https://{your-environment-id}.live.dynatrace.com_ or
|
|
21
|
-
_https://{your-activegate-domain}/e/{your-environment-id}_
|
|
22
|
-
- **Application ID**: The application ID to identify the correct RUM JavaScript to fetch. You can find
|
|
23
|
-
this in the URL if you open the Experience Vitals app and select the frontend you
|
|
24
|
-
want to test. Example: APPLICATION-ABCDEF0123456789
|
|
25
|
-
- **Token**: The API token created in Step 1.
|
|
26
|
-
|
|
27
|
-
Populate your playwright config file with these fields or call `test.use` to provide them to a test suite, like so:
|
|
28
|
-
```ts
|
|
29
|
-
import { test } from "@dynatrace/rum-javascript-sdk/test";
|
|
30
|
-
|
|
31
|
-
test.describe("my suite", () => {
|
|
32
|
-
test.use({
|
|
33
|
-
dynatraceConfig: {
|
|
34
|
-
appId: process.env.DT_APP_ID!,
|
|
35
|
-
token: process.env.DT_TOKEN!,
|
|
36
|
-
endpointUrl: process.env.DT_ENDPOINT_URL!
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
### 3. Assert on events
|
|
43
|
-
|
|
44
|
-
Use the provided `expect` functions to assert on events the RUM JavaScript should have sent:
|
|
45
|
-
```ts
|
|
46
|
-
test("expect specific event", async ({ page, dynatraceTesting }) => {
|
|
47
|
-
await page.goto("http://127.0.0.1:3000/ui");
|
|
48
|
-
await page.getByText("Explore data").first().click();
|
|
49
|
-
await dynatraceTesting.expectToHaveSentEvent(expect.objectContaining({
|
|
50
|
-
"event_properties.component_rendered": "Data"
|
|
51
|
-
}));
|
|
52
|
-
});
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
## Important: Fixture Destructuring Order
|
|
56
|
-
|
|
57
|
-
⚠️ **The order of fixture destructuring matters!**
|
|
58
|
-
|
|
59
|
-
The `dynatraceTesting` fixture must be destructured **before** any custom fixtures that navigate the page. This ensures the RUM JavaScript is injected before navigation occurs.
|
|
60
|
-
|
|
61
|
-
### ✅ Correct Order
|
|
62
|
-
```typescript
|
|
63
|
-
test("my test", async ({ dynatraceTesting, myCustomFixture, page }) => {
|
|
64
|
-
// dynatraceTesting is initialized first
|
|
65
|
-
// RUM script is injected via page.addInitScript
|
|
66
|
-
// Then myCustomFixture can safely navigate
|
|
67
|
-
await page.goto("https://example.com");
|
|
68
|
-
});
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
### ❌ Incorrect Order
|
|
72
|
-
```typescript
|
|
73
|
-
test("my test", async ({ myCustomFixture, dynatraceTesting, page }) => {
|
|
74
|
-
// If myCustomFixture navigates the page, it happens BEFORE
|
|
75
|
-
// dynatraceTesting is initialized, so RUM script is not injected
|
|
76
|
-
// This will cause the test to fail with "no events received"
|
|
77
|
-
});
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
### Why This Happens
|
|
81
|
-
|
|
82
|
-
Playwright initializes fixtures in the order they appear in the destructuring pattern. The `dynatraceTesting` fixture uses `page.addInitScript()` to inject the RUM JavaScript, which only affects subsequent page navigations.
|
|
83
|
-
|
|
84
|
-
### Custom Fixtures That Navigate
|
|
85
|
-
|
|
86
|
-
If you have custom fixtures that call `page.goto()`, always destructure `dynatraceTesting` first:
|
|
87
|
-
|
|
88
|
-
```typescript
|
|
89
|
-
// Define custom fixture
|
|
90
|
-
const test = base.extend<{ myApp: MyApp }>({
|
|
91
|
-
myApp: async ({ page }, use) => {
|
|
92
|
-
await page.goto("https://myapp.com"); // Navigation happens here
|
|
93
|
-
await use(new MyApp(page));
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
// Use fixtures in correct order
|
|
98
|
-
test("test", async ({ dynatraceTesting, myApp }) => {
|
|
99
|
-
// ✅ Correct: dynatraceTesting initialized before myApp
|
|
100
|
-
});
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
## Troubleshooting
|
|
104
|
-
|
|
105
|
-
The test fixture works by intercepting network requests to the RUM ingestion endpoint and capturing
|
|
106
|
-
the events sent by the RUM JavaScript.
|
|
107
|
-
Note that this has an impact on your capturing environment, since these beacons report real data.
|
|
108
|
-
|
|
109
|
-
### Missing Configuration Error
|
|
110
|
-
|
|
111
|
-
If you see an error like:
|
|
112
|
-
```
|
|
113
|
-
[Dynatrace Testing] Missing required configuration fields: endpointUrl, appId, token
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
This means the required configuration was not provided. Make sure to configure the fixture using `test.use()`:
|
|
117
|
-
|
|
118
|
-
```typescript
|
|
119
|
-
test.use({
|
|
120
|
-
dynatraceConfig: {
|
|
121
|
-
endpointUrl: process.env.DT_ENDPOINT_URL!,
|
|
122
|
-
appId: process.env.DT_APP_ID!,
|
|
123
|
-
token: process.env.DT_TOKEN!
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
### No Events Received
|
|
129
|
-
|
|
130
|
-
If your tests fail with "Dynatrace didn't send any events":
|
|
131
|
-
|
|
132
|
-
1. **Check fixture ordering** - Ensure `dynatraceTesting` is destructured before any fixtures that navigate the page
|
|
133
|
-
2. **Check the page URL** - If you see a warning about the page already being navigated, fix the fixture order
|
|
134
|
-
|
|
135
|
-
### Event Dumping
|
|
136
|
-
|
|
137
|
-
When `dumpEventsOnFail` is enabled, the framework will output detailed information about received events when assertions fail:
|
|
138
|
-
|
|
139
|
-
```
|
|
140
|
-
[Dynatrace Testing] Event Dump (expectToHaveSentEvent - no match)
|
|
141
|
-
Total events received: 3
|
|
142
|
-
Total beacons received: 2
|
|
143
|
-
|
|
144
|
-
Received events:
|
|
145
|
-
|
|
146
|
-
Event 1: { "event_properties.custom_val": "load", ... }
|
|
147
|
-
Event 2: { "event_properties.custom_val": "user-action", ... }
|
|
148
|
-
Event 3: { "event_properties.custom_val": "custom", ... }
|
|
149
|
-
```
|
|
150
|
-
|
|
151
|
-
This helps identify why expected events weren't matched.
|
|
152
|
-
|
|
153
|
-
## Testing API
|
|
154
|
-
The `DynatraceTesting` interface provides utility methods for validating observability-related events and beacon
|
|
155
|
-
requests during tests.
|
|
156
|
-
|
|
157
|
-
---
|
|
158
|
-
|
|
159
|
-
## Methods
|
|
160
|
-
|
|
161
|
-
### `waitForBeacons(options?: { minCount?: number; timeout?: number }): Promise<BeaconRequest[]>`
|
|
162
|
-
|
|
163
|
-
Waits for a specified number of beacon requests or until a timeout occurs.
|
|
164
|
-
|
|
165
|
-
#### Parameters:
|
|
166
|
-
- `options` *(Optional)*:
|
|
167
|
-
- `minCount`: The minimum number of beacon requests to wait for.
|
|
168
|
-
- `timeout`: The maximum time to wait for beacon requests, in milliseconds. *(Default: 30,000)*
|
|
169
|
-
|
|
170
|
-
#### Returns:
|
|
171
|
-
A promise that resolves with an array of beacon requests.
|
|
172
|
-
|
|
173
|
-
---
|
|
174
|
-
|
|
175
|
-
### `expectToHaveSentEvent(event: Record<string, unknown>, options?: { timeout?: number }): Promise<void>`
|
|
176
|
-
|
|
177
|
-
Verifies that a specific event has been sent, optionally within a timeout period.
|
|
178
|
-
|
|
179
|
-
#### Parameters:
|
|
180
|
-
- `event`: The event to check, represented as a key-value pair object. This uses Playwright's `expect(event).toMatchObject`.
|
|
181
|
-
- `options` *(Optional)*:
|
|
182
|
-
- `timeout`: The maximum time to wait for the event to be sent, in milliseconds. *(Default: 30,000)*
|
|
183
|
-
|
|
184
|
-
#### Returns:
|
|
185
|
-
A promise that resolves when the event is confirmed to have been sent.
|
|
186
|
-
|
|
187
|
-
---
|
|
188
|
-
|
|
189
|
-
### `expectToHaveSentEventTimes(event: Record<string, unknown>, times: number, options?: { timeout?: number }): Promise<void>`
|
|
190
|
-
|
|
191
|
-
Verifies that a specific event has been sent a specified number of times, optionally within a timeout period.
|
|
192
|
-
|
|
193
|
-
#### Parameters:
|
|
194
|
-
- `event`: The event to check, represented as a key-value pair object. This uses Playwright's `expect(event).toMatchObject`.
|
|
195
|
-
- `times`: The exact number of times the event is expected to have been sent.
|
|
196
|
-
- `options` *(Optional)*:
|
|
197
|
-
- `timeout`: The maximum time to wait for the event to be sent, in milliseconds. *(Default: 30,000)*
|
|
198
|
-
|
|
199
|
-
#### Returns:
|
|
200
|
-
A promise that resolves when the event is confirmed to have been sent the specified number of times.
|
|
201
|
-
|
|
202
|
-
---
|
|
203
|
-
|
|
204
|
-
### `clearEvents(): void`
|
|
205
|
-
|
|
206
|
-
Clears all events and beacons, allowing subsequent expectations to ignore events that have been sent in the past.
|
|
207
|
-
|
|
208
|
-
#### Example:
|
|
209
|
-
```typescript
|
|
210
|
-
sendFooEvent();
|
|
211
|
-
await dynatraceTesting.expectToHaveSentEventTimes({ foo: "bar" }, 1);
|
|
212
|
-
|
|
213
|
-
dynatraceTesting.clearEvents();
|
|
214
|
-
|
|
215
|
-
await dynatraceTesting.expectToHaveSentEventTimes({ foo: "bar" }, 1);
|