optimize-login
Pay a web application's login cost once per session instead of once per test — drive the login live, reduce it to the smallest script that works, save the browser session, and reload that session into a fresh browser to continue. Use when login is the slow part of a run, when several scenarios each re-login, or whenever a run needs an authenticated browser.
- License 许可
- MIT
- 最近更新
- 2026-10-26
- Stars
- ★ 21
- Forks
- 18
01 前言 Front Matter
- name
- optimize-login
- description
- Pay a web application's login cost once per session instead of once per test — drive the login live, reduce it to the smallest script that works, save the browser session, and reload that session into a fresh browser to continue. Use when login is the slow part of a run, when several scenarios each re-login, or whenever a run needs an authenticated browser.
02 资源文件 2
- 脚本scripts/session.js9.7 KB
- 脚本scripts/session.test.js12.4 KB
03 SKILL.md 正文
Optimize Login — pay for the login once
Role
You turn a web application's login into a one-time cost per session: discover the real login live, script the smallest path through it, then save and reload that session for every later run. You never build around a security gate — a captcha or OTP you cannot solve is handed to a person, never bypassed.
Login is usually the most expensive step of a browser run and the least interesting. On a real project it was ~197 seconds of agentic driving per scenario, inside a ~12-minute preamble. After applying this skill: ~38s once, then ~8s per later run.
The loop below is the same everywhere. How much code it takes is not — a username/password form is three lines; a cross-origin iframe with a captcha and an OTP is a hundred and fifty. Find out by looking, not by assuming.
The loop
- Look at the real login. Open it and read what is actually there: which fields, whether
the form sits in an iframe, what the submit control is, what stands between you and a
session. Never write the script from memory or from another application's login. Log in
with a user from the active environment's
users(password: the user'spasswordordefaults.password;login.modeinconfig/project.jsonsays whether to reuse saved sessions ("session") or log in fresh every run ("fresh")). - Write the smallest script that gets through it, driving only what the page requires.
- Prove you are in — by a landmark, never by the URL (see below).
- Save the session (
storageState). In a playwright-cli session (a test run, define-flow):login_state.js save, neverstate-saveby hand. - Reload it into a fresh browser, prove you are in again, then continue the real work.
In a playwright-cli session:
login_state.js load, which loads into that session and checks the landmark saved with the file. - When the session dies, log in again. Do not build renewal machinery; re-login is cheap once step 2 exists.
Steps 3–5 are identical in every application and are bundled:
- In a playwright-cli session (a test run, define-flow):
${CLAUDE_PLUGIN_ROOT}/skills/browser-driver/scripts/login_state.js. Follow the browser-driver skill's "Login mode" section and${CLAUDE_PLUGIN_ROOT}/skills/browser-driver/references/tools/login-state.md. - In your own library script, or a standalone check:
${CLAUDE_PLUGIN_ROOT}/skills/optimize-login/scripts/session.js—saveSession(page, {statePath, landmark}),resumeSession({statePath, url, landmark}),isAuthenticated(page, landmark).
Steps 1–2 are yours to discover per application.
To check a saved session outside a run, without writing any project code (this launches its own library browser, not the run's session):
node ${CLAUDE_PLUGIN_ROOT}/skills/optimize-login/scripts/session.js resume \
--state test/.auth/<environment>-<user>-state.json \
--url https://app.example.com/dashboard \
--absent "role=button[name='Login']"
Prints one RESULT: RESUME_PASS|RESUME_FAIL line.
session.js needs the playwright PACKAGE, because it drives a library browser of its own (a
playwright-cli session loads a saved storageState through login_state.js and needs no
library). It looks for it in the project you run it from — the working directory and its
parents, so a monorepo hoist works — falling back to NODE_PATH if you set one. If
the project has not got it: npm i -D playwright, then npx playwright install chromium.
The bundled Chromium is what it launches; add --channel chrome (or msedge, …) only when
the test needs that specific browser, and --headed to watch a resume fail with your own
eyes. A channel you ask for and Playwright cannot launch is an error — no other browser is
quietly used in its place.
Verify by landmark, never by URL
A landmark is something true only when logged in: an element that appears (an account
menu), or one that disappears (the Login button). Pass {present: sel}, {absent: sel}, or
both.
URLs lie. A login page can carry ?returnUrl=/dashboard and satisfy any path-based check while
the user is still logged out — observed live, reporting a successful login that had not
happened, with the real failure surfacing much later somewhere unrelated.
Verify before saving and again after loading. A state file written from a half-finished login is well-formed and useless; and a session that has since expired leaves the file untouched, so "the file exists" is never "the session is alive". Do not gate on the file's age either — a 15-minute-old session was dead here while a 47-minute-old one restored cleanly.
When a step does not work
Read the live page, not your assumptions: dump the fields, buttons, disabled states and any error text as they are at the moment of failure, then fix that specific thing and re-run. Most login scripts fail for a reason the page will state plainly if you ask it.
Two habits that pay for themselves:
- Give every login script a hard watchdog, so a hang always terminates with a result line.
- Make failures dump page state automatically — the next repair should start from evidence, not from a fresh guess.
Record what you learn, per application
Whatever you discover about a specific login — a control that ignores clicks on its label, a
field the server reads that the visible inputs never populate, a step that opens on a different
method than you expect — belongs in that application's own notes, not in this skill. In a
project using the AgenTeX page map, that means the page's gotchas.
This is deliberate. A shipped list of somebody else's surprises invites you to read the next login through the wrong lens; the surprises are findings from exploring one application, and the next one will be strange in its own way.
Limits
- Gates are surfaced, never defeated. A captcha the page itself renders can be handed to a person, or read by the agent. reCAPTCHA, hCaptcha and Turnstile are not that, and no attempt to work around them belongs here — run headed, let a person complete the login, and the session is still saved at the end.
- An OTP you cannot obtain is a stop. Static test codes work; a real SMS, email or authenticator code needs a person, and the headed fallback covers it.
storageStateis cookies and localStorage only. An application holding its tokens in IndexedDB cannot be resumed this way — the post-load landmark check surfaces that plainly instead of leaving a confusing failure later.- Only for applications you are authorised to access. This is a way to stop paying for your own login repeatedly, not a way into anyone else's account.
Output
This skill produces no report of its own — its output is state, consumed by whatever flow invoked it:
- The bundled
session.js resumecheck prints exactly one line,RESULT: RESUME_PASS|RESUME_FAIL, and exits 0/1 to match. - A successful run leaves a session file at
test/.auth/<environment>-<user>-state.jsonfor later runs to reload. - Anything else worth keeping — what the login looked like, gotchas found — goes to the application's own notes (see "Record what you learn" above), never into this skill.
Session files are credentials
A saved session is a bearer token in a file: whoever holds it is logged in as that user. Keep
these in test/.auth/, which /init-test and /update-agentex add to the project's .gitignore,
and never commit one. Never open, print, copy or edit one (or its .meta.json sidecar); in a
playwright-cli session only login_state.js loads or saves it.
Sessions are saved per environment and user — test/.auth/<environment>-<user>-state.json
(e.g. qa-buyer-state.json); a session saved on one environment is never resumed on another,
and one user's is never resumed as another's.
04 同仓库更多 Skills
ui-check
Execute ui-check: steps in test specs — compare the live page currently open in the browser under test against a declared design baseline: a Figma frame (identifier only; file + token configured once per project) or a screenshot image, in exact mode (every visible detail) or reference mode (only enumerated details can fail). Triggers on spec steps starting with "ui-check:", or requests like "check this page against the design", "compare with the Figma frame", "does the screen match the mockup". Baselines are resolved by the bundled fetch_baseline.js runner — an unresolvable baseline is BLOCKED, never improvised; the comparison verdict itself is agent-vision judgment.
tracker-ops
Ad-hoc work-item operations on the configured tracker — Azure DevOps or Jira Cloud — behind one approval per write batch. Use this skill whenever the user asks for a one-off board operation outside the shipped flows: "move PROJ-12 to In Progress", "transition this issue to Done", "comment on bug 4711", "link X to Y", "update the story's title", "create a quick task on the board", "show me work item 42", "search the board for …". Every operation runs through ONE bundled script (dry run by default, REST over built-in fetch — no az, no acli); reads are free, writes show the exact request plan first and need the user's ONE approval before --execute. Unsupported operations are answered upfront from the tracker's capability flags — never guessed, never silently substituted.
test-execution
Run test specs against an application and report defects, routing each step to its driver (browser via playwright-cli, API calls, database checks, knowledge-base questions, UI design checks). Use whenever the user wants to test a website, web app, or API for defects (happy paths, edge cases, negative cases), either sequentially (human-in-the-loop, the default) or in parallel (autonomous). Produces per-scenario evidence plus a consolidated defect report. Read this before starting any test run.
test-design
Designs test cases for User Stories on the configured tracker — Azure DevOps or Jira Cloud: analyze a story's acceptance criteria into test conditions, map them to test case titles, create the test artifacts (ADO Test Cases with structured steps, or the Jira issue type the user chooses — Jira has no native Test Case type) and link them to the parent story, behind ONE consolidated approval. Use this skill whenever the user wants to: - Analyze a user story and identify test conditions - Map AC scenarios to test case titles using a naming convention - Create test cases in ADO with proper steps, or design test cases for a Jira story - Review whether a story's ACs are fully covered by test cases Trigger on phrases like: "create test cases for story", "design tests for", "design test cases for a Jira story", "what test cases do I need", "analyze story for testing", "map ACs to test conditions", or any time a user story ID or Jira issue key is mentioned alongside test design/coverage work.
task-estimation
Creates QA testing tasks with estimation on the configured tracker's User Stories — Azure DevOps or Jira Cloud. Reads the sprint, analyzes each story, then creates all [Testing] tasks (ADO Tasks or Jira sub-tasks) behind ONE consolidated approval, through bundled REST scripts (no Azure CLI, no acli). Use this skill whenever the user wants to: - Add QA tasks to sprint stories in Azure DevOps or Jira - Estimate testing hours for user stories - Create [Testing] tasks on ADO work items or [Testing] sub-tasks on Jira issues - Plan QA effort for a sprint - Break down stories into testing tasks with hours Trigger on phrases like: "create tasks for stories", "add QA tasks", "estimate sprint", "estimate the Jira sprint", "create testing tasks", "create tasks for Jira sprint stories", "add sub-tasks to Jira stories", "plan QA for sprint", "add tasks to stories", or any mention of sprint stories + estimation + testing.
swagger-import
Generate an API catalog + suite of test cases (integration/api_test_suites/<service>/) from a Swagger 2.0 or OpenAPI 3.x JSON document. Use for /import-swagger, or requests like "import this swagger doc", "generate endpoint tests from this OpenAPI spec", or the guided wizard (/import-swagger --wizard) that collects real test data and previews basic checks (happy path, not found, no token, missing field) before one approval. Output feeds directly into the endpoint-testing and api-integration skills. This skill generates config and sends no API request of its own; any run, including the wizard's "Approve and run now", goes through endpoint-testing's runner.