Files
upstream-frappe-crm/e2e/helpers/auth.ts
upstream-mirror db69de1c11
Some checks failed
Frontend / Unit Tests & Coverage (push) Has been skipped
Regenerate POT file (translatable strings) / Regenerate POT file (develop) (push) Failing after 1m13s
Regenerate POT file (translatable strings) / Regenerate POT file (main-hotfix) (push) Failing after 6s
Server / Tests (frappe ${{ matrix.frappe-branch }}) (push) Has been skipped
Server / Resolve frappe matrix (push) Failing after 1s
Frontend / Lint (push) Failing after 1s
Frontend / Production Build (push) Failing after 1s
Server / Coverage Wrap Up (push) Has been skipped
Frontend / Coverage Wrap Up (push) Has been skipped
snapshot of https://github.com/frappe/crm.git (develop, 2026-09-18; blobs > 131072B omitted)
2026-09-18 01:36:01 +05:00

47 lines
1.1 KiB
TypeScript

import { APIRequestContext, Page } from '@playwright/test'
/**
* Login via the Frappe API (faster than UI login).
* Sets session cookies on the request context for subsequent API calls.
*/
export async function loginViaAPI(
request: APIRequestContext,
email = 'Administrator',
password = 'admin',
): Promise<void> {
const response = await request.post('/api/method/login', {
form: { usr: email, pwd: password },
})
if (!response.ok()) {
throw new Error(
`Login failed: ${response.status()} ${await response.text()}`,
)
}
}
/**
* Logout the current user.
*/
export async function logout(page: Page): Promise<void> {
await page.goto('/api/method/logout')
await page.waitForLoadState('networkidle')
}
/**
* Check if a user is logged in by verifying the session.
*/
export async function isLoggedIn(request: APIRequestContext): Promise<boolean> {
try {
const response = await request.get(
'/api/method/frappe.auth.get_logged_user',
)
if (!response.ok()) return false
const data = await response.json()
return data.message && data.message !== 'Guest'
} catch {
return false
}
}