Сравнение 1: класс страницы
🟡 Selenium POM (урок 11)
# pages/login_page.py
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
class LoginPage:
USERNAME = (By.ID, "user-name")
PASSWORD = (By.ID, "password")
LOGIN = (By.ID, "login-button")
def __init__(self, driver):
self.driver = driver
def login(self, u, p):
wait = WebDriverWait(self.driver, 10)
wait.until(EC.visibility_of_element_located(self.USERNAME)).send_keys(u)
self.driver.find_element(*self.PASSWORD).send_keys(p)
self.driver.find_element(*self.LOGIN).click()
🟢 Playwright POM
# pages/login_page.py
from playwright.sync_api import Page
class LoginPage:
def __init__(self, page: Page):
self.page = page
self.username = page.get_by_placeholder("Username")
self.password = page.get_by_placeholder("Password")
self.login_btn = page.get_by_role("button", name="Login")
def login(self, u, p):
self.username.fill(u)
self.password.fill(p)
self.login_btn.click()
Сравнение 2: фикстуры драйвера/страницы
🟡 Selenium (conftest.py)
@pytest.fixture(scope="class")
def driver():
d = webdriver.Chrome()
d.implicitly_wait(5)
yield d
d.quit()
🟢 Playwright (плагин)
# фикстура page уже есть —
# создание/закрытие и изоляция включены
def test_x(page):
page.goto("/")
Сравнение 3: отладка падений
🟡 Selenium
# скриншот при падении — вручную в фикстуре/хуке
driver.save_screenshot("fail.png")
🟢 Playwright
# из коробки
pytest --tracing=retain-on-failure \
--screenshot=only-on-failure \
--video=retain-on-failure
⚠️ Сравнение — про подход; в проекте используйте принятый инструмент.