Skip to content

Test tracking in end-to-end tests

Check your events in Playwright, Cypress or Selenium tests.

Loomduct skips automated browsers, so your end-to-end tests do not show up in your numbers. To test that your tracking works, turn it on for that test run.

Before you start

  • Loomduct installed on your site. See the Quick start.

Skipped by default

The SDK sends nothing when navigator.webdriver is set (Playwright, Puppeteer, Selenium) or in Cypress.

Turn it on for a test run

src/loomduct.ts
import { Loomduct } from '@loomduct/js'
import { webAnalytics } from '@loomduct/js/web-analytics'

export const loomduct = new Loomduct({
  token: 'lmt_your_project_token',
  plugins: [webAnalytics()],
  allowAutomation: import.meta.env.VITE_LOOMDUCT_E2E === 'true',
})

With the script tag, add data-allow-automation on your test build only.

Use a separate Loomduct project for tests, so test events stay out of your real numbers.

In unit tests, do not call load(). Nothing is sent, and all methods still work.

Check that it worked

In your test, wait for a POST request to /l/e and check that it answers 202. In Playwright:

tests/tracking.spec.ts
const request = page.waitForResponse((response) => response.url().endsWith('/l/e'))
await page.goto('/')
expect((await request).status()).toBe(202)