11from playwright .sync_api import Page , expect
22from pages .base_page import BasePage
3+ from utils .table_util import TableUtils
34
45
56class CreateAPlanPage (BasePage ):
@@ -23,6 +24,20 @@ def __init__(self, page: Page):
2324 self .save_note_button = self .page .locator ("#saveNote" ).get_by_role (
2425 "button" , name = "Save"
2526 )
27+ # Create A Plan Table Locators
28+ self .weekly_invitation_rate_field_on_table = self .page .locator (
29+ "#invitationPlan > tbody > tr:nth-child(1) > td.input.border-right.dt-type-numeric > input"
30+ )
31+ self .invitations_sent_value = self .page .locator (
32+ "tbody tr:nth-child(1) td:nth-child(8)"
33+ )
34+
35+ self .resulting_position_value = self .page .locator (
36+ "#invitationPlan > tbody > tr:nth-child(1) > td:nth-child(9)"
37+ )
38+
39+ # Initialize TableUtils for different tables
40+ self .create_a_plan_table = TableUtils (page , "#invitationPlan" )
2641
2742 def click_set_all_button (self ) -> None :
2843 """Clicks the Set all button to set all values"""
@@ -59,3 +74,106 @@ def click_save_note_button(self) -> None:
5974 def verify_create_a_plan_title (self ) -> None :
6075 """Verifies the Create a Plan page title"""
6176 self .bowel_cancer_screening_page_title_contains_text ("View a plan" )
77+
78+ def verify_weekly_invitation_rate_for_weeks (
79+ self , start_week : int , end_week : int , expected_weekly_rate : str
80+ ) -> None :
81+ """
82+ Verifies that the weekly invitation rate is correctly calculated and displayed for the specified range of weeks.
83+
84+ Args:
85+ start_week (int): The starting week of the range.
86+ end_week (int): The ending week of the range.
87+ expected_weekly_rate (str): The expected weekly invitation rate.
88+ """
89+
90+ # Verify the rate for the starting week
91+ weekly_invitation_rate_selector = "#invitationPlan > tbody > tr:nth-child(2) > td.input.border-right.dt-type-numeric > input"
92+ self .page .wait_for_selector (weekly_invitation_rate_selector )
93+ weekly_invitation_rate = self .page .locator (
94+ weekly_invitation_rate_selector
95+ ).input_value ()
96+
97+ assert (
98+ weekly_invitation_rate == expected_weekly_rate
99+ ), f"Expected weekly invitation rate '{ expected_weekly_rate } ' for week { start_week } but got '{ weekly_invitation_rate } '"
100+ # Verify the rate for the specified range of weeks
101+ for week in range (start_week + 1 , end_week + 1 ):
102+ weekly_rate_locator = f"#invitationPlan > tbody > tr:nth-child({ week + 2 } ) > td.input.border-right.dt-type-numeric > input"
103+
104+ # Wait for the element to be available
105+ self .page .wait_for_selector (weekly_rate_locator )
106+
107+ # Get the input value safely
108+ weekly_rate_element = self .page .locator (weekly_rate_locator )
109+ assert (
110+ weekly_rate_element .is_visible ()
111+ ), f"Week { week } rate element not visible"
112+
113+ # Verify the value
114+ actual_weekly_rate = weekly_rate_element .input_value ()
115+ assert (
116+ actual_weekly_rate == expected_weekly_rate
117+ ), f"Week { week } invitation rate should be '{ expected_weekly_rate } ', but found '{ actual_weekly_rate } '"
118+
119+ # Get the text safely
120+ # Get the frame first
121+ frame = self .page .frame (
122+ url = "https://bcss-bcss-18680-ddc-bcss.k8s-nonprod.texasplatform.uk/invitation/plan/23159/23162/create"
123+ )
124+
125+ # Ensure the frame is found before proceeding
126+ assert frame , "Frame not found!"
127+
128+ # Now locate the input field inside the frame and get its value
129+ weekly_invitation_rate_selector = "#invitationPlan > tbody > tr:nth-child(2) > td.input.border-right.dt-type-numeric > input"
130+ weekly_invitation_rate = frame .locator (
131+ weekly_invitation_rate_selector
132+ ).input_value ()
133+
134+ # Assert the expected value
135+ assert (
136+ weekly_invitation_rate == expected_weekly_rate
137+ ), f"Week 2 invitation rate should be '{ expected_weekly_rate } ', but found '{ weekly_invitation_rate } '"
138+
139+ def increment_invitation_rate_and_verify_changes (self ) -> None :
140+ """
141+ Increments the invitation rate by 1, then verifies that both the
142+ 'Invitations Sent' has increased by 1 and 'Resulting Position' has decreased by 1.
143+ """
144+ # Capture initial values before any changes
145+ initial_invitations_sent = int (self .invitations_sent_value .inner_text ().strip ())
146+ initial_resulting_position = int (
147+ self .resulting_position_value .inner_text ().strip ()
148+ )
149+
150+ # Increment the invitation rate
151+ current_rate = int (
152+ self .create_a_plan_table .get_cell_value ("Invitation Rate" , 1 )
153+ )
154+ new_rate = str (current_rate + 1 )
155+ self .weekly_invitation_rate_field_on_table .fill (new_rate )
156+ self .page .keyboard .press ("Tab" )
157+
158+ # Wait dynamically for updates
159+ expect (self .invitations_sent_value ).to_have_text (
160+ str (initial_invitations_sent + 1 )
161+ )
162+ expect (self .resulting_position_value ).to_have_text (
163+ str (initial_resulting_position + 1 )
164+ )
165+
166+ # Capture updated values
167+ updated_invitations_sent = int (self .invitations_sent_value .inner_text ().strip ())
168+ updated_resulting_position = int (
169+ self .resulting_position_value .inner_text ().strip ()
170+ )
171+
172+ # Assert changes
173+ assert (
174+ updated_invitations_sent == initial_invitations_sent + 1
175+ ), f"Expected Invitations Sent to increase by 1. Was { initial_invitations_sent } , now { updated_invitations_sent } ."
176+
177+ assert (
178+ updated_resulting_position == initial_resulting_position + 1
179+ ), f"Expected Resulting Position to increase by 1. Was { initial_resulting_position } , now { updated_resulting_position } ."
0 commit comments