|
| 1 | +import { expect, test } from '@playwright/test'; |
| 2 | +import { waitForError, waitForTransaction } from '@sentry-internal/test-utils'; |
| 3 | + |
| 4 | +test('sends a pageload transaction', async ({ page }) => { |
| 5 | + const transactionPromise = waitForTransaction('default-browser', async transactionEvent => { |
| 6 | + return !!transactionEvent?.transaction && transactionEvent.contexts?.trace?.op === 'pageload'; |
| 7 | + }); |
| 8 | + |
| 9 | + const errorEventPromise = waitForError('default-browser', event => { |
| 10 | + return !event.type && event.exception?.values?.[0]?.value === 'I am an error!'; |
| 11 | + }); |
| 12 | + |
| 13 | + await page.goto('/'); |
| 14 | + const transactionEvent = await transactionPromise; |
| 15 | + |
| 16 | + const exceptionButton = page.locator('id=exception-button'); |
| 17 | + await exceptionButton.click(); |
| 18 | + |
| 19 | + const errorEvent = await errorEventPromise; |
| 20 | + |
| 21 | + expect(errorEvent.exception?.values).toHaveLength(1); |
| 22 | + expect(errorEvent.exception?.values?.[0]?.value).toBe('I am an error!'); |
| 23 | + |
| 24 | + expect(errorEvent.transaction).toEqual('/'); |
| 25 | + |
| 26 | + expect(errorEvent.contexts?.trace).toEqual({ |
| 27 | + trace_id: transactionEvent.contexts?.trace?.trace_id, |
| 28 | + span_id: expect.not.stringContaining(transactionEvent.contexts?.trace?.span_id || ''), |
| 29 | + }); |
| 30 | +}); |
| 31 | + |
| 32 | +test('sends a navigation transaction', async ({ page }) => { |
| 33 | + page.on('console', msg => console.log(msg.text())); |
| 34 | + const pageLoadTransactionPromise = waitForTransaction('default-browser', async transactionEvent => { |
| 35 | + return !!transactionEvent?.transaction && transactionEvent.contexts?.trace?.op === 'pageload'; |
| 36 | + }); |
| 37 | + |
| 38 | + const navigationTransactionPromise = waitForTransaction('default-browser', async transactionEvent => { |
| 39 | + return !!transactionEvent?.transaction && transactionEvent.contexts?.trace?.op === 'navigation'; |
| 40 | + }); |
| 41 | + |
| 42 | + await page.goto(`/`); |
| 43 | + await pageLoadTransactionPromise; |
| 44 | + |
| 45 | + const linkElement = page.locator('id=navigation-link'); |
| 46 | + |
| 47 | + await linkElement.click(); |
| 48 | + |
| 49 | + const navigationTransaction = await navigationTransactionPromise; |
| 50 | + |
| 51 | + expect(navigationTransaction).toMatchObject({ |
| 52 | + contexts: { |
| 53 | + trace: { |
| 54 | + op: 'navigation', |
| 55 | + origin: 'auto.navigation.browser', |
| 56 | + }, |
| 57 | + }, |
| 58 | + transaction: '/', |
| 59 | + transaction_info: { |
| 60 | + source: 'url', |
| 61 | + }, |
| 62 | + }); |
| 63 | +}); |
0 commit comments