From cc2b27b6d5a52b7adb0819e4e93a8fe40cf6f87d Mon Sep 17 00:00:00 2001 From: Alena Krauch Date: Mon, 23 Jun 2025 14:20:16 +0300 Subject: [PATCH] update footer_test.py, footer_page.py, footer_data.py --- pages/footer_page.py | 43 ++++++++++++++++++++-------------------- test_data/footer_data.py | 13 +++++------- tests/footer_test.py | 6 +++--- 3 files changed, 30 insertions(+), 32 deletions(-) diff --git a/pages/footer_page.py b/pages/footer_page.py index de5023fdbb..ac09de6e1d 100644 --- a/pages/footer_page.py +++ b/pages/footer_page.py @@ -1,5 +1,7 @@ import allure import requests +from selenium.webdriver.support.wait import WebDriverWait as Wait +from urllib.parse import urlparse from selenium.common import TimeoutException from locators.footer_page_locators import FooterLocators from pages.base_page import BasePage @@ -34,7 +36,6 @@ def check_elements_visibility_on_1st_level_on_page(self): @allure.step("Get structure of the 2nd level of nesting in the Footer") def get_structure_of_2nd_level(self): elements = self.elements_are_present(self.locators.FOOTER_SECOND_LEVEL_ELEMENTS) - # tags = [element.tag_name for element in elements] return elements @allure.step("Check if elements of the 2nd level of nesting are visible") @@ -44,7 +45,6 @@ def check_elements_visibility_on_2nd_level_on_page(self): @allure.step("Get structure of the 3rd level of nesting in the Footer") def get_structure_of_3rd_level(self): elements = self.elements_are_present(self.locators.FOOTER_THIRD_LEVEL_ELEMENTS) - # tags = [element.tag_name for element in elements] return elements @allure.step("Check if elements of the 3rd level of nesting are visible") @@ -54,7 +54,6 @@ def check_elements_visibility_on_3rd_level_on_page(self): @allure.step("Get structure of the 4th level of nesting in the Footer") def get_structure_of_4th_level(self): elements = self.elements_are_present(self.locators.FOOTER_FOURTH_LEVEL_ELEMENTS) - # tags = [element.tag_name for element in elements] return elements @allure.step("Check if elements of the 4th level of nesting are visible") @@ -64,7 +63,6 @@ def check_elements_visibility_on_4th_level_on_page(self): @allure.step("Get structure of the 5th level of nesting in the Footer") def get_structure_of_5th_level(self): elements = self.elements_are_present(self.locators.FOOTER_FIFTH_LEVEL_ELEMENTS) - # tags = [element.tag_name for element in elements] return elements @allure.step("Check if elements of the 5th level of nesting are visible") @@ -74,7 +72,6 @@ def check_elements_visibility_on_5th_level_on_page(self): @allure.step("Get structure of the 6th level of nesting in the Footer") def get_structure_of_6th_level(self): elements = self.elements_are_present(self.locators.FOOTER_SIXTH_LEVEL_ELEMENTS) - # tags = [element.tag_name for element in elements] return elements @allure.step("Check if elements of the 6th level of nesting are visible") @@ -84,7 +81,6 @@ def check_elements_visibility_on_6th_level_on_page(self): @allure.step("Get structure of the 7th level of nesting in the Footer") def get_structure_of_7th_level(self): elements = self.elements_are_present(self.locators.FOOTER_SEVENTH_LEVEL_ELEMENTS) - # tags = [element.tag_name for element in elements] return elements @allure.step("Check if elements of the 7th level of nesting are visible") @@ -165,24 +161,29 @@ def get_supporter_links_status_codes(self): @allure.step("Click on links in the Footer and thereby open corresponding web pages on new tabs") def click_on_links(self): - new_tabs = [link.click() for link in self.get_list_of_supporter_links()] - # print(f'Opened tabs: {len(new_tabs)}') - new_tabs_urls, count1, count2, count3 = [], 0, 0, 0 - for i in range(1, len(new_tabs) + 1): + footer_links = self.get_list_of_supporter_links() + + for link in footer_links: + link.click() + + domains = [] + for i in range(1, len(footer_links) + 1): try: self.driver.switch_to.window(self.driver.window_handles[i]) - new_tab_url = self.get_current_tab_url() - if new_tab_url: - new_tabs_urls.append(new_tab_url) - count1 += 1 - else: - print(f"The tab url {i} has not been defined during the allotted time") - count2 += 1 + Wait(self.driver, 10).until(lambda d: d.current_url not in ('', 'about:blank')) + current_url = self.driver.current_url + parsed_url = urlparse(current_url) + domain = parsed_url.netloc + + if domain.startswith('www.'): + domain = domain[4:] + domains.append(domain) + except TimeoutException: - print(f"The tab {i} has not been loaded during the allotted time") - count3 += 1 - # print(f'{new_tabs_urls}\nDefined tabs urls: {count1}\nUndefined tabs urls: {count2}\nUnloaded tabs: {count3}') - return new_tabs_urls + print(f"Tab {i} did not load within the allotted time") + continue + + return domains @allure.step("Click on the 'Contact us' link in the Footer and thereby open an email client") def click_contact_us_link(self): diff --git a/test_data/footer_data.py b/test_data/footer_data.py index c3ce5ab3e5..e7e6029b6d 100644 --- a/test_data/footer_data.py +++ b/test_data/footer_data.py @@ -11,14 +11,11 @@ class FooterData: link1 = "https://arasaac.org/" link2 = "mailto:brainupproject@yandex.ru?subject=BrainUp" link3 = "https://epam.com/" - link4 = "https://www.epam.com/" - link5 = "https://www.jetbrains.com/" - link6 = "https://reg.ru/" - link7 = "https://www.reg.ru/" - link8 = f"{link7}?utm_source=brainup.site&utm_medium=referral&utm_campaign=brainup.site&utm_referrer=brainup.site" - link9 = "https://selectel.ru/" + link4 = "https://www.jetbrains.com/" + link5 = "https://reg.ru/" + link6 = "https://selectel.ru/" - links_href = (link1, link2, link3, link5, link6, link9) + links_href = (link1, link2, link3, link4, link5, link6) link_status_codes = (200, 403) @@ -32,4 +29,4 @@ class FooterData: images_alt = ("ARASAAC", "EPAM", "JetBrains", "Регистратор доменных имен РЕГ.РУ", "Selectel") # Related web pages urls - pages_urls = (link1, link3, link4, link5, link6, link7, link8, link9) + domains = ['arasaac.org', 'epam.com', 'jetbrains.com', 'reg.ru', 'selectel.ru'] # the list of domains diff --git a/tests/footer_test.py b/tests/footer_test.py index f39cf88379..cbffcfc654 100644 --- a/tests/footer_test.py +++ b/tests/footer_test.py @@ -100,9 +100,9 @@ def test_fp_03_01_verify_footer_links(self, driver, main_page_open): @allure.title("Verify that links in the Footer lead to correct pages after clicking") def test_fp_03_02_verify_links_lead_to_the_correct_pages(self, driver, main_page_open): page = fPage(driver) - new_tabs_urls = page.click_on_links() - assert all(element in fPD.pages_urls for element in new_tabs_urls), \ - "Links in the Footer lead to invalid pages after clicking or don't load during the allotted time" + actual_domains = page.click_on_links() + assert all(domain in fPD.domains for domain in actual_domains), \ + "Links in the Footer lead to invalid pages after clicking or don't load within the allotted time" @allure.title("Verify that the 'Contact us' link in the Footer calls an email client") def test_fp_03_03_verify_contact_us_link_calls_an_email_client(self, driver, main_page_open):