/// Resources / Local AI
Running an AI test-repair assistant fully offline with Ollama: the request, the schema and the caps
“AI-powered” usually means a cloud call with your page content in it, a non-starter on a locked-down network. The alternative is to move the model onto the box. Here is exactly what a locator-repair assistant sends to a local Ollama instance, what it insists on getting back, and the caps that keep an 8B model from doing damage.
Where the model sits, and where it does not
The decision that matters for a security review: the model is called only while a human is authoring or repairing a test in the recorder. The generated Maven project has no AI dependency and never contacts a model at mvn test time, in CI or anywhere else. The provider switch is one field in ai.json next to the tool:
{
"provider": "ollama",
"ollamaUrl": "http://localhost:11434",
"ollamaModel": "llama3.1:8b",
"dailyLimit": 50,
"monthlyLimit": 500,
"cooldownSeconds": 4,
"maxDomChars": 12000
}
With provider set to ollama the API-key fields are ignored, one model name serves both authoring and repair, and the only host that ever receives a request is ollamaUrl. Point it at an internal GPU box if the laptops are too small. The Settings Test button does a GET /api/tags and reports whether the named model has been pulled; nothing else is checked until a real call, so an offline PC still shows the AI buttons.
The request: one call to /api/chat
When a replay pauses on a failed step, the recorder offers Fix with AI. Clicking it builds one non-streaming chat request. There is no SDK and no hidden system prompt:
{
"model": "llama3.1:8b",
"stream": false,
"messages": [
{ "role": "system",
"content": "You repair a broken Selenium locator. Given a failing step, its old locator, the error, and the current page DOM, return a STABLE cssSelector for the element the step intended to target (prefer #id, then [name=...], then a short unique CSS path). If you cannot find a good match, set confidence to \"low\"." },
{ "role": "user",
"content": "Failing step action: click\nOld locator: {\"css\":\"#btn-submit\",\"label\":\"Submit\"}\nError: no such element: #btn-submit\n\nCurrent page interactive elements (JSON):\n[ ... ]" }
],
"options": { "temperature": 0, "num_predict": 400 },
"format": { "type": "object", "required": ["cssSelector"],
"properties": { "cssSelector": { "type": "string" },
"label": { "type": "string" },
"confidence": { "type": "string", "enum": ["high","medium","low"] } },
"additionalProperties": false }
}
Three choices do most of the work. temperature: 0 makes the proposal repeatable for the same page. num_predict: 400 is the whole output budget; a selector does not need more and a runaway model stops at the cap. And format is a JSON schema, which Ollama (0.5 and later) enforces with constrained decoding, so the reply is the object you asked for rather than a paragraph that mentions one.
What “the current page DOM” actually contains
The model never sees the raw HTML. A script in the paused browser returns only the visible interactive elements (a, button, input, select, textarea, [role=button], [onclick], label), capped at 120 entries, one small row each:
{ "tag": "button", "type": "submit", "id": "", "name": "",
"text": "Place order", "css": "form > div:nth-of-type(3) > button" }
Text is trimmed to 60 characters, zero-size elements are skipped, and a password field contributes no value. The css path prefers an id, then a name attribute, then at most five levels of nth-of-type path. The serialised list is cut at maxDomChars (12,000 by default) before it enters the prompt. That cap is why an 8B model with a modest context window copes: a few thousand tokens, not a page source.
What comes back, and what the recorder does with it
The reply is parsed leniently, because small models still occasionally wrap JSON in fences or add a sentence after it: exact parse first, then with ```json fences stripped, then the first balanced {...} block. If none yields an object the call fails with a message naming the fix (a larger instruct model such as qwen2.5:14b) and nothing is applied. On success the recorder does not silently patch the test:
AI proposed locator form > div:nth-of-type(3) > button (confidence: medium)
- matches exactly 1 element. Check the outlined element, then Resume.
The selector is written onto the paused step, the matching element is outlined on the live page, the note is pinned under the step, and the test stays paused until you click Resume. If the outline is on the wrong button you edit or revert; the model never decides that a test passes.
The caps: ai_usage.json
A local model costs nothing per token, so the quota exists for a different reason: a retry loop should not be able to hammer the GPU box or churn locators all afternoon. Every call, successful or not, increments a small file beside ai.json:
{ "day": "2026-11-17", "dayCount": 7,
"month": "2026-11", "monthCount": 61,
"lastCallUtc": "2026-11-17T14:02:11.4410000Z" }
A call is refused while fewer than cooldownSeconds have passed since lastCallUtc, when dayCount reaches dailyLimit, or when monthCount reaches monthlyLimit; the counters roll over when the date changes. The check runs before the DOM is captured, so a refused call sends nothing anywhere.
What this does not do
- It does not run at test time. Repair is a recorder action. The deterministic self-healing scorer in the generated Java is a separate mechanism that needs no model.
- It does not pull the model for you. If
ollama pullhas not been run, the first call fails with the exact pull command in the message. The defaultllama3.1:8bis about 5 GB. - It only sees the paused page. If the failure was a missing navigation rather than a changed locator, the model proposes the nearest-looking element on the wrong page, which is exactly why the outline-then-Resume step exists.
- A low confidence is not an error. The schema lets the model answer
"confidence": "low", and the note shows it. Treat it as a prompt to look harder, not a selector to accept.
The four-step setup (install Ollama, pull a model, switch the provider, press Test) is in the offline AI guide; the same switch covers plain-English authoring as well as repair. For what an air-gapped install does and does not send, see L3git for regulated and air-gapped teams.
Questions
Can Ollama run on a shared server instead of each tester's PC?
Yes. Set ollamaUrl to that machine, for example http://ai-box.internal:11434, and use the same model name on every seat. Traffic stays on your network; there is no key and no account. The Test button in Settings confirms the model is pulled on that host.
Which model should I use for locator repair?
llama3.1:8b is the default and is enough for repair, because the task is choosing one element from a capped list and returning it in a fixed JSON shape. If replies are unparseable or the picks are poor, pull a larger instruct model such as qwen2.5:14b and change ollamaModel; nothing else changes.
Does switching to Ollama change what the generated tests do?
No. The generated Maven project is identical whichever provider authored it, and it never calls a model. The provider only decides where the recorder sends its authoring and repair prompts.