1
1
from asyncio import sleep
2
+ from logging .handlers import RotatingFileHandler
2
3
import secrets
3
4
import string
4
5
from pytest_bdd import given , when , then , scenarios , scenario
7
8
from pages .home_page import *
8
9
from pages .nhs_signin_page import *
9
10
from pages .reports_check_and_confirm_page import *
11
+ from pages .reports_creating_report_page import *
10
12
from pages .reports_data_selection_page import *
11
13
from pages .reports_date_range_selection_page import *
12
14
import logging
19
21
20
22
scenarios (f'{ features_directory } /reports.feature' )
21
23
22
- logging .basicConfig (level = logging .INFO )
23
- logger = logging .getLogger (__name__ )
24
+ logger = logging .getLogger ()
25
+ logger .setLevel (logging .DEBUG ) # Or any other level like INFO, WARNING, etc.
26
+
27
+ # Create a rotating file handler to log to tox.log
28
+ log_handler = RotatingFileHandler ('tox.log' , maxBytes = 1024 * 1024 , backupCount = 3 ) # Log rotation (optional)
29
+ log_handler .setFormatter (logging .Formatter ('%(asctime)s - %(levelname)s - %(message)s' ))
30
+
31
+ # Add the handler to the logger
32
+ logger .addHandler (log_handler )
33
+
34
+ @pytest .fixture (scope = "session" , autouse = True )
35
+ def setup_logging ():
36
+ # You can add logging setup here if needed
37
+ logger .info ("Logging setup complete" )
38
+ yield
39
+ logger .info ("Test session complete" )
24
40
25
41
@pytest .fixture (scope = 'function' )
26
42
def shared_data ():
@@ -155,11 +171,11 @@ def I_click_today_date_range_and_click_continue(shared_data):
155
171
@when (parse ('I select the vaccine type {vaccineType} and click continue' ))
156
172
def I_select_vaccinetype_and_click_continue (shared_data , vaccineType ):
157
173
click_vaccine_check_box_on_reports_page (vaccineType )
158
- attach_screenshot ("click_ " + vaccineType .lower () + "_check_box_on_reports_page" )
159
- logging .info ("click_ " + vaccineType .lower () + "_check_box_on_reports_page" )
174
+ attach_screenshot ("clicked_ " + vaccineType .lower () + "_check_box_on_reports_page" )
175
+ logging .info ("clicked_ " + vaccineType .lower () + "_check_box_on_reports_page" )
160
176
click_continue_to_reports_select_site_button ()
161
- attach_screenshot ("click_continue_to_reports_select_site_button " )
162
- logging .info ("click_continue_to_reports_select_site_button " )
177
+ attach_screenshot ("clicked_continue_to_reports_select_site_button " )
178
+ logging .info ("clicked_continue_to_reports_select_site_button " )
163
179
164
180
@then ("the choose sites page should be displayed" )
165
181
def the_choose_sites_page_should_be_displayed ():
@@ -170,11 +186,11 @@ def the_choose_sites_page_should_be_displayed():
170
186
@when (parse ('I select the site {site} and click continue' ))
171
187
def I_select_vaccinetype_and_click_continue (shared_data , site ):
172
188
check_site_check_box (site )
173
- attach_screenshot ("click_ " + site .lower () + "_check_box_on_reports_page" )
174
- logging .info ("click_ " + site .lower () + "_check_box_on_reports_page" )
189
+ attach_screenshot ("clicked_ " + site .lower () + "_check_box_on_reports_page" )
190
+ logging .info ("clicked_ " + site .lower () + "_check_box_on_reports_page" )
175
191
click_continue_to_reports_select_data_button ()
176
- attach_screenshot ("click_continue_to_reports_select_data_button " )
177
- logging .info ("click_continue_to_reports_select_data_button " )
192
+ attach_screenshot ("clicked_continue_to_reports_select_data_button " )
193
+ logging .info ("clicked_continue_to_reports_select_data_button " )
178
194
179
195
@then ("the choose data page should be displayed and all data options should be checked by default" )
180
196
def the_choose_data_page_should_be_displayed ():
@@ -190,11 +206,36 @@ def the_choose_data_page_should_be_displayed():
190
206
@when (parse ('I click continue on the data page' ))
191
207
def I_select_data_and_click_continue (shared_data ):
192
208
click_continue_to_reports_select_data_button ()
193
- attach_screenshot ("click_continue_to_reports_select_data_button " )
194
- logging .info ("click_continue_to_reports_select_data_button " )
209
+ attach_screenshot ("clicked_continue_to_reports_select_data_button " )
210
+ logging .info ("clicked_continue_to_reports_select_data_button " )
195
211
196
212
@then ("the check and confirm page should be displayed" )
197
213
def the_check_and_confirm_page_should_be_displayed ():
198
214
assert check_reports_change_data_button_exists () == True
199
215
attach_screenshot ("check_reports_change_data_pages_reports_exists" )
200
216
logging .info ("check_reports_change_data_pages_reports_exists" )
217
+
218
+ @when ('I click Confirm and create report button in the check and confirm page' )
219
+ def I_click_confirm_to_generate_report (shared_data ):
220
+ click_continue_to_confirm_and_create_report_button ()
221
+ attach_screenshot ("clicked_continue_to_confirm_and_create_report_button" )
222
+ logging .info ("clicked_continue_to_confirm_and_create_report_button" )
223
+
224
+ @then ("Creating your page element should be displayed and Download Report button should be visible" )
225
+ def the_check_and_confirm_page_should_be_displayed ():
226
+ assert check_reports_download_report_button_exists () == True
227
+ attach_screenshot ("check_reports_change_data_pages_reports_exists" )
228
+ logging .info ("check_reports_change_data_pages_reports_exists" )
229
+
230
+ @when ('I click download report button' )
231
+ def I_click_confirm_to_generate_report (shared_data ):
232
+ shared_data ['report_download_path' ] = click_reports_download_report_button ()
233
+ attach_screenshot ("clicked_reports_download_report_button" )
234
+ logging .info ("clicked_reports_download_report_button" )
235
+
236
+
237
+ @then ("the report is downloaded successfully" )
238
+ def the_report_is_downloaded_successfully (shared_data ):
239
+ assert os .path .exists (shared_data ['report_download_path' ]), f"Downloaded file not found: { shared_data ['report_download_path' ]} "
240
+ attach_screenshot ("check_report_downloaded" )
241
+ logger .info ("check_report_downloaded_to_" + str (shared_data ['report_download_path' ]))
0 commit comments