Files
blog.pyaqa.ru/tests/e2e/test_example.py
Sergey Vanyushkin 1f6e13fbd5 feat(tests): add E2E tests with pytfm framework
- Add pytfm workspace dependency to tests and types groups

- Create E2E test example using pytfm API and page objects

- Add BlogHomePage and BlogAPI test classes

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-05-02 23:31:27 +03:00

58 lines
1.6 KiB
Python

"""Example E2E test using pytfm framework.
This module demonstrates how to use pytfm for testing
the blog application.
"""
from __future__ import annotations
import pytest
from playwright.async_api import async_playwright
from pytfm.api import APIClient
from pytfm.web import BasePage
class BlogHomePage(BasePage):
"""Page object for the blog home page."""
path = "/"
async def get_posts(self) -> list[str]:
"""Get list of post titles on the page."""
posts = await self.page.query_selector_all('[data-testid="post-title"]')
return [await post.text_content() or "" for post in posts]
class TestBlogE2E:
"""End-to-end tests for the blog application."""
@pytest.mark.asyncio
async def test_homepage_loads(self) -> None:
"""Test that homepage loads successfully."""
async with async_playwright() as p:
browser = await p.chromium.launch()
page = await browser.new_page()
home_page = BlogHomePage(page, "http://localhost:8000")
await home_page.open()
assert await home_page.is_visible('data-testid="nav-logo"')
await browser.close()
class TestBlogAPI:
"""API tests for the blog application."""
@pytest.mark.asyncio
async def test_get_posts(self) -> None:
"""Test GET /api/v1/posts endpoint."""
async with APIClient("http://localhost:8000") as client:
response = await client.get("/api/v1/posts")
assert response.status_code == 200
assert response.is_success
data = response.json()
assert isinstance(data, list)