Skip to content

サンプルコード

Playwrightのサンプルコードです。

ログイン画面

nameおよびpasswordを入力するログイン画面について、「ログイン」画面押下後に「ログイン成功」画面に遷移する仕様のテストです:

js
// @ts-check
import { test, expect } from "@playwright/test";

test("login success", async ({ page }) => {
  await page.goto("http://localhost:8080/login");

  await expect(page).toHaveTitle("First Go web");

  await page.locator("#name").fill("nob");
  await page.locator("#password").fill("passwd");

  await page.getByRole("button", { name: "ログイン" }).click();

  await expect(page).toHaveTitle("Me");
  await expect(page.getByText("ログイン完了")).toBeVisible();
});