Skip to main content
← Back to Blog

Deterministic AI Testing: One Test, Three Profiles (Explore, Guided, Strict)

By · 10 min

Short version: an AI agent that heals failing tests can also heal a broken app into a green build. Selenium AI Agent 3.9.0 adds three profiles, explore, guided and strict, that decide how much the AI may change without a person. CI always runs plain test code, without an LLM.

Every client asks for AI in testing now. The question we get right after is: how do we know the AI didn’t just make the tests pass? In the example below, the cart shows “0 items” after adding a product. The agent “fixes” the test to expect “0 items”, and the bug ships with a passing suite.

So we built the answer into the agent itself:

  • explore: the default, and the behaviour of earlier versions. Fast and AI-led, with no extra gates.
  • guided: a person approves the intent. Plans must be approved, heals that change what a test checks need the user’s own words, and every test must prove it is stable and can fail.
  • strict: CI-grade. Heals may only touch locators and waits, locators come from a locked set, and nothing reaches CI without verification.

The AI still writes and heals the tests in every profile. The profile decides what it may change on its own.

All output in this post is real. It comes from Selenium AI Agent 3.9.0 running the same pytest test under each profile. File paths are shortened and long lines wrapped; nothing else is changed.


The setup

Every scenario uses the same three things: one test, one approved plan and one line of config. Only the profile changes.

The test adds a product to a cart and checks the label the user sees:

from shop import Cart

def test_add_item():
    cart = Cart()
    cart.add("keyboard")
    assert cart.label() == "1 items"

The plan it implements is approved by a person. The agent records who approved it and when, directly under the plan’s title:

# Cart

**Status:** approved — approved by the user on 2026-11-28 18:00 UTC: "looks good"

The profile is one file in the project root, .selenium-agent.json. No file means explore.

{ "profile": "strict" }

The agent writes the test with generator_write_test. Under guided and strict it does not count the test as done yet; it answers:

Not verified yet. The “strict” profile needs 5 green runs in a row and the fails-for-the-right-reason check: call verify_test_stability with this file before reporting the test as done.

Under explore that line is missing: the test is done as soon as it is written.


Scenario 1: the app has a bug

Only explore lets the agent heal a real bug away. Guided stops for a person, and strict refuses outright.

The cart now shows “0 items” after adding a product. The test fails, as it should. The agent then proposes a heal that changes the expected value to match the app:

-    assert cart.label() == "1 items"
+    assert cart.label() == "0 items"

healer_fix_test sorts every changed line into a kind: locator, wait, assertion, removed step, added step, or other code. This heal is two assertion lines, and each profile treats that differently.

explore: the heal is applied

APPLIED: {"assertion":2}

Selenium AI Agent gate — profile: explore
PASS  tests/test_cart.py
1 test(s): 1 pass, 0 warn, 0 fail — gate passed

The suite is green and the bug ships. Nothing in the output tells a reviewer that the test now checks something else.

guided: the heal waits for a person

Fix not written: under the heal policy "assertions-need-approval" (profile) this fix
needs the user's approval, because it changes more than locators and waits:
  line 8 (removed, assertion / expected value): assert cart.label() == "1 items"
  line 8 (added, assertion / expected value): assert cart.label() == "0 items"
Show these lines to the user and explain why the test (not the app) is wrong. Only if
the user approves it in the chat, call healer_fix_test again with their words as
"userApproval". If the app is broken, report it instead of healing the test.

The file is unchanged. If the expected behaviour really changed, the user says so in the chat and the agent passes those words as userApproval. The approval, with the user’s own words, lands in the audit log.

strict: the heal is refused

Fix not written: the heal policy "locators-only" (profile) lets a heal change only
locators and waits. This fix changes what the test checks or does:
  line 8 (removed, assertion / expected value): assert cart.label() == "1 items"
  line 8 (added, assertion / expected value): assert cart.label() == "0 items"
If the app is broken, report it: do not heal the test. If the expected behaviour
really changed, update the test plan (planner_save_plan), have the user approve it,
and generate the test again with generator_write_test.

Not even an approval gets this through. Under strict, a change in what a test checks starts at the plan: change it, get it approved, regenerate the test.

A heal that only changes a locator, for example By.ID, "add-3" to By.CSS_SELECTOR, "[data-testid=add-3]", is classified as {"locator":1} and goes through in all three profiles. Under strict, the new locator must also be in the locked set.


Scenario 2: a test that checks nothing

Guided and strict reject a test that stays green when its expected value is wrong. Explore never checks.

AI-written tests are often green for the wrong reason. This one passes, but its assertion can never fail:

assert "items" in cart.label() or cart.label() != ""

verify_test_stability runs the test several times in a row (3 in guided, 5 in strict). Then it runs copies of the test with one expected value changed, and each copy must go red. Only expected values change, never locators, so a red copy means the assertion caught it.

For the good test from the setup, the copy goes red, as it should:

{"passed": true, "runs": 5,
 "failCheck": {"mutants": [{"line": 8,
   "changed": "assert cart.label() == \"1 items__mutated__\"", "caught": true}], "caught": 1}}

For the weak test, the copy stays green, and the test is rejected:

{"passed": false,
 "reasons": ["1 of 1 changed expected values stayed green: those assertions check nothing"],
 "next": "Strengthen the assertions that stayed green (compare the exact text or value
          the user sees), then verify again."}

Selenium AI Agent gate — profile: guided
FAIL  tests/test_cart.py
      FAIL verified: the last verification failed (3/3 green, 0/1 mutants caught)

The stability runs catch the other common AI failure: a flaky test. One red run among the green ones is reported as flaky: red on run 2 after 1 green, and the test is not accepted. The fix is a wait for the right condition, never a sleep or a longer timeout; the healer refuses both.

The copies are written next to the test, run and deleted again. Java and C# are skipped, because a copy would duplicate the test class; use PIT or Stryker.NET there.


Scenario 3: someone edits the test by hand

Under guided and strict, a test changed outside the agent fails the CI gate until it is verified again.

The gate is a plain command for CI. It uses no LLM and no tokens, and it gives the same result every time. It checks each test in the manifest: is its plan still approved and unchanged, is the file what the agent last wrote, is it verified for this exact content, does it follow Selenium’s rules, and (in strict) are its locators all in the locked set. With --run, it then runs the suite.

After verification, the gate passes and runs the suite:

$ npx selenium-ai-agent gate . --run
Selenium AI Agent gate — profile: strict
PASS  tests/test_cart.py
1 test(s): 1 pass, 0 warn, 0 fail — gate passed

Running the suite (no LLM): python3 -m pytest -q -p no:cacheprovider
.                                                                        [100%]
1 passed in 0.00s

Then someone changes the expected value by hand, from “1 items” to “2 items”, and pushes. The gate fails the build with exit code 1:

Selenium AI Agent gate — profile: strict
FAIL  tests/test_cart.py
      FAIL content: changed outside the agent since it was last written: review the change,
           then verify the test again
      FAIL verified: the file changed since it was verified: run verify_test_stability again
1 test(s): 0 pass, 0 warn, 1 fail — gate FAILED

The same check stops an AI from going around the heal policy. An agent that edits the file with a plain edit tool and then sends the same code through healer_fix_test is refused under guided and strict, unless the user confirms the edit.

Everything above lands in .agent-audit.jsonl: who approved the plan, which test was written, which heal was refused and why, and every verification. Each entry carries a hash of the file version it is about:

{"profile":"strict","event":"test_written","file":"tests/test_cart.py","hash":"950499ad6cc50f64",...}
{"profile":"strict","event":"stability_verified","file":"tests/test_cart.py","hash":"950499ad6cc50f64",...}
{"profile":"strict","event":"heal_refused","file":"tests/test_cart.py","reason":"heal policy",...}

Side by side

Each step from explore to strict turns one more AI decision into a gate that a person or CI controls.

Settingexplore (default)guidedstrict
Plan approvalAs configured (on by default)Required, no skippingRequired, no skipping
Selenium’s rulesErrors block, override allowedErrors block, override allowedErrors block, no override
Heal policyAnythingAssertions and removed steps need the user’s wordsLocators and waits only
LocatorsAnyAnyLocked: plan Elements, locators.json, taught selectors
Stability runs035
Fails-for-the-right-reason checkOffOnOn
Plan changed after the test was writtenIgnoredReportedHeals blocked, gate fails
Edit made outside the agentIgnoredNeeds the user’s confirmation; gate fails until verified againNeeds the user’s confirmation; gate fails until verified again
Audit logOffOnOn
Scenario 1: bug healed awayApplied, gate passesWaits for a personRefused
Scenario 2: assertion checks nothingNot checkedRejectedRejected

Any setting can be changed per project with overrides, for example { "profile": "strict", "overrides": { "stabilityRuns": 3 } }.


Which profile when

Start new projects on guided, and move suites that gate a release to strict.

  • explore fits a spike, a demo, or learning what the agent can do. You get speed, and you review every change yourself.
  • guided fits a team that is adopting AI in testing. The AI writes and heals, a person approves intent, and nothing unverified counts as done.
  • strict fits a suite in a release gate or an audited setting. It is slower to start, because it asks for test ids, approvals and 5 runs per test. In return, the suite only changes in ways a person approved.

To switch, edit .selenium-agent.json or set SELENIUM_MCP_PROFILE. You can also ask the agent; its agent_profile tool only switches with your own words, and it says what a looser profile turns off:

Less strict than strict: the plan review can be skipped again; rule overrides are allowed
again; heal policy becomes free; locators are no longer locked; stability runs 5 → 0;
no fails-for-the-right-reason check; spec lock block → off; no audit log.

Try it yourself

The profiles are in Selenium AI Agent 3.9.0 and later, and the setup takes three steps.

  1. Install the agents in your project, or run init-agents again to update them:

    npx selenium-ai-agent@latest init-agents --loop=claude
    
  2. Pick a profile in the project root:

    echo '{ "profile": "guided" }' > .selenium-agent.json
    
  3. Add the gate to CI, so only approved and verified tests run:

    - run: npx selenium-ai-agent gate --run
    

Then ask the agent to plan, generate and heal tests as usual. It reads the profile before every step.

Want to go further? Our course Agentic Engineering with Claude Code covers tests first, hooks and quality gates for AI-written code, on a real project from start to finish.

Next step

Learn this step by step in the course Agentic Engineering with Claude Code

Work with AI agents on a real codebase: context, skills, MCP, hooks and tests that keep the agent honest.

View the course →

Ralph van der Horst

Test automation consultant and builder of selenium-ai-agent and Robotyxx. Writes about AI, test automation and RPA from hands-on project work. More about me →

Related articles