Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix failing logout tests #28

Merged
merged 51 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
4e83957
Fixed failing logout test and made common methods to click to avoid c…
Oct 9, 2024
8536373
Fix git hooks errors with formatting
Oct 9, 2024
c03e84d
Fix failing tests following last commit
Oct 9, 2024
78ee810
Fix issue with attaching screenshots to alure report
Oct 9, 2024
88f7579
Fix issue with attaching screenshots to alure report
Oct 9, 2024
41c04f8
Fix issue with attaching screenshots to allure reports and fixed fail…
Oct 9, 2024
6ff2d70
Fix issue with inconsistent test failures when running headless
Oct 10, 2024
daf58e1
Hopefully nailed all intermittent failures
Oct 10, 2024
3c61394
Fixed all issues except recording a vaccine and improved wait times
Oct 21, 2024
4add662
Try publishing data to github
Oct 21, 2024
323d649
Try publishing data to github
Oct 21, 2024
3de22b5
Try publishing data to github
Oct 21, 2024
7f827a8
Try publishing data to github
Oct 21, 2024
be8d97a
Try publishing data to github
Oct 21, 2024
b08ecbc
Fixed attach screenshot issue
Oct 22, 2024
f776266
May have solved the image attachment issue
Oct 22, 2024
3498d32
Make github pages url dynamic
Oct 22, 2024
056909c
Try attach screenshots again
Oct 22, 2024
ce7fb29
Corrected upload artifact version
Oct 22, 2024
3735b8b
Fixed issue with yml
Oct 22, 2024
e0696bd
Fix dynamic branch url naming issue
Oct 22, 2024
8fb61f2
Reset git leaks actions from last colin's change
Oct 22, 2024
30b639d
Only run logout test for quick feedback
Oct 22, 2024
ca781b9
Upload screenshots as artifacts again
Oct 22, 2024
1602432
Try different version of git actions
Oct 22, 2024
56046d5
Try different version of git actions
Oct 22, 2024
47591a5
Try different version of git actions
Oct 22, 2024
b88bafb
Try different version of git actions
Oct 22, 2024
f2f778b
Try different version of git actions
Oct 22, 2024
528fdc1
Try different version of git actions
Oct 22, 2024
a4d1945
Correct screenshot path
Oct 22, 2024
fed98a2
Correct screenshot path
Oct 22, 2024
fe2d849
Correct screenshot path
Oct 22, 2024
07e073f
Correct screenshot path
Oct 22, 2024
2d9c5a1
Correct screenshot path
Oct 22, 2024
c5c8926
Correct screenshot path
Oct 22, 2024
773a935
Correct screenshot path
Oct 22, 2024
0733163
Correct screenshot path
Oct 22, 2024
7378157
Correct screenshot path
Oct 22, 2024
ef32cff
Correct screenshot path
Oct 22, 2024
e4a0045
Correct screenshot path
Oct 22, 2024
5f34f2f
publish to gibhun-dev
Oct 22, 2024
37ac12b
made new branch for publishing to github-pages-dev
Oct 22, 2024
c3fdc2b
made new branch for publishing to github-pages-dev
Oct 22, 2024
1c4af0f
made new branch for publishing to github-pages-dev
Oct 22, 2024
9704508
Fix failing tests in dev excpet record a vaccine and added enough wai…
Oct 23, 2024
fd07f17
Added more wait timers
Oct 23, 2024
975d36d
Implement new workflow file
Oct 23, 2024
d8b30c6
debug workflow file
Oct 23, 2024
9537a2a
debug workflow file
Oct 23, 2024
d4be641
debug workflow file
Oct 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ def format_nhs_number(nhs_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)
Expand Down
69 changes: 12 additions & 57 deletions helpers/playwrightHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ def navigate_to_url(self,url):
self.page.wait_for_load_state()

def wait_for_page_to_load(self, timeout=0.1):
self.page.wait_for_selector('*', timeout=timeout * 100)
self.page.wait_for_load_state('domcontentloaded', timeout=timeout * 100)
self.page.wait_for_selector('*', timeout=timeout * 1000)
self.page.wait_for_load_state('domcontentloaded', timeout=timeout * 1000)

def find_elements(self, selector):
return self.page.query_selector_all(selector)
Expand All @@ -131,15 +131,18 @@ def wait_for_element_to_appear(self, locator_or_element, timeout=5):
# If it's a selector string, wait for the element to be visible
self.page.wait_for_selector(locator_or_element, state='visible', timeout=timeout * 1000)
element = self.page.locator(locator_or_element)
else:
# If it's already a pre-located element (Locator), use it directly
elif isinstance(locator_or_element, object) and hasattr(locator_or_element, 'wait_for'):
# If it's a pre-located Playwright Locator, use it directly
locator_or_element.wait_for(state='visible', timeout=timeout * 1000)
element = locator_or_element
element.wait_for(state='visible', timeout=timeout * 1000)
else:
raise ValueError(f"Invalid locator or element type: {type(locator_or_element)}")

print(f"Element with locator '{element}' appeared on the page.")
print(f"Element with locator '{locator_or_element}' appeared on the page.")
except Exception as e:
print(f"Error waiting for element '{locator_or_element}' to appear: {e}")


def wait_for_selector_to_disappear(self, selector, timeout=5):
try:
self.page.wait_for_selector(selector, state='hidden', timeout=timeout)
Expand Down Expand Up @@ -261,57 +264,6 @@ def find_element_with_locator_and_perform_action(self, element, action, inputVal
else:
raise ValueError(f"Unsupported action: {action}")

# def find_element_and_perform_action(self, selector, action, inputValue=None):
# selector_filename = "".join(c if c.isalnum() else "_" for c in selector)
# self.capture_screenshot(selector_filename)
# try:
# element=self.page.locator(selector)
# self.page.set_viewport_size({"width": 1500, "height":1500})
# element.scroll_into_view_if_needed()
# if action.lower() == "click":
# if element.is_visible():
# if element.is_enabled():
# element.click()
# print(f"Clicked the {selector} successfully.")
# else:
# print(f"Element with {selector} is not enabled.")
# elif action.lower() == "input_text":
# text = element.text_content()
# if element.is_visible():
# if text != '':
# element.clear()
# element.fill(inputValue)
# print(f"Entered text into the {selector} successfully.")
# elif action.lower() == "type_text":
# if element.is_visible():
# text = element.text_content()
# if text != '':
# element.clear()
# element.type(inputValue)
# print(f"Entered text into the {selector} successfully.")
# elif action.lower() == "get_text":
# text = element.text_content()
# print(f"Text from the {selector}: {text}")
# return text
# elif action.lower() == "select_option":
# if element.is_visible():
# element.select_option(inputValue)
# print(f"Selected option with value '{inputValue}' from the {selector} successfully.")
# elif action.lower() == "click_checkbox":
# if element.is_visible():
# if not element.is_checked():
# element.check()
# print(f"{selector} checkbox checked successfully.")
# else:
# print(f"{selector} checkbox is already checked.")
# else:
# print(f"Unsupported action: {action}")
# except TimeoutError:
# print(f"Timeout waiting for selector: {selector} to perform {action}")
# except Exception as e:
# print(f"Exception: {e}. Element not found: {selector}")
# self.capture_screenshot(selector_filename)

def find_element_and_perform_action(self, locator_or_element, action, inputValue=None):
# Check if the input is a string (locator) or already an element
if isinstance(locator_or_element, str):
Expand Down Expand Up @@ -350,6 +302,9 @@ def find_element_and_perform_action(self, locator_or_element, action, inputValue
if element.is_visible():
element.select_option(inputValue)
print(f"Selected option '{inputValue}' successfully.")
elif action == "clear":
element.fill('')
print(f"Cleared text from the element: {element}.")
elif action.lower() == "input_text":
if inputValue is None:
raise ValueError("`inputValue` cannot be None for 'input_text' action.")
Expand Down
58 changes: 48 additions & 10 deletions init_helpers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import re
from helpers.apiHelper import ApiHelper
from helpers.datetimeHelper import DatetimeHelper
from helpers.playwrightHelper import PlaywrightHelper
Expand Down Expand Up @@ -59,23 +60,32 @@ def load_config_from_env():
}
return config

def sanitize_filename(filename):
"""
Remove or replace illegal characters in filenames for cross-platform compatibility.
For example, Windows does not allow: \\ / : * ? " < > |
"""
return re.sub(r'[<>:"/\\|?*]', '_', filename)

def attach_screenshot(filename):
logging.basicConfig(level=logging.DEBUG)
if config["browser"] == "mobile":
filename = config["test_environment"] + "_" + config["browser"] + "_" + config["device"] + "_" + get_browser_version() + "_" + filename + ".png"
else:
filename = config["test_environment"] + "_" + config["browser"] + "_" + get_browser_version() + "_" + filename + ".png"

directory = os.path.dirname(filename)
if directory:
os.makedirs(os.path.dirname(filename), exist_ok=True)
filename = sanitize_filename(filename)
directory = os.path.join('data', 'attachments')
full_path = os.path.join(directory, filename)

os.makedirs(os.path.dirname(full_path), exist_ok=True)

logging.debug(f"Filename: {filename}")
logging.debug(f"Filename: {full_path}")

try:
screenshot = capture_screenshot(filename)
screenshot = capture_screenshot(full_path)
logging.debug(f"Screenshot saved at: {screenshot}")
allure.attach.file(screenshot, name=f"{filename}", attachment_type=allure.attachment_type.PNG)
allure.attach.file(screenshot, name=f"{full_path}", attachment_type=allure.attachment_type.PNG)
except Exception as e:
logging.error(f"Failed to capture screenshot: {e}")

Expand Down Expand Up @@ -130,6 +140,34 @@ def find_elements(selector):
def wait_for_page_to_load(timeout=1):
playwright_helper_instance.wait_for_page_to_load(timeout)

def click_element(element):
element = get_element_by_type(*element)
find_element_and_perform_action(element, "click")

def get_element_text(element):
element = get_element_by_type(*element)
find_element_and_perform_action(element, "get_text")

def clear_element(element):
element = get_element_by_type(*element)
find_element_and_perform_action(element, "clear")

def check_element(element):
element = get_element_by_type(*element)
find_element_and_perform_action(element, "check")

def check_if_element_exists(element, wait=False):
element = get_element_by_type(*element)
return check_element_exists(element, wait)

def input_text_into_element(element, text):
element = get_element_by_type(*element)
find_element_and_perform_action(element, "input_text", text)

def select_option(element, option):
element = get_element_by_type(*element)
find_element_and_perform_action(element, "select_option", option)

def check_element_exists(element, wait=False):
try:
return playwright_helper_instance.check_element_exists(element, wait)
Expand Down Expand Up @@ -157,11 +195,11 @@ def check_element_by_locator_enabled(element, wait=False):
def scroll_into_view(element):
return playwright_helper_instance.scroll_into_view(element)

def wait_for_element_to_appear(selector):
playwright_helper_instance.wait_for_element_to_appear(selector)
def wait_for_element_to_appear(*selector):
playwright_helper_instance.wait_for_element_to_appear(*selector)

def clear_element(element):
return playwright_helper_instance.clear_element(element)
# def clear_element(element):
# return playwright_helper_instance.clear_element(element)

def capture_screenshot(filename):
return playwright_helper_instance.capture_screenshot(filename)
Expand Down
39 changes: 20 additions & 19 deletions pages/choose_vaccines_page.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import time
from init_helpers import *
from test_data.get_values_from_models import get_covid_consent_vaccine_xpath, get_flu_consent_vaccine_xpath, get_rsv_consent_vaccine_xpath, get_pertussis_consent_vaccine_xpath

Expand All @@ -12,48 +13,48 @@
MIN_INTERVAL_BASED_WARNING = ("text", "You may have not reached the minimal interval between COVID-19 vaccine doses for this patient. This could depend on the clinical circumstances. For vaccination guidance, visit ")

def click_site_radiobutton(site):
element = get_element_by_type("label", site)
find_element_with_locator_and_perform_action(element, "check")
element = ("label", site)
click_element(element)

def click_back_button_choosing_vaccine_for_patient():
element = get_element_by_type(BACK_ELEMENT)
find_element_with_locator_and_perform_action(element, "click")
click_element(BACK_ELEMENT)

def click_delivery_team_radiobutton(deliveryTeam):
element = get_element_by_type("label", deliveryTeam)
if element:
find_element_with_locator_and_perform_action(element, "check")
element = ("label", deliveryTeam)
if check_if_element_exists(element, True) == True:
check_element(element)
else:
print("Delivery team not available at organization")

def click_vaccine_type_radiobutton(vaccine_type):
element = get_element_by_type("label", vaccine_type)
if element:
find_element_with_locator_and_perform_action(element, "check")
element = ("label", vaccine_type)
if check_if_element_exists(element, True) == True:
check_element(element)
else:
print("Vaccine type not available")

def click_vaccine_radiobutton(vaccine):
element = get_element_by_type("label", vaccine)
if element:
find_element_with_locator_and_perform_action(element, "check")
element = ("label", vaccine)
if check_if_element_exists(element, True) == True:
check_element(element)
else:
print("Vaccine not available")

def check_back_button_exists():
return check_element_by_locator_exists(get_element_by_type(*BACK_ELEMENT), True)
return check_if_element_exists(BACK_ELEMENT, True)

def check_age_based_warning_exists():
return check_element_by_locator_exists(get_element_by_type(*AGE_BASED_WARNING), False)
time.sleep(1)
return check_if_element_exists(AGE_BASED_WARNING, True)

def check_minimum_interval_based_warning_exists():
return check_element_by_locator_exists(get_element_by_type(*MIN_INTERVAL_BASED_WARNING), False)
return check_if_element_exists(MIN_INTERVAL_BASED_WARNING, False)

def check_covid_radiobutton_exists():
return check_element_exists(COVID_RADIOBUTTON, True)
return check_if_element_exists(COVID_RADIOBUTTON, True)

def check_flu_radiobutton_exists():
return check_element_exists(COVID_RADIOBUTTON, True)
return check_if_element_exists(FLU_RADIOBUTTON, True)

def click_continue_to_assess_patient_button():
find_element_with_locator_and_perform_action(get_element_by_type(*CONTINUE_BUTTON), "click")
click_element(CONTINUE_BUTTON)
Loading
Loading