> ## Documentation Index
> Fetch the complete documentation index at: https://usefoil.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Testing your integration

> Test your Foil integration with test keys and simulated bot traffic from Playwright, Puppeteer, or Selenium, then confirm verdicts and enforcement paths.

Before you turn enforcement on in production, confirm two things: your integration **fires on bot traffic** and it **doesn't fire on real users**. This page walks through the patterns we recommend.

## Test vs live keys

Foil issues separate test and live key pairs.

* Test keys are prefixed `pk_test_*` / `sk_test_*`; live keys are `pk_live_*` / `sk_live_*`.
* Sessions created with test keys are tagged in the dashboard so you can filter integration traffic out of real metrics.
* Test and live keys are **not** interchangeable. A sealed token issued under a test publishable key cannot be verified with a live secret key - verification fails locally with a `FoilTokenVerificationError`. Keep the environments fully separate.
* Verdicts, scoring, phases, and fingerprinting behave the same across environments, with two exceptions. Test keys skip IP-intelligence enrichment, so findings that depend on the network, such as VPN, proxy, and hosting-provider detection, don't appear in test sessions. Test keys also skip the geo-velocity check that Foil applies when it resolves a visitor ID. Because Foil doesn't evaluate those network signals for test keys, a session can score lower under a test key than the same traffic would under a live key.

## What verdicts to expect

An unmodified automation runner should land on `bot` every time. Stealth variants still land on `bot` but with lower confidence, and real user traffic should land on `human`.

| Runner | Expected `decision.verdict` | Notes |
| - | - | - |
| Playwright (default Chromium) | `bot`, high `risk_score` | The browser reports that automation controls it, which Foil treats as definitive evidence. |
| Puppeteer (default) | `bot`, high `risk_score` | Same. |
| Selenium / WebDriver | `bot`, high `risk_score` | Same. |
| `playwright-stealth`, `puppeteer-extra-stealth` | `bot`, lower `risk_score` | `attribution.bot.labels` usually includes an `evasion` label, such as `stealth`. |
| Headless Chromium via `--headless=new` with no automation library | `bot` | Environment probes catch it; no behavioral signal needed. |
| Real browser with real user interaction before submit | `human`, `phase: "behavioral"` | Behavioral signals accumulate once the user moves and types. |
| Real browser, `getSession()` called before any interaction | `human`, `phase: "snapshot"`, `is_provisional: true` | Nothing indicates automation, but no behavioral evidence exists yet. |

If you're seeing consistently *different* verdicts than these, something is off in the integration - usually the sealed token isn't reaching the verifier, or `getSession()` is being called against a different `Foil.start()` instance than the one your page initialized.

## Runnable Playwright example

This asserts end-to-end that a bot gets blocked at signup:

```ts theme={"dark"}
import { test, expect, chromium } from '@playwright/test';

test('bot traffic is blocked at signup', async () => {
  const browser = await chromium.launch({ headless: true });
  const page = await browser.newPage();

  await page.goto('http://localhost:3000/signup');
  await page.fill('input[name="email"]', 'bot@example.com');
  await page.fill('input[name="password"]', 'correct-horse-battery-staple');

  const [response] = await Promise.all([
    page.waitForResponse('**/api/signup'),
    page.click('button[type="submit"]'),
  ]);

  expect(response.status()).toBe(403);
  await browser.close();
});
```

Run it with `npx playwright test` against your local dev server. If the assertion passes, your block path is wired correctly. To verify the allow path, submit the form by hand from a regular browser against your staging build and confirm that the response is `200`. Don't change this test to expect `200`: the test is scripted, so Foil still classifies it as a bot and your server blocks it.

For Puppeteer, Selenium, or WebDriverIO, the pattern is the same - launch, navigate, submit, assert the response. Foil detects them all.

## Testing the `inconclusive` path

`inconclusive` means that Foil doesn't have enough evidence either way. You can't request it on demand, because Foil decides the verdict from the evidence in each session. Calling `getSession()` before any interaction doesn't reliably produce it either: a session with no sign of automation gets a provisional `human` verdict in the snapshot phase (`phase: "snapshot"`, `is_provisional: true`).

To test whatever challenge flow you serve on ambiguous sessions, such as a CAPTCHA, email verification, or step-up authentication, stub the verification result in your own tests. For example, if your handler calls a `verifyFoil()` function like the one in [Server verification](https://usefoil.com/docs/server-verification.md#what-verification-doesnt-check), have the test return an inconclusive result:

```js theme={"dark"}
// In a test, replace verifyFoil() with a stub that returns an inconclusive decision.
const verifyFoil = () => ({
  session_id: "sid_test",
  decision: {
    event_id: "evt_test",
    verdict: "inconclusive",
    risk_score: 55,
    phase: "behavioral",
    is_provisional: false,
  },
});
```

If your integration treats `inconclusive` identically to `human`, you're leaving coverage on the table; see [Verdicts & scoring](https://usefoil.com/docs/verdicts-and-scoring.md) for the recommended policy split.

## Debugging common issues

| Symptom | Cause | Fix |
| - | - | - |
| `getSession()` rejects with `runtime.unavailable` | Method called before `start()` resolved, or after `destroy()` | Await the `start()` promise before any client method. See [Browser SDK → API reference](https://usefoil.com/docs/browser-sdk.md#api-reference). |
| The `import()` of `t.js` rejects, or `start()` rejects with `runtime.bootstrap_failed` | CSP blocks `cdn.usefoil.com` (the import rejects) or `'wasm-unsafe-eval'` (bootstrap fails), or the CDN load fails | See [Content Security Policy](https://usefoil.com/docs/content-security-policy.md). |
| Sealed token verification fails locally with no clear reason | Mismatched environment - test-key token verified with a live secret key (or vice versa) | Confirm `pk_*` and `sk_*` come from the same organization **and** environment. |
| Handoff verifies locally but requests to `api.usefoil.com` return `auth.origin_not_allowed` | The publishable key's allowed-origin list doesn't include your dev host | Add `http://localhost:3000` (or your dev origin) to the key's allowed origins in the dashboard, or use an unrestricted test key. |
| Server receives `sealedToken: undefined` | Request-body shape mismatch | Confirm the browser sends JSON with a `foil: { sessionId, sealedToken }` field, and that your body parser runs before your verification middleware. |
| Real test sessions from your own machine score as `inconclusive` | The session's evidence is mixed: the score falls between the `human` and `bot` ranges, or a behavioral-phase result has too little interaction for a `human` verdict. Frontend scripts on the page, such as monitoring or tag manager scripts, can add evidence. | Log `decision.phase`, `decision.risk_score`, and `attribution` for the session. Test in a clean browser profile, and see [Frontend JavaScript compatibility](https://usefoil.com/docs/runtime-instrumentation.md). Call `getSession()` at action time so the result includes behavioral evidence. See [Browser SDK → Best practices](https://usefoil.com/docs/browser-sdk.md#best-practices). |

## What's next

* [Going to production](https://usefoil.com/docs/going-to-production.md) - rollout checklist and monitoring
* [Verdicts & scoring](https://usefoil.com/docs/verdicts-and-scoring.md) - policy patterns for each verdict band
* [Troubleshooting](https://usefoil.com/docs/resources/troubleshooting.md) - production error triage


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.