Файл conftest.py
import pytest
from selenium import webdriver
@pytest.fixture(scope="session")
def browser():
browser = webdriver.Chrome()
browser.maximize_window()
yield browser
browser.quit()
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Файл TrailBearPage.py
from BaseApp import BasePage
from selenium.webdriver.common.by import By
class TrailBearLocators:
LOCATOR_TrailBear_BUTTON_MYWORK = (By.XPATH, '//*[@id="basic-navbar-nav"]/div/a[1]')
LOCATOR_TrailBear_FIELD_MYWORK_EL = (By.XPATH, '//*[@id="root"]/div/main/div[3]/div[1]/p[1]')
LOCATOR_TrailBear_BUTTON_REVIEWS = (By.XPATH, '//*[@id="basic-navbar-nav"]/div/a[2]')
LOCATOR_TrailBear_BUTTON_FEEDBACK = (By.XPATH, '//*[@id="basic-navbar-nav"]/div/a[3]')
LOCATOR_TrailBear_BUTTON_VK = (By.XPATH, '//*[@id="feedback"]/footer/p[1]/a')
LOCATOR_TrailBear_BUTTON_WHATSAPP = (By.XPATH, '//*[@id="feedback"]/footer/p[2]/a')
class TrailBearHelper(BasePage):
def click_mywork(self):
self.driverwait(TrailBearLocators.LOCATOR_TrailBear_BUTTON_MYWORK).click()
element_mywork = self.driverwait(TrailBearLocators.LOCATOR_TrailBear_FIELD_MYWORK_EL)
return element_mywork.text
def click_reviews(self):
self.driverwait(TrailBearLocators.LOCATOR_TrailBear_BUTTON_REVIEWS).click()
def click_feedback(self):
self.driverwait(TrailBearLocators.LOCATOR_TrailBear_BUTTON_FEEDBACK).click()
def click_vk(self):
self.driverwait(TrailBearLocators.LOCATOR_TrailBear_BUTTON_VK).click()
def click_whatsapp(self):
self.driverwait(TrailBearLocators.LOCATOR_TrailBear_BUTTON_WHATSAPP).click()
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Файл BaseApp.py
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as ec
class BasePage:
def __init__(self, browser):
self.browser = browser
self.base_url = "https://diplom.pages.dev"
self.quantity = 0
def driverwait(self, locator):
return WebDriverWait(self.browser, 20).until(ec.visibility_of_element_located(locator))
def go_to_site(self):
return self.browser.get(self.base_url)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Файл test.py
import allure
from TrailBearPage import TrailBearHelper
from selenium.webdriver.common.by import By
from selenium.webdriver import ActionChains
from allure_commons.types import AttachmentType
@allure.title('Тест mywork')
@allure.feature('Проверка click mywork')
@allure.story('Проверка ссылки Мои работы ')
def test_click_mywork(browser):
with allure.step('Открыть сайт'):
mywork = TrailBearHelper(browser)
mywork.go_to_site()
with allure.step('Кликнуть Мои работы'):
mywork.click_mywork()
element = element_mywork.click_mywork()
allure.attach(mywork.browser.get_screenshot_as_png(), name='Screenshot', attachment_type=AttachmentType.PNG)
assert element.element_mywork() == 'Ошибка!'
element.click_mywork()
@allure.title('Тест reviews')
@allure.feature('Проверка click reviews')
@allure.story('Проверка ссылки Отзывы ')
def test_click_reviews(browser):
with allure.step('Открыть сайт'):
reviews = TrailBearHelper(browser)
with allure.step('Кликнуть Отзывы'):
reviews.click_reviews()
element = reviews.browser.find_element(By.XPATH, '//*[@id="feedback"]/div/div/h5').text
allure.attach(reviews.browser.get_screenshot_as_png(), name='Screenshot', attachment_type=AttachmentType.PNG)
assert element == 'Есть вопросы? Нужна консультация?', 'Ошибка!'
@allure.title('Тест feedback')
@allure.feature('Проверка click feedback')
@allure.story('Проверка ссылки Контакты ')
def test_click_feedback(browser):
with allure.step('Открыть сайт'):
feedback = TrailBearHelper(browser)
with allure.step('Кликнуть Контакты'):
feedback.click_feedback()
element = feedback.browser.find_element(By.XPATH, '//*[@id="feedback"]/footer/button').text
allure.attach(feedback.browser.get_screenshot_as_png(), name='Screenshot', attachment_type=AttachmentType.PNG)
assert element == 'TrailBear', 'Ошибка!'
@allure.title('Тест vk')
@allure.feature('Проверка ссылки на сайт vk.com')
@allure.story('Проверка ссылки vk ')
def test_click_vk(browser):
with allure.step('Открыть сайт'):
vk = TrailBearHelper(browser)
with allure.step('Кликнуть vk'):
vk.click_vk()
@allure.title('Тест whatsapp')
@allure.feature('Проверка ссылки на сайт api.whatsapp.com')
@allure.story('Проверка ссылки whatsapp ')
def test_click_whatsapp(browser):
with allure.step('Открыть сайт'):
whatsapp = TrailBearHelper(browser)
with allure.step('Кликнуть whatsapp'):
whatsapp.click_whatsapp()
import pytest
from selenium import webdriver
@pytest.fixture(scope="session")
def browser():
browser = webdriver.Chrome()
browser.maximize_window()
yield browser
browser.quit()
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Файл TrailBearPage.py
from BaseApp import BasePage
from selenium.webdriver.common.by import By
class TrailBearLocators:
LOCATOR_TrailBear_BUTTON_MYWORK = (By.XPATH, '//*[@id="basic-navbar-nav"]/div/a[1]')
LOCATOR_TrailBear_FIELD_MYWORK_EL = (By.XPATH, '//*[@id="root"]/div/main/div[3]/div[1]/p[1]')
LOCATOR_TrailBear_BUTTON_REVIEWS = (By.XPATH, '//*[@id="basic-navbar-nav"]/div/a[2]')
LOCATOR_TrailBear_BUTTON_FEEDBACK = (By.XPATH, '//*[@id="basic-navbar-nav"]/div/a[3]')
LOCATOR_TrailBear_BUTTON_VK = (By.XPATH, '//*[@id="feedback"]/footer/p[1]/a')
LOCATOR_TrailBear_BUTTON_WHATSAPP = (By.XPATH, '//*[@id="feedback"]/footer/p[2]/a')
class TrailBearHelper(BasePage):
def click_mywork(self):
self.driverwait(TrailBearLocators.LOCATOR_TrailBear_BUTTON_MYWORK).click()
element_mywork = self.driverwait(TrailBearLocators.LOCATOR_TrailBear_FIELD_MYWORK_EL)
return element_mywork.text
def click_reviews(self):
self.driverwait(TrailBearLocators.LOCATOR_TrailBear_BUTTON_REVIEWS).click()
def click_feedback(self):
self.driverwait(TrailBearLocators.LOCATOR_TrailBear_BUTTON_FEEDBACK).click()
def click_vk(self):
self.driverwait(TrailBearLocators.LOCATOR_TrailBear_BUTTON_VK).click()
def click_whatsapp(self):
self.driverwait(TrailBearLocators.LOCATOR_TrailBear_BUTTON_WHATSAPP).click()
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Файл BaseApp.py
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as ec
class BasePage:
def __init__(self, browser):
self.browser = browser
self.base_url = "https://diplom.pages.dev"
self.quantity = 0
def driverwait(self, locator):
return WebDriverWait(self.browser, 20).until(ec.visibility_of_element_located(locator))
def go_to_site(self):
return self.browser.get(self.base_url)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Файл test.py
import allure
from TrailBearPage import TrailBearHelper
from selenium.webdriver.common.by import By
from selenium.webdriver import ActionChains
from allure_commons.types import AttachmentType
@allure.title('Тест mywork')
@allure.feature('Проверка click mywork')
@allure.story('Проверка ссылки Мои работы ')
def test_click_mywork(browser):
with allure.step('Открыть сайт'):
mywork = TrailBearHelper(browser)
mywork.go_to_site()
with allure.step('Кликнуть Мои работы'):
mywork.click_mywork()
element = element_mywork.click_mywork()
allure.attach(mywork.browser.get_screenshot_as_png(), name='Screenshot', attachment_type=AttachmentType.PNG)
assert element.element_mywork() == 'Ошибка!'
element.click_mywork()
@allure.title('Тест reviews')
@allure.feature('Проверка click reviews')
@allure.story('Проверка ссылки Отзывы ')
def test_click_reviews(browser):
with allure.step('Открыть сайт'):
reviews = TrailBearHelper(browser)
with allure.step('Кликнуть Отзывы'):
reviews.click_reviews()
element = reviews.browser.find_element(By.XPATH, '//*[@id="feedback"]/div/div/h5').text
allure.attach(reviews.browser.get_screenshot_as_png(), name='Screenshot', attachment_type=AttachmentType.PNG)
assert element == 'Есть вопросы? Нужна консультация?', 'Ошибка!'
@allure.title('Тест feedback')
@allure.feature('Проверка click feedback')
@allure.story('Проверка ссылки Контакты ')
def test_click_feedback(browser):
with allure.step('Открыть сайт'):
feedback = TrailBearHelper(browser)
with allure.step('Кликнуть Контакты'):
feedback.click_feedback()
element = feedback.browser.find_element(By.XPATH, '//*[@id="feedback"]/footer/button').text
allure.attach(feedback.browser.get_screenshot_as_png(), name='Screenshot', attachment_type=AttachmentType.PNG)
assert element == 'TrailBear', 'Ошибка!'
@allure.title('Тест vk')
@allure.feature('Проверка ссылки на сайт vk.com')
@allure.story('Проверка ссылки vk ')
def test_click_vk(browser):
with allure.step('Открыть сайт'):
vk = TrailBearHelper(browser)
with allure.step('Кликнуть vk'):
vk.click_vk()
@allure.title('Тест whatsapp')
@allure.feature('Проверка ссылки на сайт api.whatsapp.com')
@allure.story('Проверка ссылки whatsapp ')
def test_click_whatsapp(browser):
with allure.step('Открыть сайт'):
whatsapp = TrailBearHelper(browser)
with allure.step('Кликнуть whatsapp'):
whatsapp.click_whatsapp()