Skip to content

Commit 2b4f56f

Browse files
Adding more POMs for compartment 1.
Altering the login and database connection functions to use environment variables
1 parent 899ac66 commit 2b4f56f

File tree

9 files changed

+111
-64
lines changed

9 files changed

+111
-64
lines changed

pages/active_batch_list_page.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ def __init__(self, page: Page):
1212
self.batch_split_by_filter = self.page.locator("#splitByFilter")
1313
self.screening_centre_filter = self.page.locator("#screeningCentreFilter")
1414
self.count_filter = self.page.locator("#countFilter")
15-
# self.td = self.page.locator("td")
16-
17-
# def filter_td(self, filter):
18-
# self.td.
1915

2016
def enter_id_filter(self, search_text: str):
2117
self.id_filter.click()

pages/create_a_plan_page.py

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

3-
class CreateaPlan:
3+
class CreateAPlan:
44
def __init__(self, page: Page):
55
self.page = page
66
# Call and Recall - page links

pages/login_page.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
from playwright.sync_api import Page
1+
import os
22

3+
from playwright.sync_api import Page
4+
from utils.user_tools import UserTools
5+
from dotenv import load_dotenv
36

47
class BcssLoginPage:
58

@@ -23,6 +26,26 @@ def login(self, username, password):
2326

2427
def login_as_user_bcss401(self):
2528
"""Logs in to bcss as the test user 'BCSS401'"""
26-
self.username.fill("BCSS401")
27-
self.password.fill("changeme")
29+
# Take environment variables from .env
30+
load_dotenv()
31+
# Retrieve and enter username from users.json
32+
user_details = UserTools.retrieve_user("BCSS401")
33+
self.username.fill(user_details["username"])
34+
# Retrieve and enter password from .env file
35+
password = os.getenv("BCSS401_PASS")
36+
self.password.fill(password)
37+
# Click submit button
38+
self.submit_button.click()
39+
40+
def login_as_user_bcss118(self):
41+
"""Logs in to bcss as the test user 'BCSS118'"""
42+
# Take environment variables from .env
43+
load_dotenv()
44+
# Retrieve and enter username from users.json
45+
user_details = UserTools.retrieve_user("BCSS118")
46+
self.username.fill(user_details["username"])
47+
# Retrieve and enter password from .env file
48+
password = os.getenv("BCSS118_PASS")
49+
self.password.fill(password)
50+
# Click submit button
2851
self.submit_button.click()

pages/manage_active_batch_page.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from playwright.sync_api import Page
2+
3+
class ManageActiveBatch:
4+
def __init__(self, page: Page):
5+
self.page = page
6+
# Manage Active Batch - page buttons
7+
self.prepare_button = self.page.get_by_role("button", name="Prepare Batch")
8+
self.retrieve_button = self.page.get_by_role("button", name="Retrieve")
9+
self.confirm_button = self.page.get_by_role("button", name="Confirm Printed")
10+
# Manage Active Batch - page buttons (text)
11+
self.prepare_button_text = self.page.locator('text="Prepare Batch"')
12+
self.retrieve_button_text = self.page.locator('text="Retrieve"')
13+
self.confirm_button_text = self.page.locator('text="Confirm Printed"')
14+
15+
def click_prepare_button(self):
16+
self.prepare_button.click()
17+
18+
def click_retrieve_button(self):
19+
self.retrieve_button.click()
20+
21+
def click_confirm_button(self):
22+
self.confirm_button.click()

requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ pytest-json-report>=1.5.0
44
pypdf>=5.3.0
55
oracledb>=2.5.1
66
pandas>=2.2.3
7+
dotenv~=0.9.9
8+
python-dotenv~=1.0.1
9+
Flask~=3.0.3

tests/Smokescreen/test_compartment_1.py

Lines changed: 26 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -14,50 +14,37 @@
1414
from pages.archived_batch_list_page import *
1515
from pages.navigation_bar_links import *
1616
from pages.subject_screening_page import *
17-
18-
# @pytest.mark.wip2 # Not working at the moment
19-
# def test_prereq():
20-
# database_connection_exec("prereq_check")
21-
22-
# paramater_32 = database_connection_query("select DEFAULT_VALUE from PARAMETERS where PARAM_ID = 32")
23-
# print(f"paramater_32: {paramater_32}")
24-
# if paramater_32[0] != "-1":
25-
# database_connection_query("UPDATE PARAMETERS SET DEFAULT_VALUE = -1 WHERE PARAM_ID = 32")
26-
# database_connection_query("COMMIT")
27-
# paramater_31 = database_connection_query("select DEFAULT_VALUE from PARAMETERS where PARAM_ID = 31")
28-
# print(f"paramater_31: {paramater_31}")
29-
# if paramater_31[0] != "-1":
30-
# database_connection_query("UPDATE PARAMETERS SET DEFAULT_VALUE = -1 WHERE PARAM_ID = 31")
31-
# database_connection_query("COMMIT")
32-
17+
from pages.manage_active_batch_page import *
18+
from pages.invitations_monitoring_page import *
19+
from pages.create_a_plan_page import *
20+
from pages.invitations_plans_page import *
3321

3422
# To Do:
35-
# Create more POM
36-
# Remove as many hard coded timeouts as possible
23+
# Create more POMs
3724
# Add more fail states
3825
# Add more logging to understand what is going on
3926
# Convert import pages * into 1 line
4027
# Move functions to utils
28+
# Remove as many hard coded timeouts as possible
29+
# Create a generic click() function -> this aims to solve an issue where sometimes it thinks it has clicked the element but the page does not change
4130

4231
@pytest.mark.wip
4332
def test_example(page: Page) -> None:
4433
page.goto("/")
4534
BcssLoginPage(page).login_as_user_bcss401()
4635

47-
# 2 - Create plan
36+
# Create plan
4837
MainMenu(page).go_to_call_and_recall_page()
4938
CallAndRecall(page).go_to_planning_and_monitoring_page()
50-
page.get_by_role("link", name="BCS001").click()
51-
page.get_by_role("button", name="Create a Plan").click()
52-
page.get_by_role("link", name="Set all").click()
53-
page.get_by_placeholder("Enter daily invitation rate").fill("1")
54-
page.get_by_role("button", name="Update").click()
55-
page.get_by_role("button", name="Confirm").click()
56-
page.get_by_role("link", name="Set all").click()
57-
page.get_by_role("button", name="Close").click()
58-
page.get_by_role("button", name="Save").click()
59-
page.get_by_placeholder("Enter note").fill("test data")
60-
page.locator("#saveNote").get_by_role("button", name="Save").click()
39+
InvitationsMonitoring(page).go_to_bcss001_invitations_plan_page()
40+
InvitationsPlans(page).go_to_create_a_plan_page()
41+
CreateAPlan(page).click_set_all_button()
42+
CreateAPlan(page).fill_daily_invitation_rate_field("1")
43+
CreateAPlan(page).click_update_button()
44+
CreateAPlan(page).click_confirm_button()
45+
CreateAPlan(page).click_save_button()
46+
CreateAPlan(page).fill_note_field("test data")
47+
CreateAPlan(page).click_saveNote_button()
6148

6249
# Generate Invitations
6350
NavigationBar(page).click_main_menu_link()
@@ -135,21 +122,21 @@ def batch_processing(page: Page, batch_type: str, batch_description: str, latest
135122

136123
# Checks to see if batch is already prepared
137124
page.wait_for_timeout(3000) # Without this timeout prepare_button is always set to false
138-
prepare_button = page.get_by_role("button", name="Prepare Batch").is_visible()
125+
prepare_button = ManageActiveBatch(page).prepare_button_text.is_visible()
139126

140127
#If not prepared it will click on the prepare button
141128
if prepare_button:
142-
page.get_by_role("button", name="Prepare Batch").click()
129+
ManageActiveBatch(page).click_prepare_button()
143130

144-
page.locator('text="Retrieve"').nth(0).wait_for()
131+
ManageActiveBatch(page).retrieve_button_text.nth(0).wait_for()
145132
page.wait_for_timeout(5000) # This 5 second wait is to allow other Retrieve buttons to show as they do not show up at the same time
146133

147134
# This loops through each Retrieve button and clicks each one
148-
for retrieve_button in range (page.get_by_role("button", name="Retrieve").count()):
135+
for retrieve_button in range (ManageActiveBatch(page).retrieve_button.count()):
149136
# Start waiting for the pdf download
150137
with page.expect_download() as download_info:
151138
# Perform the action that initiates download
152-
page.get_by_role("button", name="Retrieve").nth(retrieve_button-1).click()
139+
ManageActiveBatch(page).retrieve_button.nth(retrieve_button-1).click()
153140
download_file = download_info.value
154141
file = download_file.suggested_filename
155142
# Wait for the download process to complete and save the downloaded file in a temp folder
@@ -162,13 +149,13 @@ def batch_processing(page: Page, batch_type: str, batch_description: str, latest
162149
csv_df = csv_Reader(file) # Currently no use in compartment 1, will be necessary for future compartments
163150
os.remove(file) # Deletes the file after extracting the necessary data
164151

165-
page.locator('text="Confirm Printed"').nth(0).wait_for()
152+
ManageActiveBatch(page).confirm_button_text.nth(0).wait_for()
166153
page.wait_for_timeout(1000) # This 1 second wait is to allow other Confirm printed buttons to show as they do not show up at the same time
167154

168155
# This loops through each Confirm printed button and clicks each one
169-
for _ in range (page.get_by_role("button", name="Confirm Printed").count()):
156+
for _ in range (ManageActiveBatch(page).confirm_button.count()):
170157
page.on("dialog", lambda dialog: dialog.accept())
171-
page.get_by_role("button", name="Confirm Printed").nth(0).click()
158+
ManageActiveBatch(page).confirm_button.nth(0).click()
172159
page.wait_for_timeout(1000)
173160

174161
# Add wait for batch successfully archived
@@ -193,7 +180,7 @@ def pdf_Reader(file: str):
193180
for split_text in text:
194181
if "NHS No" in split_text:
195182
# If a string is found containing "NHS No" only digits are stored into nhs_no
196-
nhs_no = res = "".join([ele for ele in split_text if ele.isdigit()])
183+
nhs_no = "".join([ele for ele in split_text if ele.isdigit()])
197184
break
198185
return nhs_no
199186

tests/test_login_to_bcss.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import os
2+
3+
from dotenv import load_dotenv
14
from playwright.sync_api import Page, expect
25
from pages.login_page import BcssLoginPage
36

@@ -16,9 +19,13 @@ def test_login_to_bcss_with_invalid_username(page: Page) -> None:
1619
"""
1720
Confirms that a user with a valid password, and invalid username, can NOT log in to bcss
1821
"""
19-
# Enter a valid password with an invalid username and click 'sign in' button
22+
# Take environment variables from .env
23+
load_dotenv()
24+
# Set an invalid username
2025
username = "BCSSZZZ"
21-
password = "changeme"
26+
# Retrieve valid password from .env file
27+
password = os.getenv("BCSS_PASS")
28+
# Enter valid password with an invalid username and click 'sign in' button
2229
BcssLoginPage(page).login(username, password)
2330
# Confirm error message is displayed
2431
expect(page.locator("body")).to_contain_text("Incorrect username or password.")

users.json

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
{
2-
"_comment": "This file can be used to store data on users for your application, and then pulled through using the utils.user_tools UserTools utility. The documentation for this utility explains how this file is read.",
3-
"Example User 1": {
4-
"username": "EXAMPLE_USER1",
5-
"roles": ["Example Role A"]
6-
},
7-
"Example User 2": {
8-
"username": "EXAMPLE_USER2",
9-
"roles": ["Example Role B", "Example Role C"]
10-
}
2+
"_comment": "This file can be used to store data on users for your application, and then pulled through using the utils.user_tools UserTools utility. The documentation for this utility explains how this file is read.",
3+
4+
"BCSS401": {
5+
"username": "BCSS401",
6+
"roles": [
7+
"Hub Manager State Registered, Midlands and North West"
8+
]
9+
},
10+
"BCSS118": {
11+
"username": "BCSS118",
12+
"roles": [
13+
"Screening Centre Manager for Wolverhampton, Midlands and North West"
14+
]
15+
}
1116
}

utils/oracle.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
import oracledb
2+
import os
3+
from dotenv import load_dotenv
24

35
def database_connection_exec(procedure: str): # To use when "exec xxxx" (stored procedures)
4-
un = 'MPI'
5-
cs = 'bcss-oracle-bcss-bcss-18680.cqger35bxcwy.eu-west-2.rds.amazonaws.com/TSTBCS01'
6-
pw = 'g0blin'
6+
load_dotenv()
7+
un = os.getenv("un")
8+
cs = os.getenv("cs")
9+
pw = os.getenv("pw")
710

811
with oracledb.connect(user=un, password=pw, dsn=cs) as connection:
912
with connection.cursor() as cursor:
1013
for r in cursor.callproc(procedure):
1114
print(r)
1215

1316
def database_connection_query(sql: str): # To use when "select a from b"
14-
un = 'MPI'
15-
cs = 'bcss-oracle-bcss-bcss-18680.cqger35bxcwy.eu-west-2.rds.amazonaws.com/TSTBCS01'
16-
pw = 'g0blin'
17+
load_dotenv()
18+
un = os.getenv("un")
19+
cs = os.getenv("cs")
20+
pw = os.getenv("pw")
1721

1822
with oracledb.connect(user=un, password=pw, dsn=cs) as connection:
1923
with connection.cursor() as cursor:

0 commit comments

Comments
 (0)