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
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict'

const { test, expect } = require('@playwright/test')

test.beforeEach(async ({ page }) => {
await page.goto(process.env.PW_BASE_URL)
})

test.describe('playwright', () => {
test('should have RUM active', async ({ page }) => {
await expect(page.locator('.hello-world')).toHaveText([
'Hello World'
])
await page.goto(`${process.env.PW_BASE_URL}/another-page`)
await expect(page.locator('.hello-world')).toHaveText([
'Hello World'
])
})
})
42 changes: 22 additions & 20 deletions integration-tests/playwright/playwright.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1700,25 +1700,26 @@ versions.forEach((version) => {
receiver
.gatherPayloadsMaxTimeout(({ url }) => url === '/api/v2/citestcycle', (payloads) => {
const events = payloads.flatMap(({ payload }) => payload.events)
const playwrightTest = events.find(event => event.type === 'test').content
if (isRedirecting) {
assert.notProperty(playwrightTest.meta, TEST_IS_RUM_ACTIVE)
assert.notProperty(playwrightTest.meta, TEST_BROWSER_VERSION)
} else {
assert.property(playwrightTest.meta, TEST_IS_RUM_ACTIVE, 'true')
assert.property(playwrightTest.meta, TEST_BROWSER_VERSION)
}
assert.include(playwrightTest.meta, {
[TEST_BROWSER_NAME]: 'chromium',
[TEST_TYPE]: 'browser'
const tests = events.filter(event => event.type === 'test').map(event => event.content)
tests.forEach(test => {
if (isRedirecting) {
// can't do assertions because playwright has been redirected
assert.propertyVal(test.meta, TEST_STATUS, 'fail')
assert.notProperty(test.meta, TEST_IS_RUM_ACTIVE)
assert.notProperty(test.meta, TEST_BROWSER_VERSION)
} else {
assert.propertyVal(test.meta, TEST_STATUS, 'pass')
assert.property(test.meta, TEST_IS_RUM_ACTIVE, 'true')
assert.property(test.meta, TEST_BROWSER_VERSION)
}
})
})

const runTest = (done, { isRedirecting }, extraEnvVars) => {
const runRumTest = async ({ isRedirecting }, extraEnvVars) => {
const testAssertionsPromise = getTestAssertions({ isRedirecting })

childProcess = exec(
'./node_modules/.bin/playwright test -c playwright.config.js active-test-span-rum-test.js',
'./node_modules/.bin/playwright test -c playwright.config.js',
{
cwd,
env: {
Expand All @@ -1731,17 +1732,18 @@ versions.forEach((version) => {
}
)

childProcess.on('exit', () => {
testAssertionsPromise.then(() => done()).catch(done)
})
await Promise.all([
once(childProcess, 'exit'),
testAssertionsPromise
])
}

it('can correlate tests and RUM sessions', (done) => {
runTest(done, { isRedirecting: false })
it('can correlate tests and RUM sessions', async () => {
await runRumTest({ isRedirecting: false })
})

it('do not crash when redirecting and RUM sessions are not active', (done) => {
runTest(done, { isRedirecting: true })
it('do not crash when redirecting and RUM sessions are not active', async () => {
await runRumTest({ isRedirecting: true })
})
})

Expand Down
7 changes: 6 additions & 1 deletion packages/datadog-instrumentations/src/playwright.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ const testSuiteToTestStatuses = new Map()
const testSuiteToErrors = new Map()
const testsToTestStatuses = new Map()

const RUM_FLUSH_WAIT_TIME = 1000

let applyRepeatEachIndex = null

let startedSuites = []
Expand Down Expand Up @@ -1060,16 +1062,19 @@ addHook({
})

if (isRumActive) {
// Give some time RUM to flush data, similar to what we do in selenium
await new Promise(resolve => setTimeout(resolve, RUM_FLUSH_WAIT_TIME))
const url = page.url()
if (url) {
const domain = new URL(url).hostname
await page.context().addCookies([{
name: 'datadog-ci-visibility-test-execution-id',
value: '',
domain,
expires: 0,
path: '/'
}])
} else {
log.error('RUM is active but page.url() is not available')
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion packages/datadog-plugin-playwright/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const {
TELEMETRY_EVENT_FINISHED
} = require('../../dd-trace/src/ci-visibility/telemetry')
const { appClosing: appClosingTelemetry } = require('../../dd-trace/src/telemetry')
const log = require('../../dd-trace/src/log')

class PlaywrightPlugin extends CiPlugin {
static id = 'playwright'
Expand Down Expand Up @@ -174,7 +175,10 @@ class PlaywrightPlugin extends CiPlugin {
}) => {
const store = storage('legacy').getStore()
const span = store && store.span
if (!span) return
if (!span) {
log.error('ci:playwright:test:page-goto: test span not found')
return
}

if (isRumActive) {
span.setTag(TEST_IS_RUM_ACTIVE, 'true')
Expand Down
Loading