11import logging
2- from re import A
32import pytest
43from playwright .sync_api import Page , expect
5- from pages import screening_subject_search
4+ from pages import login , screening_subject_search
65from pages .logout .log_out_page import LogoutPage
76from pages .base_page import BasePage
87from pages .screening_subject_search import subject_screening_search_page
2726 get_subjects_with_multiple_notes ,
2827 get_supporting_notes ,
2928)
29+ import pandas as pd
3030
3131
3232@pytest .mark .regression
3333@pytest .mark .note_tests
3434def test_subject_does_not_have_an_additional_care_note (
35- page : Page , general_properties : dict
35+ page : Page , general_properties : dict , login_as
3636) -> None :
3737 """
3838 Test to check if I can identify if a subject does not have a Additional Care note
3939 """
4040 logging .info (
4141 f"Starting test: Verify subject does not have a '{ general_properties ["additional_care_note_name" ]} '."
4242 )
43- logging .info ("Logging in as 'ScreeningAssistant at BCS02'." )
44- # user login
45- logging .info ("Logging in as 'ScreeningAssistant at BCS02'." )
46- UserTools .user_login (page , "ScreeningAssistant at BCS02" )
47-
48- # Navigate to the Screening Subject Search Page
49- logging .info ("Navigating to the Screening Subject Search Page." )
50- BasePage (page ).go_to_screening_subject_search_page ()
43+ # Use the login fixture
44+ login_as ("ScreeningAssistant at BCS02" )
5145
5246 # Search for the subject by NHS Number.")
5347 subjects_df = get_subjects_by_note_count (
@@ -77,7 +71,7 @@ def test_subject_does_not_have_an_additional_care_note(
7771@pytest .mark .regression
7872@pytest .mark .note_tests
7973def test_add_an_additional_care_note_for_a_subject_without_a_note (
80- page : Page , general_properties : dict
74+ page : Page , general_properties : dict , login_as
8175) -> None :
8276 """
8377 Test to add a note for a subject without an additional care note.
@@ -86,12 +80,8 @@ def test_add_an_additional_care_note_for_a_subject_without_a_note(
8680 logging .info (
8781 "Starting test: Add a '{general_properties['additional_care_note_name']}' for a subject without a note."
8882 )
89- logging .info ("Logging in as 'Team Leader at BCS01'." )
90- UserTools .user_login (page , "Team Leader at BCS01" )
91-
92- # Navigate to the Screening Subject Search Page
93- logging .info ("Navigating to the Screening Subject Search Page." )
94- BasePage (page ).go_to_screening_subject_search_page ()
83+ # Use the login fixture
84+ login_as ("Team Leader at BCS01" )
9585
9686 # Get a subject with no notes of the specified type
9787 subjects_df = get_subjects_by_note_count (
@@ -144,27 +134,30 @@ def test_add_an_additional_care_note_for_a_subject_without_a_note(
144134 logging .info (
145135 f"Retrieved notes for Screening Subject ID: { screening_subject_id } , Type ID: { type_id } ."
146136 )
147- # Verify title and note match the provided values
148- logging .info (
149- f"Verifying that the title and note match the provided values for type_id: { type_id } ."
137+ verify_note_content_matches_expected (
138+ notes_df , note_title , note_text , nhs_no , type_id
150139 )
151- assert (
152- notes_df ["title" ].iloc [0 ].strip () == note_title
153- ), f"Title does not match. Expected: '{ note_title } ', Found: '{ notes_df ['title' ].iloc [0 ].strip ()} '."
154- assert (
155- notes_df ["note" ].iloc [0 ].strip () == note_text
156- ), f"Note does not match. Expected: '{ note_text } ', Found: '{ notes_df ['note' ].iloc [0 ].strip ()} '."
140+ # # Verify title and note match the provided values
141+ # logging.info(
142+ # f"Verifying that the title and note match the provided values for type_id: {type_id}."
143+ # )
144+ # assert (
145+ # notes_df["title"].iloc[0].strip() == note_title
146+ # ), f"Title does not match. Expected: '{note_title}', Found: '{notes_df['title'].iloc[0].strip()}'."
147+ # assert (
148+ # notes_df["note"].iloc[0].strip() == note_text
149+ # ), f"Note does not match. Expected: '{note_text}', Found: '{notes_df['note'].iloc[0].strip()}'."
157150
158- logging .info (
159- f"Verification successful: Additional care note added for the subject with NHS Number: { nhs_no } . "
160- f"Title and note matched the provided values. Title: '{ note_title } ', Note: '{ note_text } '."
161- )
151+ # logging.info(
152+ # f"Verification successful: Additional care note added for the subject with NHS Number: {nhs_no}. "
153+ # f"Title and note matched the provided values. Title: '{note_title}', Note: '{note_text}'."
154+ # )
162155
163156
164157@pytest .mark .regression
165158@pytest .mark .note_tests
166159def test_add_additional_care_note_for_subject_with_existing_note (
167- page : Page , general_properties : dict
160+ page : Page , general_properties : dict , login_as
168161) -> None :
169162 """
170163 Test to add an additional care note for a subject who already has an existing note.
@@ -173,12 +166,7 @@ def test_add_additional_care_note_for_subject_with_existing_note(
173166 logging .info (
174167 "Starting test: Add an additional care note for a subject who already has additional care note."
175168 )
176- logging .info ("Logging in as 'Team Leader at BCS01'." )
177- UserTools .user_login (page , "Team Leader at BCS01" )
178-
179- # Navigate to the Screening Subject Search Page
180- logging .info ("Navigating to the Screening Subject Search Page." )
181- BasePage (page ).go_to_screening_subject_search_page ()
169+ login_as ("Team Leader at BCS01" )
182170
183171 # Get a subject with existing additional care notes
184172 subjects_df = get_subjects_by_note_count (
@@ -211,8 +199,8 @@ def test_add_additional_care_note_for_subject_with_existing_note(
211199 logging .info (f"Filling in notes: '{ note_text } '." )
212200 SubjectEventsNotes (page ).fill_notes (note_text )
213201
214- # Dismiss dialog and update notes
215- logging .info ("Dismissing dialog and clicking 'Update Notes'." )
202+ # Accept dialog and update notes
203+ logging .info ("Accept dialog and clicking 'Update Notes'." )
216204 SubjectEventsNotes (page ).accept_dialog_and_update_notes ()
217205 # Get supporting notes for the subject
218206 logging .info (
@@ -246,20 +234,13 @@ def test_add_additional_care_note_for_subject_with_existing_note(
246234@pytest .mark .regression
247235@pytest .mark .note_tests
248236def test_identify_subject_with_additional_care_note (
249- page : Page , general_properties : dict
237+ page : Page , general_properties : dict , login_as
250238) -> None :
251239 """
252240 Test to identify if a subject has an Additional Care note.
253241 """
254242 logging .info ("Starting test: Verify subject has an additional care note." )
255- logging .info ("Logging in as 'ScreeningAssistant at BCS02'." )
256- # user login
257- logging .info ("Logging in as 'ScreeningAssistant at BCS02'." )
258- UserTools .user_login (page , "ScreeningAssistant at BCS02" )
259-
260- # Navigate to the Screening Subject Search Page
261- logging .info ("Navigating to the Screening Subject Search Page." )
262- BasePage (page ).go_to_screening_subject_search_page ()
243+ login_as ("ScreeningAssistant at BCS02" )
263244
264245 # Search for the subject by NHS Number.")
265246 subjects_df = get_subjects_by_note_count (
@@ -281,19 +262,14 @@ def test_identify_subject_with_additional_care_note(
281262
282263@pytest .mark .regression
283264@pytest .mark .note_tests
284- def test_view_active_additional_care_note (page : Page , general_properties : dict ) -> None :
265+ def test_view_active_additional_care_note (
266+ page : Page , general_properties : dict , login_as
267+ ) -> None :
285268 """
286269 Test to verify if an active Additional Care note is visible for a subject.
287270 """
288271 logging .info ("Starting test: Verify subject has an additional care note." )
289- logging .info ("Logging in as 'ScreeningAssistant at BCS02'." )
290- # user login
291- logging .info ("Logging in as 'ScreeningAssistant at BCS02'." )
292- UserTools .user_login (page , "ScreeningAssistant at BCS02" )
293-
294- # Navigate to the Screening Subject Search Page
295- logging .info ("Navigating to the Screening Subject Search Page." )
296- BasePage (page ).go_to_screening_subject_search_page ()
272+ login_as ("ScreeningAssistant at BCS02" )
297273
298274 # Search for the subject by NHS Number.")
299275 subjects_df = get_subjects_by_note_count (
@@ -352,19 +328,13 @@ def test_view_active_additional_care_note(page: Page, general_properties: dict)
352328@pytest .mark .regression
353329@pytest .mark .note_tests
354330def test_update_existing_additional_care_note (
355- page : Page , general_properties : dict
331+ page : Page , general_properties : dict , login_as
356332) -> None :
357333 """
358334 Test to verify if an existing Additional Care note can be updated successfully.
359335 """
360336 logging .info ("Starting test: Verify subject has an additional care note." )
361- # user login
362- logging .info ("Logging in as 'TeamLeader at BCS01'." )
363- UserTools .user_login (page , "Team Leader at BCS01" )
364-
365- # Navigate to the Screening Subject Search Page
366- logging .info ("Navigating to the Screening Subject Search Page." )
367- BasePage (page ).go_to_screening_subject_search_page ()
337+ login_as ("Team Leader at BCS01" )
368338 # Search for the subject by NHS Number.")
369339 subjects_df = get_subjects_by_note_count (
370340 general_properties ["additional_care_note_type_value" ],
@@ -437,21 +407,15 @@ def test_update_existing_additional_care_note(
437407@pytest .mark .regression
438408@pytest .mark .note_tests
439409def test_remove_existing_additional_care_note (
440- page : Page , general_properties : dict
410+ page : Page , general_properties : dict , login_as
441411) -> None :
442412 """
443413 Test to verify if an existing Additional Care note can be removed for a subject with one Additional Care note.
444414 """
445415 logging .info (
446416 "Starting test: Verify if an existing Additional Care note can be removed for a subject with one Additional Care note"
447417 )
448- # user login
449- logging .info ("Logging in as 'Team Leader at BCS01'." )
450- UserTools .user_login (page , "Team Leader at BCS01" )
451-
452- # Navigate to the Screening Subject Search Page
453- logging .info ("Navigating to the Screening Subject Search Page." )
454- BasePage (page ).go_to_screening_subject_search_page ()
418+ login_as ("Team Leader at BCS01" )
455419
456420 # Search for the subject by NHS Number.")
457421 subjects_df = get_subjects_by_note_count (
@@ -502,7 +466,7 @@ def test_remove_existing_additional_care_note(
502466@pytest .mark .regression
503467@pytest .mark .note_tests
504468def test_remove_existing_additional_care_note_for_subject_with_multiple_notes (
505- page : Page , general_properties : dict
469+ page : Page , general_properties : dict , login_as
506470) -> None :
507471 """
508472 Test to verify if an existing Additional Care note can be removed for a subject with multiple Additional Care notes.
@@ -511,12 +475,7 @@ def test_remove_existing_additional_care_note_for_subject_with_multiple_notes(
511475 logging .info (
512476 "Starting test: Remove an additional care note for a subject who already has multiple additional care note."
513477 )
514- logging .info ("Logging in as 'Team Leader at BCS01'." )
515- UserTools .user_login (page , "Team Leader at BCS01" )
516-
517- # Navigate to the Screening Subject Search Page
518- logging .info ("Navigating to the Screening Subject Search Page." )
519- BasePage (page ).go_to_screening_subject_search_page ()
478+ login_as ("Team Leader at BCS01" )
520479
521480 # Get a subject with multiple additional care notes
522481 subjects_df = get_subjects_with_multiple_notes (
@@ -618,3 +577,40 @@ def test_remove_existing_additional_care_note_for_subject_with_multiple_notes(
618577 logging .info (
619578 "Verification successful: Removed note is present in the obsolete list."
620579 )
580+
581+
582+ def verify_note_content_matches_expected (
583+ notes_df : pd .DataFrame ,
584+ expected_title : str ,
585+ expected_note : str ,
586+ nhs_no : str ,
587+ type_id : int ,
588+ ) -> None :
589+ """
590+ Verifies that the title and note fields from the DataFrame match the expected values.
591+
592+ :param notes_df: DataFrame containing the actual note data.
593+ :param expected_title: Expected note title.
594+ :param expected_note: Expected note content.
595+ :param nhs_no: NHS Number of the subject (for logging).
596+ :param type_id: Note type ID (for logging).
597+ """
598+ logging .info (
599+ f"Verifying that the title and note match the provided values for type_id: { type_id } ."
600+ )
601+
602+ actual_title = notes_df ["title" ].iloc [0 ].strip ()
603+ actual_note = notes_df ["note" ].iloc [0 ].strip ()
604+
605+ assert actual_title == expected_title , (
606+ f"Title does not match. Expected: '{ expected_title } ', "
607+ f"Found: '{ actual_title } '."
608+ )
609+ assert actual_note == expected_note , (
610+ f"Note does not match. Expected: '{ expected_note } ', " f"Found: '{ actual_note } '."
611+ )
612+
613+ logging .info (
614+ f"Verification successful: Additional care note added for the subject with NHS Number: { nhs_no } . "
615+ f"Title and note matched the provided values. Title: '{ expected_title } ', Note: '{ expected_note } '."
616+ )
0 commit comments