From 0c7de47618718ca4d377635a2ee3bf6988318f90 Mon Sep 17 00:00:00 2001 From: Carmelo Seminara <89209493+carme-10@users.noreply.github.com> Date: Fri, 13 Nov 2026 18:30:35 +0100 Subject: [PATCH] feat: contact test --- pages/contact_page.py | 10 ++++++++++ tests/features/contact.feature | 7 +++++++ tests/test_contact_bdd.py | 19 +++++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 pages/contact_page.py create mode 100644 tests/features/contact.feature create mode 100644 tests/test_contact_bdd.py diff --git a/pages/contact_page.py b/pages/contact_page.py new file mode 100644 index 0000000..419221f --- /dev/null +++ b/pages/contact_page.py @@ -0,0 +1,10 @@ +from playwright.sync_api import Page + + +class ContactPage: + def __init__(self, page: Page) -> None: + self.page = page + self.email = page.get_by_test_id("contact-email") + + def goto(self) -> None: + self.page.goto("/contact") \ No newline at end of file diff --git a/tests/features/contact.feature b/tests/features/contact.feature new file mode 100644 index 0000000..ddffa2e --- /dev/null +++ b/tests/features/contact.feature @@ -0,0 +1,7 @@ +Feature: Contact + + Background: + Given I am on the contact page + + Scenario: Correct email + Then I see the email "student.office@example.com" diff --git a/tests/test_contact_bdd.py b/tests/test_contact_bdd.py new file mode 100644 index 0000000..5794d79 --- /dev/null +++ b/tests/test_contact_bdd.py @@ -0,0 +1,19 @@ +from playwright.sync_api import Page, expect +from pytest_bdd import given, parsers, scenarios, then, when + +from pages.contact_page import ContactPage + +scenarios("features/contact.feature") + + +@given("I am on the contact page", target_fixture="contact_page") +def open_contact_page(page: Page) -> ContactPage: + contact_page = ContactPage(page) + contact_page.goto() + return contact_page + + +@then(parsers.parse('I see the email "{text}"')) +def see_email(page: Page, text: str) -> None: + contact_page = ContactPage(page) + expect(contact_page.email).to_have_text(text)