Files
upstream-ory-kratos/test/e2e/playwright/tests/mobile/app_login.spec.ts
upstream-mirror c60cc7ca75
Some checks failed
CI / Run tests and lints (push) Failing after 29s
CI / Build CLI docs (push) Has been skipped
CI / Run Playwright end-to-end tests (mysql) (push) Failing after 3s
CI / Run Playwright end-to-end tests (postgres) (push) Failing after 2s
CI / Run Playwright end-to-end tests (sqlite) (push) Failing after 3s
CodeQL / Analyze (go) (push) Failing after 4s
CodeQL / Analyze (javascript) (push) Failing after 3s
Docker Image Scanners / scanners (push) Failing after 4s
Synchronize Issue Labels / Synchronize Issue Labels (push) Has been skipped
CI / Run end-to-end tests (postgres) (push) Failing after 19s
CI / Run end-to-end tests (sqlite) (push) Failing after 2s
CI / Run Playwright end-to-end tests (cockroach) (push) Failing after 2s
CI / Draft newsletter (push) Has been skipped
CI / Generate release (push) Has been skipped
CI / Pending approval Slack notification (push) Has been skipped
CI / Send newsletter (push) Has been skipped
snapshot of https://github.com/ory/kratos.git (master, 2026-09-15; blobs > 131072B omitted)
2026-09-15 21:19:12 +05:00

118 lines
3.7 KiB
TypeScript

// Copyright © 2023 Ory Corp
// SPDX-License-Identifier: Apache-2.0
import { expect, Page } from "@playwright/test"
import { test } from "../../fixtures"
async function performOidcLogin(popup: Page, username: string) {
await popup.waitForLoadState()
await popup.locator("#username").fill(username)
await popup.getByRole("button", { name: "login" }).click()
await popup.locator("#offline").click()
await popup.locator("#openid").click()
await popup.locator("#website").fill("https://example.com")
await popup.getByRole("button", { name: "login" }).click()
}
async function rejectOidcLogin(popup: Page) {
await popup.waitForLoadState()
await popup.getByRole("button", { name: "reject" }).click()
await popup.close()
}
async function testRegistrationOrLogin(page: Page, username: string) {
const popupPromise = page.waitForEvent("popup")
await page.getByText(/sign (up|in) with ory/i).click()
const popup = await popupPromise
await performOidcLogin(popup, username)
await page.waitForURL("Home")
expect(popup.isClosed()).toBeTruthy()
await expect(page.getByText("Welcome back")).toBeVisible()
}
async function logout(page: Page) {
return page.getByTestId("logout").click()
}
async function testRegistration(page: Page, username: string) {
await page.goto("Registration")
return testRegistrationOrLogin(page, username)
}
async function testLogin(page: Page, username: string) {
await page.goto("Login")
return testRegistrationOrLogin(page, username)
}
test.describe("Registration", () => {
test("register twice", async ({ page }) => {
await testRegistration(page, "registration@example.com")
await logout(page)
await testRegistration(page, "registration@example.com")
})
test("register, then login", async ({ page }) => {
await testRegistration(page, "registration-login@example.com")
await logout(page)
await testLogin(page, "registration-login@example.com")
})
test("register, cancel, register", async ({ page }) => {
await page.goto("Registration")
let popupPromise = page.waitForEvent("popup")
await page.getByText(/sign (up|in) with ory/i).click()
let popup = await popupPromise
await rejectOidcLogin(popup)
await expect(page.getByText("login rejected request")).toBeVisible()
popupPromise = page.waitForEvent("popup")
await page.getByText(/continue/i).click()
popup = await popupPromise
await performOidcLogin(popup, "register-reject-then-accept@example.com")
await page.waitForURL("Home")
expect(popup.isClosed()).toBeTruthy()
await expect(page.getByText("Welcome back")).toBeVisible()
})
})
test.describe("Login", () => {
test("login twice", async ({ page }) => {
await testLogin(page, "login@example.com")
await logout(page)
await testLogin(page, "login@example.com")
})
test("login, then register", async ({ page }) => {
await testLogin(page, "login-registration@example.com")
await logout(page)
await testRegistration(page, "login-registration@example.com")
})
test("login, cancel, login", async ({ page }) => {
await page.goto("Login")
let popupPromise = page.waitForEvent("popup")
await page.getByText(/sign (up|in) with ory/i).click()
let popup = await popupPromise
await rejectOidcLogin(popup)
await expect(page.getByText("login rejected request")).toBeVisible()
popupPromise = page.waitForEvent("popup")
await page.getByText(/sign in with ory/i).click()
popup = await popupPromise
await performOidcLogin(popup, "login-reject-then-accept@example.com")
await page.waitForURL("Home")
expect(popup.isClosed()).toBeTruthy()
await expect(page.getByText("Welcome back")).toBeVisible()
})
})