Skip to content

Commit

Permalink
less flaky
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldambra committed Dec 29, 2024
1 parent cac6d33 commit e5a4a47
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions playwright/session-recording/session-recording.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,13 @@ test.describe('Session recording - array.js', () => {

const responsePromise = page.waitForResponse('**/ses/*')
await page.mouse.move(200, 300)
await page.waitForTimeout(25)
await page.waitForTimeout(5)
await page.mouse.move(210, 300)
await page.waitForTimeout(25)
await page.waitForTimeout(5)
await page.mouse.move(220, 300)
await page.waitForTimeout(25)
await page.waitForTimeout(5)
await page.mouse.move(240, 300)
await page.waitForTimeout(25)
await page.waitForTimeout(5)
await responsePromise

const capturedEvents = await page.capturedEvents()
Expand Down Expand Up @@ -159,25 +159,23 @@ test.describe('Session recording - array.js', () => {
await page.resetCapturedEvents()
await waitForRecorder

await page.evaluate(() => {
const ph = (window as WindowWithPostHog).posthog
ph?.capture('some_custom_event')
})
const capturedAfterReload = await page.capturedEvents()
expect(capturedAfterReload.map((x) => x.event)).toEqual(['some_custom_event'])
expect(capturedAfterReload[0]['properties']['$session_id']).toEqual(firstSessionId)
expect(capturedAfterReload[0]['properties']['$session_recording_start_reason']).toEqual('recording_initialized')
expect(capturedAfterReload[0]['properties']['$recording_status']).toEqual('active')

await page.resetCapturedEvents()

const moreResponsePromise = page.waitForResponse('**/ses/*')
await page.locator('[data-cy-input]').type('hello posthog!')
await moreResponsePromise

const capturedAfterActivity = await page.capturedEvents()
expect(capturedAfterActivity.map((x) => x.event)).toEqual(['$snapshot'])
expect(capturedAfterActivity[0]['properties']['$session_id']).toEqual(firstSessionId)

await page.evaluate(() => {
const ph = (window as WindowWithPostHog).posthog
ph?.capture('some_custom_event')
})
const capturedAfterReload = await page.capturedEvents()
expect(capturedAfterReload.map((x) => x.event)).toEqual(['$snapshot', 'some_custom_event'])
expect(capturedAfterReload[1]['properties']['$session_id']).toEqual(firstSessionId)
expect(capturedAfterReload[1]['properties']['$session_recording_start_reason']).toEqual('recording_initialized')
expect(capturedAfterReload[1]['properties']['$recording_status']).toEqual('active')
})

test('starts a new recording after calling reset', async ({ page }) => {
Expand Down

0 comments on commit e5a4a47

Please sign in to comment.