diff --git a/pages/profile_page.py b/pages/profile_page.py new file mode 100644 index 0000000..c68b80d --- /dev/null +++ b/pages/profile_page.py @@ -0,0 +1,12 @@ +from playwright.sync_api import Page + + +class ProfilePage: + def __init__(self, page: Page) -> None: + self.page = page + self.name = page.get_by_test_id("profile-name") + self.student_id = page.get_by_test_id("profile-student-id") + self.degree_course = page.get_by_test_id("profile-degree") + + def goto(self): + self.page.goto("/profile") diff --git a/tests/features/student_id.feature b/tests/features/student_id.feature new file mode 100644 index 0000000..76f96c0 --- /dev/null +++ b/tests/features/student_id.feature @@ -0,0 +1,14 @@ +Feature: StudentId + + # Background: + + Scenario: Correct student id + Given I log in as "mario" with password "password123" + When I goto profile page + Then I see the student ID "1000012345" + + Scenario: Wrong student id + Given I log in as "luigi" with password "password123" + When I goto profile page + Then I cannot enter profile page + And I do not see any student ID diff --git a/tests/test_student_id.py b/tests/test_student_id.py new file mode 100644 index 0000000..1c58135 --- /dev/null +++ b/tests/test_student_id.py @@ -0,0 +1,36 @@ +from playwright.sync_api import Page, expect +from pytest_bdd import given, parsers, scenarios, then, when + +from pages.login_page import LoginPage +from pages.profile_page import ProfilePage + +scenarios("features/student_id.feature") + + +@given(parsers.parse('I log in as "{username}" with password "{password}"')) +def login_as_user(page: Page, username: str, password: str) -> None: + login_page = LoginPage(page) + login_page.goto() + login_page.login(username, password) + + +@when("I goto profile page", target_fixture="profile_page") +def goto_profile_page(page: Page) -> ProfilePage: + profile_page = ProfilePage(page) + profile_page.goto() + return profile_page + + +@then(parsers.parse('I see the student ID "{student_id}"')) +def see_student_id(profile_page: ProfilePage, student_id: str) -> None: + expect(profile_page.student_id).to_have_text(student_id) + + +@then("I do not see any student ID") +def dont_see_student_id(profile_page: ProfilePage) -> None: + expect(profile_page.student_id).to_have_count(0) + + +@then("I cannot enter profile page") +def dont_see_student_id(page: Page) -> None: + expect(page).not_to_have_url("/profile")