├── conftest.py ├── Tests.py ├── BaseApp.py └── YandexPages.py /conftest.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | from selenium import webdriver 3 | 4 | @pytest.fixture(scope="session") 5 | def browser(): 6 | driver = webdriver.Chrome(executable_path="./chromedriver") 7 | yield driver 8 | driver.quit() 9 | -------------------------------------------------------------------------------- /Tests.py: -------------------------------------------------------------------------------- 1 | from YandexPages import SearchHelper 2 | 3 | def test_yandex_search(browser): 4 | yandex_main_page = SearchHelper(browser) 5 | yandex_main_page.go_to_site() 6 | yandex_main_page.enter_word("Hello") 7 | yandex_main_page.click_on_the_search_button() 8 | elements = yandex_main_page.check_navigation_bar() 9 | assert "Картинки" and "Видео" in elements 10 | -------------------------------------------------------------------------------- /BaseApp.py: -------------------------------------------------------------------------------- 1 | from selenium.webdriver.support.wait import WebDriverWait 2 | from selenium.webdriver.support import expected_conditions as EC 3 | 4 | 5 | class BasePage: 6 | 7 | def __init__(self, driver): 8 | self.driver = driver 9 | self.base_url = "https://ya.ru/" 10 | 11 | def find_element(self, locator,time=10): 12 | return WebDriverWait(self.driver,time).until(EC.presence_of_element_located(locator), 13 | message=f"Can't find element by locator {locator}") 14 | 15 | def find_elements(self, locator,time=10): 16 | return WebDriverWait(self.driver,time).until(EC.presence_of_all_elements_located(locator), 17 | message=f"Can't find elements by locator {locator}") 18 | 19 | def go_to_site(self): 20 | return self.driver.get(self.base_url) 21 | 22 | -------------------------------------------------------------------------------- /YandexPages.py: -------------------------------------------------------------------------------- 1 | from BaseApp import BasePage 2 | from selenium.webdriver.common.by import By 3 | 4 | 5 | class YandexSeacrhLocators: 6 | LOCATOR_YANDEX_SEARCH_FIELD = (By.ID, "text") 7 | LOCATOR_YANDEX_SEARCH_BUTTON = (By.CLASS_NAME, "search2__button") 8 | LOCATOR_YANDEX_NAVIGATION_BAR = (By.CSS_SELECTOR, ".service__name") 9 | 10 | 11 | class SearchHelper(BasePage): 12 | 13 | def enter_word(self, word): 14 | search_field = self.find_element(YandexSeacrhLocators.LOCATOR_YANDEX_SEARCH_FIELD) 15 | search_field.click() 16 | search_field.send_keys(word) 17 | return search_field 18 | 19 | def click_on_the_search_button(self): 20 | return self.find_element(YandexSeacrhLocators.LOCATOR_YANDEX_SEARCH_BUTTON,time=2).click() 21 | 22 | def check_navigation_bar(self): 23 | all_list = self.find_elements(YandexSeacrhLocators.LOCATOR_YANDEX_NAVIGATION_BAR,time=2) 24 | nav_bar_menu = [x.text for x in all_list if len(x.text) > 0] 25 | return nav_bar_menu 26 | --------------------------------------------------------------------------------