-
Notifications
You must be signed in to change notification settings - Fork 0
/
conftest.py
370 lines (310 loc) · 15.8 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
import pytest
# from pages.add_vaccines_page import *
from pages.settings_page import *
from pages.site_vaccine_batches_page import *
from pages.vaccines_page import *
from pages.site_vaccine_batches_confirm_page import *
from pages.site_vaccines_check_and_confirm_page import *
from pages.home_page import *
from pages.login_page import *
from pages.nhs_signin_page import *
from pages.appointments_page import *
from pages.patient_details_page import *
from pages.find_a_patient_page import *
from pages.choose_vaccines_page import *
from pages.assess_patient_page import *
from pages.vaccinator_location_page import *
from pages.record_consent_page import *
from pages.record_vaccinated_page import *
from pages.vaccines_choose_site_page import *
from pages.vaccines_choose_vaccine_page import *
from pages.site_vaccines_add_batch_page import *
from pages.vaccines_view_products_page import *
from init_helpers import *
from datetime import datetime, timedelta
from allure_commons.types import LabelType
import logging
# Define marks
pytest.mark.login = pytest.mark.mark(login=True)
pytest.mark.logout = pytest.mark.mark(logout=True)
pytest.mark.smoke = pytest.mark.mark(smoke=True)
pytest.mark.appointments = pytest.mark.mark(appointments=True)
pytest.mark.consent = pytest.mark.mark(consent=True)
pytest.mark.findpatient = pytest.mark.mark(findpatient=True)
pytest.mark.createpatient = pytest.mark.mark(createpatient=True)
pytest.mark.recordvaccine = pytest.mark.mark(recordvaccine=True)
pytest.mark.addvaccine = pytest.mark.mark(addvaccine=True)
pytest.mark.addbatches = pytest.mark.mark(addbatches=True)
pytest.mark.reports = pytest.mark.mark(reports=True)
@pytest.fixture(scope='function', autouse=True)
def report_browser_version(request):
browser_version = get_browser_version()
allure.dynamic.label(LabelType.TAG, browser_version)
if config["browser"] == "mobile":
logging.info(config["browser"].upper() + f" browser version for " + config["device"] + f" is : {browser_version}")
else:
logging.info(config["browser"].upper() + f" browser version is : {browser_version}")
def format_nhs_number(nhs_number):
# Use regular expressions to insert spaces in the phone number
formatted_number = re.sub(r"(\d{3})(\d{3})(\d{4})", r"\1 \2 \3", nhs_number)
return formatted_number
# @pytest.fixture(scope='function')
# def playwright_helper(request):
# helper = PlaywrightHelper(get_working_directory(), config)
# def teardown():
# try:
# helper.quit_browser()
# except Exception as e:
# print(f"An error occurred during teardown: {e}")
# raise
# request.addfinalizer(teardown)
# return helper
# Fixture for site parameter
@pytest.fixture(params=["NEELIMA HOUSE", "ALBERT HOUSE", "ST JOHN'S HOUSE"])
def site(request):
return request.param
# Fixture for care_model parameter
@pytest.fixture(params=["Vaccination Centre", "Hospital Hub", "Care Home", "Home Of Housebound Patient", "Off-site Outreach Event"])
def care_model(request):
return request.param
# Fixture for covid vaccination types parameter
@pytest.fixture(params=["Comirnaty Original/Omicron BA.4-5", "Comirnaty 30 Omicron XBB.1.5", "Comirnaty 3 Omicron XBB.1.5", "Comirnaty 10 Omicron XBB.1.5", "Spikevax XBB.1.5"])
def covid_vaccine_type(request):
return request.param
# Fixture for navigating and logging in
@pytest.fixture(scope='function')
def navigate_and_login(request, navigate_to_ravs):
if config["browser"] == "mobile":
if check_navbar_toggle_exists_without_waiting():
click_navbar_toggler()
if check_logout_button_exists_without_waiting():
click_logout_button()
click_login_button()
emailAddress = "[email protected]"
enter_email_address(emailAddress)
password = config["credentials"]["ravs_password"]
enter_password(password)
click_nhs_signin_button()
# Fixture for navigating to RAVS
@pytest.fixture(scope='function')
def navigate_to_ravs(request):
if config["browser"] == "mobile":
if check_navbar_toggle_exists_without_waiting():
click_navbar_toggler()
if check_logout_button_exists_without_waiting():
click_logout_button()
url = get_app_url(config["test_environment"])
navigate_to_ravs_login_page(url)
return True
# Fixture for logging in and navigating to find a patient
@pytest.fixture(scope='function')
def login_and_navigate_to_find_a_patient(request):
if config["browser"] == "mobile":
if check_nav_link_bar_toggle_exists():
click_nav_link_bar_toggler()
click_find_a_patient_nav_link()
# Fixture for logging in and finding a patient by NHS number
@pytest.fixture(scope='function')
def login_and_find_a_patient_by_nhs_number(request, login_and_navigate_to_find_a_patient, nhs_number):
enter_nhs_number(nhs_number)
click_search_for_patient_button()
# Fixture for navigating to appointments open first patient and clicking choose vaccine
@pytest.fixture(scope='function')
def goto_appointments_open_first_patient_and_click_choose_vaccine(request, login_and_navigate_to_appointments_open_first_patient):
click_choose_vaccine_button()
# Fixture for logging out
@pytest.fixture(scope='function')
def logout(request, navigate_and_login):
if config["browser"] == "mobile":
if check_navbar_toggle_exists():
click_navbar_toggler()
attach_screenshot("clicked_navbar_toggler")
click_logout_button()
attach_screenshot("clicked_log_out_button")
def click_find_a_patient_and_search_with_nhs_number(nhs_number):
if config["browser"] == "mobile":
if check_nav_link_bar_toggle_exists():
click_nav_link_bar_toggler()
click_find_a_patient_nav_link()
enter_nhs_number(nhs_number)
click_search_for_patient_button()
attach_screenshot("entered_nhs_number_as" + nhs_number + "_and_clicked_search_for_patient_button")
def click_on_patient_name(name):
click_on_patient_name_search_result(name)
wait_for_element_to_disappear(PAGE_LOADING_ELEMENT)
def click_find_a_patient_top_nav_bar():
click_find_a_patient_nav_link()
wait_for_element_to_disappear(PAGE_LOADING_ELEMENT)
def click_manage_users_top_nav_bar():
click_manage_users_nav_link()
wait_for_element_to_disappear(PAGE_LOADING_ELEMENT)
def click_on_patient_search_result_and_click_choose_vaccine(name, vaccine):
wait_for_element_to_disappear(PAGE_LOADING_ELEMENT)
immunisation_history_records = get_count_of_immunisation_history_records(vaccine)
click_choose_vaccine_button()
wait_for_element_to_disappear(PAGE_LOADING_ELEMENT)
attach_screenshot("clicked_on_patient_" + name + "_and_clicked_choose_vaccine_button")
return immunisation_history_records
def choose_vaccine_and_vaccine_type_for_patient(site, vaccine, vaccine_type):
wait_for_element_to_disappear(PAGE_LOADING_ELEMENT)
click_delivery_team_radiobutton(site)
click_vaccine_radiobutton(vaccine)
click_vaccine_type_radiobutton(vaccine_type)
click_continue_to_assess_patient_button()
attach_screenshot("selected_vaccine_" + vaccine + "_and_" + vaccine_type + "_and_clicked_continue_button")
def choose_vaccine_and_vaccine_type_only(site, vaccine, vaccine_type):
wait_for_element_to_disappear(PAGE_LOADING_ELEMENT)
click_delivery_team_radiobutton(site)
click_vaccine_radiobutton(vaccine)
click_vaccine_type_radiobutton(vaccine_type)
attach_screenshot("selected_vaccine_" + vaccine + "_and_" + vaccine_type)
def check_vaccine_and_batch_exists_in_site_api_request(site, vaccine, vaccineType, batch_number, expirydate):
pass
def check_vaccine_and_batch_exists_in_site(site, vaccine, vaccine_type, batch_number, expiry_date):
if config["browser"] == "mobile":
if check_nav_link_bar_toggle_exists():
click_nav_link_bar_toggler()
click_vaccines_nav_link()
check_site_vaccine_type_has_active_batch(site, vaccine, vaccine_type, batch_number, expiry_date)
def check_site_vaccine_type_has_active_batch(site, vaccine, vaccine_type, batch_number, expiry_date):
# If the site does NOT currently have the vaccine, then add a site vaccine
# Adding a vaccine also adds a vaccine type and an active batch, so we don't need to do further checks
if not check_vaccine_has_been_added(site, vaccine, True):
add_site_vaccine(site, vaccine, vaccine_type, batch_number, expiry_date)
return True
# If the site has the vaccine, but does NOT currently have the vaccine type, then add a site vaccine
# Adding a vaccine type is the same process as adding a vaccine for a site
if not check_vaccine_type_has_been_added(site, vaccine, vaccine_type, False):
add_site_vaccine(site, vaccine, vaccine_type, batch_number, expiry_date)
return True
# Open the vaccine type to see the batches.
# If the batch does NOT currently exist, add a batch
# This adds an active batch, so we don't need to do further checks
click_view_product(site, vaccine_type)
if not check_batch_number_and_expiry_date_exists(batch_number, expiry_date, True):
add_vaccine_type_batch(batch_number, expiry_date)
return True
# If we get this far, the batch does exists but is currently INACTIVE
# This reactivates the batch
if not check_batch_number_is_active_with_date(batch_number, expiry_date, True):
click_reactivate_batch_link(batch_number)
click_reactivate_batch_confirmation_button()
def add_site_vaccine(site, vaccine, vaccine_type, batch_number, expiry_date):
# vaccines_page
click_add_vaccine_button()
# vaccines_choose_site_page
enter_site_name(site)
select_site_from_list(site)
click_continue_to_add_vaccine_button()
# choose_vaccine_page
click_vaccine_radiobutton_on_add_vaccine_screen(vaccine)
click_vaccine_type_radiobutton_on_add_vaccine_screen(vaccine_type)
click_continue_to_add_batch_button()
# vaccines_add_batch_page
enter_batch_number(batch_number)
enter_expiry_date(expiry_date)
click_continue_to_confirm_batch_details_button()
# vaccines_check_and_confirm_page
click_confirm_add_vaccine_and_batch_button()
def add_vaccine_type_batch(batch_number, expiry_date):
click_add_batch_link()
enter_batch_number(batch_number)
enter_expiry_date(expiry_date)
click_continue_to_confirm_batch_details_button()
# vaccines_check_and_confirm_page
click_confirm_add_vaccine_and_batch_button()
def assess_patient_with_details_and_click_continue_to_consent(eligible_decision, eligibility_type, staff_role, assessing_clinician, due_date, assessment_date, legal_mechanism, assessment_outcome, assessment_comments, eligibility_assessment_no_vaccine_given_reason=None):
if eligible_decision.lower() == 'yes':
click_eligible_yes_radiobutton()
if check_eligibility_type_is_enabled():
select_eligibility_type(eligibility_type)
if eligibility_type == "Healthcare workers":
select_staff_role(staff_role)
if eligibility_type == "Pregnancy" and due_date:
enter_due_date(due_date)
attach_screenshot("clicked_eligibility_yes_and_selected_eligibility_type")
else:
click_eligible_no_radiobutton()
attach_screenshot("clicked_patient_not_eligible_radiobutton")
set_assessment_date(assessment_date)
click_legal_mechanism(legal_mechanism)
logging.debug("Assess clinician to select is: " + assessing_clinician)
logging.debug("Assess legal mechanism is: " + legal_mechanism)
select_assessing_clinician_with_name_and_council(assessing_clinician)
if assessment_outcome.lower() == "give vaccine":
click_give_vaccine_radiobutton()
attach_screenshot("clicked_patient_give_vaccine_radio_button")
else:
click_vaccine_not_given_radiobutton()
select_assessment_no_vaccination_reason(eligibility_assessment_no_vaccine_given_reason)
attach_screenshot("select_patient_not_given_vaccine_after_assessing")
click_save_and_return_button_on_assessment_screen()
attach_screenshot("clicked_save_and_return_on_assessment_screen")
enter_comments_for_assessing_patient(assessment_comments)
click_continue_to_record_consent_button()
attach_screenshot("clicked_continue_to_record_consent_button")
def record_consent_details_and_click_continue_to_vaccinate(consent_decision, consent_given_by, person_consenting_name, relationship_to_patient, consent_clinician, legal_mechanism, no_consent_reason=None):
attach_screenshot("before_selecting_consent_clinician")
logging.debug("Consent clinician to select is: " + consent_clinician)
logging.debug("Consent legal mechanism is: " + legal_mechanism)
if (legal_mechanism) != "Patient Group Direction (PGD)":
select_consent_clinician_with_name_and_council(consent_clinician)
if consent_decision.lower() == 'yes':
click_yes_to_consent()
select_consent_given_by_from_dropdown(consent_given_by)
if consent_given_by != "Patient (informed consent)":
enter_person_consenting_details(person_consenting_name)
enter_relationship_to_patient(relationship_to_patient)
click_continue_to_vaccinate_button()
attach_screenshot("clicked_continue_to_vaccinate_button")
else:
click_no_to_consent()
if no_consent_reason is not None:
select_reason_for_no_consent(no_consent_reason)
attach_screenshot("patient_decided_to_not_consent")
click_save_and_return_button_on_record_consent_page()
attach_screenshot("patient_decided_to_not_consent_saved_and_returned")
def enter_vaccine_details_and_click_continue_to_check_and_confirm(vaccinate_decision, care_model, vaccination_date, vaccine, vaccine_type2, vaccination_site, batch_number, batch_expiry_date, dose_amount, vaccinator, vaccination_comments, legal_mechanism, no_vaccination_reason=None):
if vaccinate_decision.lower() == 'yes':
click_yes_vaccinated_radiobutton()
click_vaccine_type(vaccine_type2)
set_vaccination_date(vaccination_date)
click_care_model_option(care_model)
if care_model == "Care home":
enter_care_home_details("WHITESTONES CARE HOME")
logging.debug("Vaccination legal mechanism is: " + legal_mechanism)
logging.debug("Vaccinator to select is: " + vaccinator)
if (legal_mechanism) != "Patient Group Direction (PGD)":
select_vaccinator_name_and_council(vaccinator)
enter_vaccination_comments(vaccination_comments)
select_vaccination_site(vaccination_site)
batch_number_to_select = batch_number.upper() + " - " + batch_expiry_date
select_batch_number(batch_number_to_select)
enter_dose_amount_value(dose_amount)
if click_continue_to_check_and_confirm_screen_button() == True:
vaccination_date = format_date(vaccination_date, "safari")
set_vaccination_date(vaccination_date)
select_batch_number(batch_number_to_select)
click_continue_to_check_and_confirm_screen_button()
else:
click_not_vaccinated_radiobutton()
if no_vaccination_reason is not None:
select_reason_for_no_vaccination(no_vaccination_reason)
click_save_and_return_button_on_record_vaccinated_page
attach_screenshot("patient_decided_to_not_vaccinate")
click_save_and_return_button_on_record_vaccinated_page()
attach_screenshot("patient_decided_to_not_vaccinate_saved_and_returned")
def navigate_and_login_with_username(username):
if config["browser"] == "mobile":
if check_navbar_toggle_exists_without_waiting():
click_navbar_toggler()
if check_logout_button_exists_without_waiting():
click_logout_button()
url = get_app_url(config["test_environment"])
navigate_to_ravs_login_page(url)
click_login_button()
emailAddress = username
enter_email_address(emailAddress)
password = config["credentials"]["ravs_password"]
enter_password(password)
click_nhs_signin_button()