Module: pipeline/autoLogin

Selector-less login helper. Given a Playwright page, a username and password, locates the three login form elements (username field, password field, submit button) via a semantic-first waterfall of locator strategies so users don't have to hand-author CSS selectors when creating a project.

Strategies (in order, per field)

Username field

  1. page.locator('input[type="email"]').first()
  2. page.getByLabel(/email|user|login/i)
  3. page.getByPlaceholder(/email|user|login/i)
  4. page.getByRole('textbox', { name: /email|user|login/i })
  5. page.locator('input[name*="email" i], input[name*="user" i], input[id*="email" i], input[id*="user" i]')
  6. First visible non-password <input> on the page (last resort).

Password field

  1. page.locator('input[type="password"]').first() — almost always wins.

Submit button

  1. page.getByRole('button', { name: /sign in|log in|login|submit|continue/i })
  2. page.locator('button[type="submit"], input[type="submit"]').first()
  3. form button:not([type="button"]) scoped to the password field's form.
  4. Fallback: press Enter inside the password field (browsers submit the form natively).

Honest limitations: this is a best-effort heuristic, not an AI solver. It handles ~90% of conventional login pages (email + password + button) but will miss exotic flows (multi-step SSO, captchas, phone-number-first forms, shadow-DOM components without semantic roles). Those sites can still fall back to the recorder or legacy explicit selectors.

Backwards compatibility

Projects that already persist explicit usernameSelector / passwordSelector / submitSelector values continue to use them (fast path). This module is only invoked when those fields are blank.

Source:
Example
const ok = await performAutoLogin(page, {
  username: "alice@example.com",
  password: "secret",
}, { timeout: 5000, logger: (m) => console.log(m) });

Methods

(static) performAutoLogin(page, creds, optsopt) → {Promise.<object>}

Attempt to log in by auto-detecting the login form elements.

Parameters:
Name Type Attributes Description
page object

Playwright Page already navigated to the login URL.

creds object

{ username, password } strings.

opts object <optional>
Properties
Name Type Attributes Default Description
timeout number <optional>
5000

Per-strategy visibility timeout (ms).

logger function <optional>

Optional logger (msg) => void.

Source:
Returns:

Result envelope { ok: boolean, reason?: string }. Never throws — transient Playwright errors are captured in reason.

Type
Promise.<object>