Skip to main content

Persona DSL - Framework for implementing Screenplay pattern in Python tests

Project description

persona-dsl: фреймворк для автотестов на Python

persona-dsl — это библиотека для E2E-, API- и интеграционных тестов, построенная вокруг Screenplay-подхода и тесно связанная с runtime/discovery/tooling, которые использует TaaS.

Установка

pip install persona-dsl
python -m playwright install --with-deps

Базовая модель

Публичный слой строится вокруг:

  • Persona
  • Ops
  • Step
  • CombinedStep
  • алиасов Action, Fact, Expectation, Goal
  • Page и Element
from __future__ import annotations

from persona_dsl import Goal
from persona_dsl.ops.web import Click, CurrentPath, Fill, NavigateTo
from persona_dsl.expectations.generic import IsEqualTo
from persona_dsl.pages import Button, Page, TextField


class LoginPage(Page):
    expected_path = "/login"

    username = TextField(name="username", accessible_name="Логин")
    password = TextField(name="password", accessible_name="Пароль")
    submit_button = Button(name="submit_button", accessible_name="Войти")


def test_login_flow(persona) -> None:
    login_page = LoginPage()

    persona.make(
        NavigateTo(login_page),
        Fill(login_page.username, "admin"),
        Fill(login_page.password, "secret"),
        Click(login_page.submit_button),
    )

    current_path = persona.get(CurrentPath())
    persona.check(current_path, IsEqualTo("/dashboard"))

Страницы и элементы

Page наследуется от Element и добавляет:

  • expected_path
  • default_query_params
  • build_url(base_url=None)

Element поддерживает:

  • declarative class attrs
  • aria_ref
  • multi-strategy resolve
  • .using(...), .robust(), .resolve_or(...)
  • ElementList
  • Table и declarative table DSL

VirtualPage используется для динамической in-memory модели страницы.

Генерация page object'ов

PageGenerator и GeneratePageObject генерируют declarative page objects.

Для обычных generated страниц текущий контракт такой:

  • committed generated file не содержит def __init__(...)
  • не содержит self.add_element(...)
  • не содержит self.add_element_list(...)
  • хранит expected_path, snapshot/screenshot paths и aria_ref
  • для повторяющихся анонимных контролов может выпускать declarative group, доступную по индексу как page.otp_kod[0]
  • внутри таких групп item-level aria_ref может намеренно отсутствовать, чтобы resolve шёл через container scope и role + index
  • поддерживает merge/regeneration
  • использует footer-секции unresolved/archived diagnostics

CLI:

persona-page-gen --url http://localhost:8080 --output tests/pages/home_page.py

Из теста:

from persona_dsl.ops.web import GeneratePageObject, NavigateTo


def test_generate_home_page(persona) -> None:
    persona.make(NavigateTo("/"))
    persona.make(
        GeneratePageObject(
            class_name="HomePage",
            output_path="tests/pages/home_page.py",
            wait_for_state="networkidle",
            sleep_before=1,
        )
    )

Таблицы

Актуальный table contract включает:

  • Column(...)
  • TableColumn
  • table.filters.*
  • row.elements.*
  • row.element(column)
  • row.value(column)
  • row.details
  • table.select_all_checkbox

Generator использует этот DSL и для обычных, и для сложных таблиц.

Конфигурация

Конфигурация проекта живёт в config/{env}.yaml и tests/conftest.py. Для запуска:

pytest --env=dev tests/

Если нужен локальный генератор страниц или шаблонный проект, ориентируйтесь на example_template.

Где смотреть дальше

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

persona_dsl-2026.4.10rc132.tar.gz (365.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

persona_dsl-2026.4.10rc132-py3-none-any.whl (454.8 kB view details)

Uploaded Python 3

File details

Details for the file persona_dsl-2026.4.10rc132.tar.gz.

File metadata

  • Download URL: persona_dsl-2026.4.10rc132.tar.gz
  • Upload date:
  • Size: 365.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for persona_dsl-2026.4.10rc132.tar.gz
Algorithm Hash digest
SHA256 3d84be15cd16ae34180736adf7434e3c55c19ec48ba1fa2a373b657051189a8a
MD5 e28fb7a875cba48031124c1b3c9743b3
BLAKE2b-256 14a340f362a18716c6d2a70c9befc6495072baff21f5e2acd92d084ec524a9d2

See more details on using hashes here.

File details

Details for the file persona_dsl-2026.4.10rc132-py3-none-any.whl.

File metadata

File hashes

Hashes for persona_dsl-2026.4.10rc132-py3-none-any.whl
Algorithm Hash digest
SHA256 9216de86655b7c5987d351a9313bf0e2e41707054382b2a89502118cf22e2944
MD5 01ae39050aeb6fee1e3daaa6ede8202b
BLAKE2b-256 834e1ed07d3127bc3062d853860fa503c48232c7d321341c0c99f29eadb131b0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page