Skip to content

Commit 19a27dd

Browse files
author
Victor Soares
committed
Added support and pages for approved users list test
1 parent 50212f1 commit 19a27dd

File tree

5 files changed

+87
-2
lines changed

5 files changed

+87
-2
lines changed

pages/bcss_home_page.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from playwright.sync_api import Page
1+
from playwright.sync_api import Page, expect
22

33

44
class BcssHomePage:
@@ -13,6 +13,8 @@ def __init__(self, page: Page):
1313
self.refresh_alerts_link = self.page.get_by_role("link", name="Refresh alerts")
1414
self.user_guide_link = self.page.get_by_role("link", name="User guide")
1515
self.help_link = self.page.get_by_role("link", name="Help")
16+
# Bowel Cancer Screening System header
17+
self.bowel_cancer_screening_system_header = self.page.locator("#ntshAppTitle")
1618

1719
def click_sub_menu_link(self):
1820
self.sub_menu_link.click()
@@ -38,6 +40,9 @@ def click_user_guide_link(self):
3840
def click_help_link(self):
3941
self.help_link.click()
4042

43+
def bowel_cancer_screening_system_header_is_displayed(self):
44+
expect(self.bowel_cancer_screening_system_header).to_contain_text("Bowel Cancer Screening System")
45+
4146

4247
class MainMenu:
4348
def __init__(self, page: Page):

pages/login_failure_screen.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from playwright.sync_api import Page,expect
2+
3+
class LoginFailureScreen:
4+
def __init__(self, page: Page):
5+
self.page = page
6+
# Login failure message
7+
self.login_failure_msg = self.page.get_by_role("heading", name="Sorry, BCSS is unavailable")
8+
9+
def verify_login_failure_screen(self):
10+
expect(self.login_failure_msg).to_be_visible()

tests/Smokescreen/my_pages.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@
1515
from pages.fit_test_kits_page import *
1616
from pages.log_devices_page import *
1717
from pages.log_out_page import *
18+
from pages.login_failure_screen import *
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import pytest
2+
from playwright.sync_api import Page
3+
from my_pages import *
4+
from utils.oracle import OracleDB
5+
6+
#Login successfully with bcss401 user
7+
#Login successfully with bcss118 user
8+
#Add bcss401 user to approved users list table
9+
#Login successfully with bcss401 user
10+
#Login unsuccessfully with bcss118 user and verify expected error message
11+
#Delete bcss401 user from approved users list table
12+
13+
@pytest.fixture(scope="function", autouse=True)
14+
def before_test(page: Page):
15+
"""
16+
This fixture confirms that users can log in successfully in to BCSS whilst the approved users list is empty
17+
"""
18+
# Log in to BCSS as bcss401 user, then log out
19+
BcssLoginPage(page).login_as_user("BCSS401")
20+
BcssHomePage(page).bowel_cancer_screening_system_header_is_displayed()
21+
NavigationBar(page).click_log_out_link()
22+
Logout(page).verify_log_out_page()
23+
# Log in to BCSS as bcss118 user, then log out
24+
BcssLoginPage(page).login_as_user("BCSS118")
25+
BcssHomePage(page).bowel_cancer_screening_system_header_is_displayed()
26+
NavigationBar(page).click_log_out_link()
27+
Logout(page).verify_log_out_page()
28+
29+
yield
30+
OracleDB().delete_all_users_from_approved_users_table()
31+
32+
@pytest.mark.wip3
33+
def test_only_users_on_approved_can_login_to_bcss(page: Page) -> None:
34+
# Add bcss401 user to approved users list table
35+
OracleDB().populate_ui_approved_users_table("BCSS401")
36+
# BCSS401 user successfully logs in to BCSS whilst on the approved list
37+
BcssLoginPage(page).login_as_user("BCSS401")
38+
BcssHomePage(page).bowel_cancer_screening_system_header_is_displayed()
39+
# BCSS401 user logs out
40+
NavigationBar(page).click_log_out_link()
41+
Logout(page).verify_log_out_page()
42+
43+
# BCSS118 user fails to logs in to BCSS as they are not on the approved list
44+
BcssLoginPage(page).login_as_user("BCSS118")
45+
# Verify relevant error message is displayed
46+
LoginFailureScreen(page).verify_login_failure_screen()
47+
page.close()
48+
# Delete all users from approved users list table
49+
# Delete function is called with the yield command in the fixture to make sure it clears the table even when the test fails

utils/oracle.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ def populate_ui_approved_users_table(self, user: str): # To add users to the UI_
4444
try:
4545
print("Attempting to write to the db...")
4646
cursor = conn.cursor()
47-
cursor.execute(f'INSERT INTO "UI_APPROVED_USERSf" (OE_USER_CODE) VALUES ({user})')
47+
cursor.execute(f"INSERT INTO UI_APPROVED_USERS (OE_USER_CODE) VALUES ('{user}')")
48+
conn.commit()
4849
print(conn.version, "DB write successful!")
4950
except Exception as dbWriteError:
5051
print(f"Failed to write to the DB! with write error {dbWriteError}")
@@ -54,6 +55,25 @@ def populate_ui_approved_users_table(self, user: str): # To add users to the UI_
5455
except Exception as connectionError:
5556
print(f"Failed to connect to the DB! with connection error {connectionError}")
5657

58+
def delete_all_users_from_approved_users_table(self): # To remove all users from the UI_APPROVED_USERS table
59+
try:
60+
print("Attempting DB connection...")
61+
conn = oracledb.connect(user=self.user, password=self.password, dsn=self.dns)
62+
print(conn.version, "DB connection successful!")
63+
try:
64+
print("Attempting to delete users from DB table...")
65+
cursor = conn.cursor()
66+
cursor.execute(f"DELETE FROM UI_APPROVED_USERS WHERE OE_USER_CODE is not null")
67+
conn.commit()
68+
print(conn.version, "DB table values successfully deleted!")
69+
except Exception as dbValuesDeleteError:
70+
print(f"Failed to delete values from the DB table! with data deletion error {dbValuesDeleteError}")
71+
finally:
72+
if conn is not None:
73+
conn.close()
74+
except Exception as connectionError:
75+
print(f"Failed to connect to the DB! with connection error {connectionError}")
76+
5777
# The following two functions are commented out as they are not used currently, but may be needed in future compartments
5878

5979
# def execute_stored_procedure(self, procedure: str): # To use when "exec xxxx" (stored procedures)

0 commit comments

Comments
 (0)