diff --git a/conftest.py b/conftest.py index 4d99738b4e..3a5014ef10 100644 --- a/conftest.py +++ b/conftest.py @@ -1,4 +1,7 @@ import os +import shutil + +import allure import pytest from selenium import webdriver from selenium.webdriver.chrome.options import Options @@ -15,7 +18,7 @@ def driver(): driver.set_window_size(1920, 1080) else: # chrome_options.add_argument("--window-size=1920,1080") - chrome_options.add_argument('--headless') + # chrome_options.add_argument('--headless') driver = webdriver.Chrome(options=chrome_options) yield driver print('\nquit browser...') @@ -28,3 +31,31 @@ def wait(driver): yield wait +# скриншот +@allure.feature("Make a Screenshot") +def pytest_runtest_makereport(item, call): + if call.when == 'call': + if call.excinfo is not None: + try: + driver = item.funcargs['driver'] + driver.save_screenshot('allure_result/screenshot.png') + allure.attach.file('allure_result/screenshot.png', name='Screenshot', + attachment_type=allure.attachment_type.PNG) + allure.attach(driver.page_source, name="HTML source", attachment_type=allure.attachment_type.HTML) + except Exception as e: + print(f"Failed to take screenshot: {e}") + + +@pytest.fixture(scope="session", autouse=True) +def clear_allure_results_folder(): + allure_report_dir = "allure_result" + if os.path.exists(allure_report_dir): + for file_name in os.listdir(allure_report_dir): + file_path = os.path.join(allure_report_dir, file_name) + try: + if os.path.isfile(file_path): + os.unlink(file_path) + elif os.path.isdir(file_path): + shutil.rmtree(file_path) + except Exception as e: + print(f"Failed to delete {file_path}. Reason: {e}") diff --git a/pages/main_page.py b/pages/main_page.py index b3728d8b98..64c0c43a8b 100644 --- a/pages/main_page.py +++ b/pages/main_page.py @@ -8,17 +8,20 @@ class MainPage(BasePage): locators = BasePageLocators() + @allure.step("") def open_description_page(self): self.element_is_presence_and_clickable(self.locators.DESCRIPTION_PAGE).click() assert self.driver.current_url == MainPageLinks.URL_DESCRIPTION_PAGE, \ "The link leads to an incorrect page" + @allure.step("") def open_telegram_page(self): self.element_is_presence_and_clickable(self.locators.TELEGRAM_PAGE).click() self.switch_to_new_window() assert self.driver.current_url == MainPageLinks.URL_TELEGRAM_PAGE, \ "The link leads to an incorrect page" + @allure.step("") def open_donate_page(self): self.element_is_presence_and_clickable(self.locators.MORE_MENU).click() self.element_is_presence_and_clickable(self.locators.DONATE_PAGE).click() @@ -26,6 +29,7 @@ def open_donate_page(self): assert self.driver.current_url == MainPageLinks.URL_DONATE_PAGE, \ "The link leads to an incorrect page" + @allure.step("") def open_contacts_page(self): self.element_is_presence_and_clickable(self.locators.MORE_MENU).click() self.element_is_presence_and_clickable(self.locators.CONTACTS).click() @@ -33,6 +37,7 @@ def open_contacts_page(self): assert self.driver.current_url == MainPageLinks.URL_CONTACTS, \ "The link leads to an incorrect page" + @allure.step("") def open_specialists_page(self): with allure.step('Click button "MORE".'): self.element_is_presence_and_clickable(self.locators.MORE_MENU).click() @@ -42,6 +47,7 @@ def open_specialists_page(self): self.check_expected_link(MainPageLinks.URL_SPECIALISTS_PAGE) self.get_current_url() + @allure.step("") def open_github(self): self.element_is_presence_and_clickable(self.locators.MORE_MENU).click() self.element_is_presence_and_clickable(self.locators.GITHUB).click() @@ -49,12 +55,14 @@ def open_github(self): assert self.driver.current_url == MainPageLinks.URL_GITHUB, \ "The link leads to an incorrect page" + @allure.step("") def open_contributors_page(self): self.element_is_presence_and_clickable(self.locators.MORE_MENU).click() self.element_is_presence_and_clickable(self.locators.CONTRIBUTORS_PAGE).click() assert self.driver.current_url == MainPageLinks.URL_CONTRIBUTORS_PAGE, \ "The link leads to an incorrect page" + @allure.step("") def open_used_resources_page(self): self.element_is_presence_and_clickable(self.locators.MORE_MENU).click() self.element_is_presence_and_clickable(self.locators.USED_RESOURCES_PAGE).click() diff --git a/tests/main_page_test.py b/tests/main_page_test.py index 0d889c63d8..7d7bf3960d 100644 --- a/tests/main_page_test.py +++ b/tests/main_page_test.py @@ -1,27 +1,34 @@ +import allure import pytest from pages.main_page import MainPage from test_data.links import MainPageLinks +@allure.epic("Main Page") class TestMainPage: + @allure.title("verify redirection to description page not authorized user") def test_mp_01_verify_redirection_to_description_page(self, driver, main_page_open): page = MainPage(driver) page.open_description_page() + @allure.title("verify redirection to telegram page not authorized user") def test_mp_02_verify_redirection_to_telegram_page(self, driver, main_page_open): page = MainPage(driver) page.open_telegram_page() + @allure.title("verify redirection to donate page not authorized user") def test_mp_03_verify_redirection_to_donate_page(self, driver, main_page_open): page = MainPage(driver) page.open_donate_page() + @allure.title("verify redirection to contacts page not authorized user") def test_mp_04_verify_redirection_to_contacts_page(self, driver, main_page_open): page = MainPage(driver) page.open_contacts_page() + @allure.title("verify redirection to specialists page not authorized user") @pytest.mark.xfail def test_mp_05_verify_redirection_to_specialists_page(self, driver, main_page_open): page = MainPage(driver) @@ -31,15 +38,18 @@ def test_mp_05_verify_redirection_to_specialists_page(self, driver, main_page_op (f"The link leads to an incorrect page. \nExpected link: {MainPageLinks.URL_SPECIALISTS_PAGE}." f"\nGotten link: {current_page_url}") + @allure.title("verify redirection to github not authorized user") def test_mp_06_verify_redirection_to_github(self, driver, main_page_open): page = MainPage(driver) page.open_github() + @allure.title("verify redirection to contributors page not authorized user") @pytest.mark.xfail def test_mp_07_verify_redirection_to_contributors_page(self, driver, main_page_open): page = MainPage(driver) page.open_contributors_page() + @allure.title("verify redirection to used resources page not authorized user") def test_mp_08_verify_redirection_to_used_resources_page(self, driver, main_page_open): page = MainPage(driver) page.open_used_resources_page()