Skip to content

Commit 6ed48b1

Browse files
rootroot
authored andcommitted
Fixedd failing tests and checking report file is downloaded tests are added
1 parent b52a775 commit 6ed48b1

File tree

6 files changed

+146
-31
lines changed

6 files changed

+146
-31
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ allure-report/
2525
tox.log
2626
node_modules/
2727
package-lock.json
28+
downloads/RAVs-Vaccination-Report.csv

features/reports.feature

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ Scenario Outline: Choose data page is displayed
9191
| Pertussis | Albert House |
9292
| Respiratory syncytial virus (RSV) | Albert House |
9393

94-
Scenario Outline: Check and confirm page is displayed
94+
Scenario Outline: Check and confirm page should be displayed
9595
Given I am logged into the RAVS app
9696
When I click the reports navigation link
9797
And I click the create report button
@@ -108,3 +108,42 @@ Scenario Outline: Check and confirm page is displayed
108108
| Pertussis | Albert House |
109109
| Respiratory syncytial virus (RSV) | Albert House |
110110
| COVID-19 | Albert House |
111+
112+
Scenario Outline: Report is ready page should be displayed
113+
Given I am logged into the RAVS app
114+
When I click the reports navigation link
115+
And I click the create report button
116+
And I click the today date range button and click continue
117+
And I select the vaccine type <vaccineType> and click continue
118+
And I select the site <site> and click continue
119+
And I click continue on the data page
120+
And I click Confirm and create report button in the check and confirm page
121+
Then Creating your page element should be displayed and Download Report button should be visible
122+
123+
Examples:
124+
|vaccineType | site |
125+
| COVID-19 | Albert House |
126+
| Flu | Albert House |
127+
| Pertussis | Albert House |
128+
| Respiratory syncytial virus (RSV) | Albert House |
129+
| COVID-19 | Albert House |
130+
131+
Scenario Outline: User can download the report
132+
Given I am logged into the RAVS app
133+
When I click the reports navigation link
134+
And I click the create report button
135+
And I click the <day> radio button and click Continue
136+
And I select the vaccine type <vaccineType> and click continue
137+
And I select the site <site> and click continue
138+
And I click continue on the data page
139+
And I click Confirm and create report button in the check and confirm page
140+
And I click download report button
141+
Then the report is downloaded successfully
142+
143+
Examples:
144+
|vaccineType | site | day |
145+
| COVID-19 | Albert House | Last 31 days (includes today) |
146+
| Flu | Albert House | Last 31 days (includes today) |
147+
| Pertussis | Albert House | Last 7 days (includes today) |
148+
| Respiratory syncytial virus (RSV) | Albert House | Last 14 days (includes today) |
149+
| COVID-19 | Albert House | Last 31 days (includes today) |

helpers/playwrightHelper.py

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from init_helpers import *
55
import pytest
66
import logging
7+
import platform
78

89
class BasePlaywrightHelper:
910
def __init__(self, working_directory, config):
@@ -84,19 +85,6 @@ def launch_mobile_browser(self, device_name, headless_mode):
8485
except Exception as e:
8586
print(f"Error launching mobile browser for {device_name}: {e}")
8687

87-
# def capture_screenshot(self, full_path):
88-
# try:
89-
# logging.debug("Scrolling to the top of the page.")
90-
# self.page.evaluate("window.scrollTo(0, 0);")
91-
# self.page.screenshot(path=full_path)
92-
# except Exception as error:
93-
# if "Timeout" in str(error):
94-
# print('Screenshot taking timed out, ignoring...')
95-
# return None
96-
# else:
97-
# raise error
98-
# return full_path
99-
10088
def capture_screenshot(self, full_path):
10189
try:
10290
# Get the current mouse position
@@ -239,6 +227,38 @@ def handle_unresponsive_page(self):
239227
self.page.reload(wait_until="networkidle")
240228
self.wait_for_page_to_load()
241229

230+
def click_and_get_download_path(self, locator_or_element, action="click", timeout=30, download_dir="downloads"):
231+
"""
232+
Clicks an element and waits for a file to be downloaded, then returns the download path.
233+
The file is saved in a custom directory to prevent deletion after the test.
234+
This works cross-platform (Windows and Linux).
235+
"""
236+
try:
237+
# Ensure the custom download directory exists
238+
if not os.path.isabs(download_dir): # Make sure the download_dir is an absolute path
239+
download_dir = os.path.join(os.getcwd(), download_dir) # Use current working directory as base
240+
241+
os.makedirs(download_dir, exist_ok=True)
242+
243+
# Set the download behavior in Playwright to download files to the specified directory
244+
self.page.on("download", lambda download: download.save_as(os.path.join(download_dir, download.suggested_filename)))
245+
246+
# Use Playwright's download expectation
247+
with self.page.expect_download(timeout=timeout * 1000) as download_info:
248+
self.find_element_and_perform_action(locator_or_element, action)
249+
250+
# Get the download object
251+
download = download_info.value
252+
downloaded_file_path = download.path()
253+
254+
print(f"Download completed: {downloaded_file_path}")
255+
return downloaded_file_path
256+
257+
except Exception as e:
258+
print(f"Error during download: {e}")
259+
raise
260+
261+
242262
def find_element_and_perform_action(self, locator_or_element, action, inputValue=None, screenshot_name=None):
243263
# Generate screenshot filename if not provided
244264
if not screenshot_name:

pages/find_a_patient_page.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
GENDER_OPTIONAL_SELECT = ("label", "Gender field optional")
2323
POSTCODE_OPTIONAL_INPUT = ("label", "Postcode field optional")
2424
GENDER_SELECT = ("label", "Gender")
25-
POSTCODE_INPUT = ("label", "Full postcode")
26-
DOB_DAY_INPUT = ("placeholder", "DD")
27-
DOB_MONTH_INPUT = ("placeholder", "MM")
28-
DOB_YEAR_INPUT = ("placeholder", "YYYY")
25+
POSTCODE_INPUT = ("label", "Postcode")
26+
DOB_DAY_INPUT = ("label", "Day")
27+
DOB_MONTH_INPUT = ("label", "Month")
28+
DOB_YEAR_INPUT = ("label", "Year")
2929

3030
NHS_NUMBER_INPUT_ERROR_LABEL= ("text", "Error: Enter an NHS number")
3131
NHS_NUMBER_INPUT_ERROR_BUTTON = ("button", "Enter an NHS number")
@@ -36,7 +36,6 @@
3636
GENDER_SELECT_ERROR_LABEL = ("#GenderIdError")
3737
POSTCODE_INVALID_INPUT_ERROR_LABEL = ("text", "Error: Enter the full postcode in the correct format")
3838
DOB_INPUT_ERROR_LABEL = ("text", "Error: Enter the date of birth")
39-
4039
CREATE_NEW_PATIENT_BUTTON = ("role", "button", "Create new patient")
4140
SEARCH_TIPS_LINK = ("link", "search tips")
4241
PATIENT_NAME_LINK = ("//span[@class='nhsuk-action-link__text']")

pages/reports_creating_report_page.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from init_helpers import *
2+
3+
CREATING_REPORT_ELEMENT = ("text", "Loading...Loading...")
4+
DOWNLOAD_REPORT_BUTTON = ("role", "button", "Download report")
5+
6+
def check_reports_download_report_button_exists():
7+
wait_for_element_to_disappear(CREATING_REPORT_ELEMENT)
8+
wait_for_element_to_appear(DOWNLOAD_REPORT_BUTTON)
9+
return check_element_exists(DOWNLOAD_REPORT_BUTTON)
10+
11+
def click_reports_download_report_button():
12+
wait_for_element_to_disappear(CREATING_REPORT_ELEMENT)
13+
wait_for_element_to_appear(DOWNLOAD_REPORT_BUTTON)
14+
return click_and_get_download_path(DOWNLOAD_REPORT_BUTTON, "click", 300, "downloads")
15+

tests/test_reports_steps.py

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from asyncio import sleep
2+
from logging.handlers import RotatingFileHandler
23
import secrets
34
import string
45
from pytest_bdd import given, when, then, scenarios, scenario
@@ -7,6 +8,7 @@
78
from pages.home_page import *
89
from pages.nhs_signin_page import *
910
from pages.reports_check_and_confirm_page import *
11+
from pages.reports_creating_report_page import *
1012
from pages.reports_data_selection_page import *
1113
from pages.reports_date_range_selection_page import *
1214
import logging
@@ -19,8 +21,22 @@
1921

2022
scenarios(f'{features_directory}/reports.feature')
2123

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")
2440

2541
@pytest.fixture(scope='function')
2642
def shared_data():
@@ -155,11 +171,11 @@ def I_click_today_date_range_and_click_continue(shared_data):
155171
@when(parse('I select the vaccine type {vaccineType} and click continue'))
156172
def I_select_vaccinetype_and_click_continue(shared_data, vaccineType):
157173
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")
160176
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")
163179

164180
@then("the choose sites page should be displayed")
165181
def the_choose_sites_page_should_be_displayed():
@@ -170,11 +186,11 @@ def the_choose_sites_page_should_be_displayed():
170186
@when(parse('I select the site {site} and click continue'))
171187
def I_select_vaccinetype_and_click_continue(shared_data, site):
172188
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")
175191
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")
178194

179195
@then("the choose data page should be displayed and all data options should be checked by default")
180196
def the_choose_data_page_should_be_displayed():
@@ -190,11 +206,36 @@ def the_choose_data_page_should_be_displayed():
190206
@when(parse('I click continue on the data page'))
191207
def I_select_data_and_click_continue(shared_data):
192208
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")
195211

196212
@then("the check and confirm page should be displayed")
197213
def the_check_and_confirm_page_should_be_displayed():
198214
assert check_reports_change_data_button_exists() == True
199215
attach_screenshot("check_reports_change_data_pages_reports_exists")
200216
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

Comments
 (0)