Skip to content

Commit

Permalink
feat: allure hierarchy
Browse files Browse the repository at this point in the history
  • Loading branch information
crlinm committed Dec 6, 2023
1 parent 9eafa0b commit 6f82d65
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
33 changes: 32 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import os
import shutil

import allure
import pytest
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
Expand All @@ -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...')
Expand All @@ -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}")
8 changes: 8 additions & 0 deletions pages/main_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,36 @@
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()
self.switch_to_new_window()
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()
print(self.driver.current_url)
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()
Expand All @@ -42,19 +47,22 @@ 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()
self.switch_to_new_window()
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()
Expand Down
10 changes: 10 additions & 0 deletions tests/main_page_test.py
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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()

0 comments on commit 6f82d65

Please sign in to comment.