Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions pages/base_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from selenium.common import TimeoutException
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.support.ui import WebDriverWait as Wait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait as Wait

from locators.main_page_locators import MainPageLocators

Expand All @@ -30,44 +30,44 @@ def get_current_url(self):

def element_is_present(self, locator):
return Wait(self.driver, self.timeout).until(
ec.presence_of_element_located(locator), message=f"Can't find element by locator {locator}")
EC.presence_of_element_located(locator), message=f"Can't find element by locator {locator}")

def element_is_clickable(self, locator):
return Wait(self.driver, self.timeout).until(
ec.element_to_be_clickable(locator), message=f"Can't find element by locator {locator}")
EC.element_to_be_clickable(locator), message=f"Can't find element by locator {locator}")

def element_is_present_and_clickable(self, locator):
return (Wait(self.driver, self.timeout).until(
ec.visibility_of_element_located(locator), message=f"Can't find element by locator {locator}") and
EC.visibility_of_element_located(locator), message=f"Can't find element by locator {locator}") and
self.element_is_clickable(locator))

def element_is_visible(self, locator):
self.go_to_element(self.element_is_present(locator))
return Wait(self.driver, self.timeout).until(
ec.visibility_of_element_located(locator), message=f"Can't find element by locator {locator}")
EC.visibility_of_element_located(locator), message=f"Can't find element by locator {locator}")

def element_is_not_visible(self, locator):
return Wait(self.driver, self.timeout).until(
ec.invisibility_of_element_located(locator), message=f"The element located by {locator} is invisible")
EC.invisibility_of_element_located(locator), message=f"The element located by {locator} is invisible")

def elements_are_present(self, locator):
return Wait(self.driver, self.timeout).until(
ec.presence_of_all_elements_located(locator), message=f"Can't find elements by locator {locator}")
EC.presence_of_all_elements_located(locator), message=f"Can't find elements by locator {locator}")

def elements_are_visible1(self, locator):
return Wait(self.driver, self.timeout).until(
ec.visibility_of_all_elements_located(locator),
EC.visibility_of_all_elements_located(locator),
message=f"Can't find elements by locator {locator}")

def elements_are_visible(self, locator, timeout=10):
try:
return Wait(self.driver, timeout).until(ec.visibility_of_all_elements_located(locator))
return Wait(self.driver, timeout).until(EC.visibility_of_all_elements_located(locator))
except TimeoutException:
raise TimeoutException(f"Elements have not become visible at locator {locator} within {timeout} seconds")

def elements_are_located(self, locator, timeout=10):
try:
return Wait(self.driver, timeout).until(ec.presence_of_all_elements_located(locator))
return Wait(self.driver, timeout).until(EC.presence_of_all_elements_located(locator))
except TimeoutException:
raise TimeoutException(f"Elements were not found at locator {locator} within {timeout} seconds")

Expand All @@ -78,21 +78,21 @@ def check_expected_link(self, url):
with allure.step(f'Check url is present: {url}'):
try:
return Wait(self.driver, self.timeout).until(
ec.url_to_be(url), message=f"Can't find element by locator {url}")
EC.url_to_be(url), message=f"Can't find element by locator {url}")
except Exception as ex:
print(ex)
return Wait(self.driver, self.timeout).until(
ec.url_to_be(url), message=f"Can't find element by locator {url}")
EC.url_to_be(url), message=f"Can't find element by locator {url}")

def wait_changed_url(self, url):
with allure.step(f'Wait until url: {url} will be changed.'):
Wait(self.driver, self.timeout).until(
ec.url_changes(url), message=f"Url: {url} has not been changed!!!")
EC.url_changes(url), message=f"Url: {url} has not been changed!!!")

def wait_url_to_be(self, url):
with allure.step(f'Wait until url to be: {url}.'):
Wait(self.driver, self.timeout).until(
ec.url_to_be(url), message=f"Url: {url} has not been changed!!!")
EC.url_to_be(url), message=f"Url: {url} has not been changed!!!")

def get_text(self, locator):
with allure.step(f'Get text in the element: {locator}'):
Expand All @@ -118,22 +118,22 @@ def get_image_size(self, locator):

def get_current_tab_title(self):
try:
Wait(self.driver, 30).until(ec.presence_of_element_located((By.TAG_NAME, "title")))
Wait(self.driver, 30).until(EC.presence_of_element_located((By.TAG_NAME, "title")))
return self.driver.title
except TimeoutException:
return False

def get_current_tab_url(self):
try:
Wait(self.driver, 50).until(ec.presence_of_element_located((By.TAG_NAME, "title")))
Wait(self.driver, 50).until(EC.presence_of_element_located((By.TAG_NAME, "title")))
return self.driver.current_url
except TimeoutException:
return False

def element_is_not_clickable(self, locator):
self.timeout = 5
try:
Wait(self.driver, self.timeout).until(ec.element_to_be_clickable(locator))
Wait(self.driver, self.timeout).until(EC.element_to_be_clickable(locator))
return False
except TimeoutException:
return True
Expand All @@ -148,7 +148,7 @@ def action_move_to_element(self, element):
def check_element_is_visible(self, locator):
"""Return True or False if element is visible it's more easily for asserts"""
try:
Wait(self.driver, self.timeout).until(ec.visibility_of_element_located(locator),
Wait(self.driver, self.timeout).until(EC.visibility_of_element_located(locator),
message=f"Can't find element by locator {locator}")
return True
except TimeoutException:
Expand Down
1 change: 0 additions & 1 deletion pages/exercises_ru_similar_phrases_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ def check_list4_visibility(self):
@allure.step("Get value of the title of the tab")
def get_value_of_tab_title(self):
tab_title = self.get_current_tab_title()
# print(tab_title)
return tab_title

@allure.step("Get value of the breadcrumbs on the page")
Expand Down
34 changes: 20 additions & 14 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
import allure
import pytest
from dotenv import load_dotenv
from selenium.webdriver.support.wait import WebDriverWait
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait as Wait

from locators.contacts_page_locators import ContactsPageLocators
from locators.contributors_page_locators import ContributorsPageLocators
from locators.exercises_ru_similar_phrases_page_locators import ExercisesRuSimilarPhrasesPageLocators as erspPL
from locators.groups_page_locators import GroupsPageLocators
from locators.header_page_locators import HeaderUnauthorizedLocators as huLocators
from locators.login_page_locators import LoginPageLocators
Expand Down Expand Up @@ -51,16 +54,6 @@ def description_page_open(driver):
driver.get(MainPageLinks.URL_DESCRIPTION_PAGE)


@pytest.fixture()
@allure.step(f'Open page: {ExercisesUrls.STARTING_POINT}')
def groups_ru_page_open1(driver, auto_test_user_authorized):
page = GroupsPage(driver)
page.element_is_present_and_clickable(huLocators.RU_BUTTON).click()
page.element_is_visible(GroupsPageLocators.PAGE_SUBTITLES)
page.check_expected_link(ExercisesUrls.STARTING_POINT)
page.loader_checking()


@pytest.fixture()
@allure.step(f'Open page: {ExercisesUrls.STARTING_POINT} on the "ru" local')
def groups_ru_page_open(driver, auto_test_user_authorized):
Expand All @@ -73,7 +66,7 @@ def subtitles_changed(driver):
current_subtitles = [el.text for el in page.elements_are_located(GroupsPageLocators.PAGE_SUBTITLES)]
return current_subtitles != subtitles_before and all(current_subtitles)

WebDriverWait(driver, 10).until(subtitles_changed)
Wait(driver, 10).until(subtitles_changed)
page.elements_are_visible(GroupsPageLocators.PAGE_SUBTITLES)


Expand All @@ -86,10 +79,23 @@ def groups_en_page_open(driver, auto_test_user_authorized):


@pytest.fixture()
@allure.step(f'Open page: {ExercisesUrls.URL_EXERCISES_RU_SIMILAR_PHRASES_PAGE}')
@allure.step(f'Open page: {ExercisesUrls.URL_EXERCISES_RU_SIMILAR_PHRASES_PAGE} on the "ru" local')
def exercises_ru_similar_phrases_page_open(driver, groups_ru_page_open):
driver.get(ExercisesUrls.URL_EXERCISES_RU_SIMILAR_PHRASES_PAGE)
time.sleep(3)

def page_fully_loaded(driver):
ready_state = driver.execute_script("return document.readyState")
if ready_state != "complete":
return False

try:
content = driver.find_element(*erspPL.PAGE_LIST3)
return content.is_displayed()
except NoSuchElementException:
return False

Wait(driver, timeout=10).until(page_fully_loaded)
Wait(driver, 10).until(EC.presence_of_all_elements_located(erspPL.PAGE_LIST3))


@pytest.fixture()
Expand Down
4 changes: 4 additions & 0 deletions tests/exercises_ru_similar_phrases_page_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class TestExRuSimPhrPageText:
def test_ersp_02_01_verify_tab_title(self, driver, exercises_ru_similar_phrases_page_open):
page = erspPage(driver)
tab_title_value = page.get_value_of_tab_title()
print("Found tab title value:", tab_title_value) # temporarily for debugging
print("Expected tab title value:", erspPD.tab_title_ru)
assert tab_title_value, "The title value of the tab is empty"
assert tab_title_value in erspPD.tab_title_ru, "The tab title mismatches the valid value"

Expand All @@ -95,6 +97,8 @@ def test_ersp_02_03_verify_group_links_text(self, driver, exercises_ru_similar_p
def test_ersp_02_04_verify_subgroup_links_text(self, driver, exercises_ru_similar_phrases_page_open):
page = erspPage(driver)
subgroup_links_text = page.get_subgroup_links_text()
print("Found tab title value:", subgroup_links_text) # temporarily for debugging
print("Expected tab title value:", erspPD.subgroup_links_text)
assert subgroup_links_text, "Text in cards is absent"
assert all(element in erspPD.subgroup_links_text for element in subgroup_links_text), \
"Text in subgroup links mismatches valid values"
Expand Down