Skip to content

Commit bd9c1d0

Browse files
committed
Refactored code based on code review comments
1 parent 07f9543 commit bd9c1d0

17 files changed

+70
-64
lines changed
Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,25 @@
11
import os
22

33
from playwright.sync_api import Page
4-
from utils.user_tools import UserTools
5-
from dotenv import load_dotenv
64

75

8-
class BcssLoginPage:
6+
class CognitoLoginPage:
97

108
def __init__(self, page: Page):
119
self.page = page
12-
self.page.goto("/")
1310
self.username = page.get_by_role("textbox", name="Username")
1411
self.password = page.get_by_role("textbox", name="Password")
1512
self.submit_button = page.get_by_role("button", name="submit")
16-
load_dotenv() # Take environment variables from .env
1713

18-
def login_as_user(self, username: str) -> None:
14+
def login_as_user(self, username: str, password: str) -> None:
1915
"""Logs in to bcss with specified user credentials
2016
Args:
2117
username (str) enter a username that exists in users.json
18+
password (str) the password for the user provided
2219
"""
2320
# Retrieve and enter username from users.json
24-
user_details = UserTools.retrieve_user(username)
25-
self.username.fill(user_details["username"])
21+
self.username.fill(username)
2622
# Retrieve and enter password from .env file
27-
password = os.getenv("BCSS_PASS")
2823
self.password.fill(password)
2924
# Click Submit
3025
self.submit_button.click()

tests/test_bowel_scope_page.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
import pytest
22
from playwright.sync_api import Page, expect
3-
43
from pages.bcss_home_page import MainMenu
5-
from pages.login_page import BcssLoginPage
4+
from utils.user_tools import UserTools
65

76

87
@pytest.fixture(scope="function", autouse=True)
98
def before_each(page: Page):
109
"""
11-
Before every test is executed, this fixture logs in to BCSS as a test user and navigates to the bowel scope page
10+
Before every test is executed, this fixture logs in to BCSS as the specified user and navigates to the bowel scope page
1211
"""
1312
# Log in to BCSS
14-
BcssLoginPage(page).login_as_user("BCSS401")
13+
UserTools.user_login(page, "Hub Manager State Registered")
1514

1615
# Go to bowel scope page
1716
MainMenu(page).go_to_bowel_scope_page()

tests/test_call_and_recall_page.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
import pytest
22
from playwright.sync_api import Page, expect
3-
43
from pages.bcss_home_page import MainMenu
5-
from pages.login_page import BcssLoginPage
4+
from utils.user_tools import UserTools
65

76

87
@pytest.fixture(scope="function", autouse=True)
98
def before_each(page: Page):
109
"""
11-
Before every test is executed, this fixture logs in to BCSS as a test user and navigates to the call and recall page
10+
Before every test is executed, this fixture logs in to BCSS as the specified user and navigates to the call and recall page
1211
"""
1312
# Log in to BCSS
14-
BcssLoginPage(page).login_as_user("BCSS401")
13+
UserTools.user_login(page, "Hub Manager State Registered")
1514

1615
# Go to call and recall page
1716
MainMenu(page).go_to_call_and_recall_page()

tests/test_communications_production_page.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import pytest
22
from playwright.sync_api import Page, expect
3-
from pages.login_page import BcssLoginPage
3+
from utils.user_tools import UserTools
44
from pages.bcss_home_page import MainMenu
55

66

77
@pytest.fixture(scope="function", autouse=True)
88
def before_each(page: Page):
99
"""
10-
Before every test is executed, this fixture logs in to BCSS as a test user and navigates to the communications
10+
Before every test is executed, this fixture logs in to BCSS as the specified user and navigates to the communications
1111
production page
1212
"""
1313
# Log in to BCSS
14-
BcssLoginPage(page).login_as_user("BCSS401")
14+
UserTools.user_login(page, "Hub Manager State Registered")
1515

1616
# Go to communications production page
1717
MainMenu(page).go_to_communications_production_page()

tests/test_contacts_list_page.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
import pytest
22
from playwright.sync_api import Page, expect
3-
43
from pages.bcss_home_page import MainMenu
5-
from pages.login_page import BcssLoginPage
4+
from utils.user_tools import UserTools
65

76

87
@pytest.fixture(scope="function", autouse=True)
98
def before_each(page: Page):
109
"""
11-
Before every test is executed, this fixture logs in to BCSS as a test user and navigates to the contacts list page
10+
Before every test is executed, this fixture logs in to BCSS as the specified user and navigates to the contacts list page
1211
"""
1312
# Log in to BCSS
14-
BcssLoginPage(page).login_as_user("BCSS401")
13+
UserTools.user_login(page, "Hub Manager State Registered")
1514

1615
# Go to contacts list page
1716
MainMenu(page).go_to_contacts_list_page()

tests/test_download_page.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
import pytest
22
from playwright.sync_api import Page, expect
3-
43
from pages.bcss_home_page import MainMenu
5-
from pages.login_page import BcssLoginPage
4+
from utils.user_tools import UserTools
65

76

87
@pytest.fixture(scope="function", autouse=True)
98
def before_each(page: Page):
109
"""
11-
Before every test is executed, this fixture logs in to BCSS as a test user and navigates to the download page
10+
Before every test is executed, this fixture logs in to BCSS as the specified user and navigates to the download page
1211
"""
1312
# Log in to BCSS
14-
BcssLoginPage(page).login_as_user("BCSS401")
13+
UserTools.user_login(page, "Hub Manager State Registered")
1514

1615
# Go to download page
1716
MainMenu(page).go_to_download_page()

tests/test_fit_test_kits_page.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
import pytest
22
from playwright.sync_api import Page, expect
3-
43
from pages.bcss_home_page import MainMenu
5-
from pages.login_page import BcssLoginPage
4+
from utils.user_tools import UserTools
65

76

87
@pytest.fixture(scope="function", autouse=True)
98
def before_each(page: Page):
109
"""
11-
Before every test is executed, this fixture logs in to BCSS as a test user and navigates to the
10+
Before every test is executed, this fixture logs in to BCSS as the specified user and navigates to the
1211
fit test kits page
1312
"""
1413
# Log in to BCSS
15-
BcssLoginPage(page).login_as_user("BCSS401")
14+
UserTools.user_login(page, "Hub Manager State Registered")
1615

1716
# Go to fit test kits page
1817
MainMenu(page).go_to_fit_test_kits_page()

tests/test_gfobt_test_kits_page.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
import pytest
22
from playwright.sync_api import Page, expect
3-
43
from pages.bcss_home_page import MainMenu
5-
from pages.login_page import BcssLoginPage
4+
from utils.user_tools import UserTools
65

76

87
@pytest.fixture(scope="function", autouse=True)
98
def before_each(page: Page):
109
"""
11-
Before every test is executed, this fixture logs in to BCSS as a test user and navigates to the
10+
Before every test is executed, this fixture logs in to BCSS as the specified user and navigates to the
1211
gfob test kits page
1312
"""
1413
# Log in to BCSS
15-
BcssLoginPage(page).login_as_user("BCSS401")
14+
UserTools.user_login(page, "Hub Manager State Registered")
1615

1716
# Go to gFOBT test kits page
1817
MainMenu(page).go_to_gfob_test_kits_page()

tests/test_home_page_links.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import pytest
22
from playwright.sync_api import Page, expect
3-
from pages.login_page import BcssLoginPage
3+
from utils.user_tools import UserTools
44
from pages.bcss_home_page import BcssHomePage
55
from utils.date_time_utils import DateTimeUtils
66

77

88
@pytest.fixture(scope="function", autouse=True)
99
def before_each(page: Page):
1010
"""
11-
Before every test is executed, this fixture logs in to BCSS as a test user and results in the home page
11+
Before every test is executed, this fixture logs in to BCSS as the specified user and results in the home page
1212
being displayed
1313
"""
1414
# Log in to BCSS
15-
BcssLoginPage(page).login_as_user("BCSS401")
15+
UserTools.user_login(page, "Hub Manager State Registered")
1616

1717

1818
@pytest.mark.smoke

tests/test_login_to_bcss.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
from playwright.sync_api import Page, expect
2-
3-
from pages.login_page import BcssLoginPage
2+
from utils.user_tools import UserTools
43

54

65
def test_successful_login_to_bcss(page: Page) -> None:
76
"""
87
Confirms that a user with valid credentials can log in to bcss
98
"""
109
# Enter a valid username and password and click 'sign in' button
11-
BcssLoginPage(page).login_as_user("BCSS401")
10+
UserTools.user_login(page, "Hub Manager State Registered")
11+
1212
# Confirm user has successfully signed in and is viewing the bcss homepage
1313
expect(page.locator("#ntshAppTitle")).to_contain_text("Bowel Cancer Screening System")

0 commit comments

Comments
 (0)