Skip to content

Commit b598dee

Browse files
Nir.TalNir.Tal
Nir.Tal
authored and
Nir.Tal
committed
feat: add test id
1 parent 6edcbed commit b598dee

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

pages/login_page.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
class LoginPage:
1414
def __init__(self, page: Page):
1515
self.page = page
16-
self.user_name_field = page.locator("[data-test='username']")
17-
self.password_field = page.locator("[data-test='password']")
18-
self.login_button = page.locator("[data-test='login-button']")
19-
self.error_message = page.locator("[data-test='error']")
16+
self.user_name_field = page.get_by_test_id("username")
17+
self.password_field = page.get_by_test_id("password")
18+
self.login_button = page.get_by_test_id("login-button")
19+
self.error_message = page.get_by_test_id("error")
2020

2121
@allure.step("Login with username {username} and password {password}")
2222
def login(self, username: Union[User, str], password: str):

tests/conftest.py

+13-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from _pytest.fixtures import FixtureRequest, SubRequest
77
from _pytest.nodes import Item
88
from axe_playwright_python.sync_playwright import Axe
9-
from playwright.sync_api import Page
9+
from playwright.sync_api import Page, Playwright
1010

1111
from utilities.axe_helper import AxeHelper
1212
from utilities.constants import Constants
@@ -85,17 +85,26 @@ def browser_context_args(
8585

8686

8787
@pytest.fixture(scope="session")
88-
def browser_type_launch_args(browser_type_launch_args: Dict):
88+
def browser_type_launch_args(browser_type_launch_args: Dict, playwright: Playwright):
8989
"""Fixture to set browser launch arguments.
9090
91+
This fixture updates the browser launch arguments to start the browser maximized
92+
and sets the test ID attribute for selectors.
93+
9194
Args:
92-
browser_type_launch_args (dict): Browser type launch arguments.
95+
browser_type_launch_args (Dict): Original browser type launch arguments.
96+
playwright (Playwright): The Playwright instance.
9397
9498
Returns:
95-
dict: Updated browser type launch arguments.
99+
Dict: Updated browser type launch arguments with maximized window setting.
100+
101+
Note:
102+
This fixture has a session scope, meaning it will be executed once per test session.
103+
96104
See Also:
97105
https://playwright.dev/python/docs/api/class-browsertype#browser-type-launch
98106
"""
107+
playwright.selectors.set_test_id_attribute("data-test")
99108
return {**browser_type_launch_args, "args": ["--start-maximized"]}
100109

101110

tests/inventory_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ class TestInventory:
1010
"browser_context_args", [User.STANDARD_USER], indirect=True
1111
)
1212
def test_inventory_page(self, browser_context_args, page: Page):
13-
expect(page.locator("//span[@class='title']")).to_have_text("Products")
13+
expect(page.get_by_test_id("title")).to_have_text("Products")

0 commit comments

Comments
 (0)