From 7a90886b99ffa2fb324384dfdf6e8e84e06a851a Mon Sep 17 00:00:00 2001 From: Andrii Rubchuk Date: Thu, 5 Jun 2025 15:01:02 +0300 Subject: [PATCH] added parametrize test and some minorfixes --- elements/dropdown_element.py | 2 +- pages/exercises_page.py | 2 +- pages/home_page.py | 2 +- pages/navigation_page.py | 2 +- pages/tutorial_page.py | 2 +- tests/test_home.py | 24 ++++++++++++------------ tests/test_tutorial.py | 4 ++-- utils/{Assertions.py => assertions.py} | 6 ++++++ utils/{Constants.py => constants.py} | 2 -- utils/data_generators.py | 7 +++++++ utils/{Locators.py => locators.py} | 0 utils/{Random.py => random.py} | 0 12 files changed, 32 insertions(+), 21 deletions(-) rename utils/{Assertions.py => assertions.py} (89%) rename utils/{Constants.py => constants.py} (93%) create mode 100644 utils/data_generators.py rename utils/{Locators.py => locators.py} (100%) rename utils/{Random.py => random.py} (100%) diff --git a/elements/dropdown_element.py b/elements/dropdown_element.py index c3ac5b6..fe69939 100644 --- a/elements/dropdown_element.py +++ b/elements/dropdown_element.py @@ -1,7 +1,7 @@ import allure from elements.base_element import BaseElement -from utils.Locators import GeneralLocators +from utils.locators import GeneralLocators class DropdownElement(BaseElement): def __init__(self, page, locator, name): diff --git a/pages/exercises_page.py b/pages/exercises_page.py index 8fde4a5..81d4ff3 100644 --- a/pages/exercises_page.py +++ b/pages/exercises_page.py @@ -1,6 +1,6 @@ from elements.base_element import BaseElement from pages.base_page import BasePage -from utils.Locators import ExercisesPageLocators +from utils.locators import ExercisesPageLocators class ExercisePage(BasePage): def __init__(self, page): diff --git a/pages/home_page.py b/pages/home_page.py index 639e62d..52472e2 100644 --- a/pages/home_page.py +++ b/pages/home_page.py @@ -5,7 +5,7 @@ from elements.input_element import InputElement from pages.base_page import BasePage from elements.base_element import BaseElement -from utils.Locators import HomePageLocators +from utils.locators import HomePageLocators class HomePage(BasePage): def __init__(self, page): diff --git a/pages/navigation_page.py b/pages/navigation_page.py index 84db71c..1ef9a92 100644 --- a/pages/navigation_page.py +++ b/pages/navigation_page.py @@ -2,7 +2,7 @@ from elements.base_element import BaseElement from pages.base_page import BasePage -from utils.Locators import NavigationLocators +from utils.locators import NavigationLocators class NavigationPage(BasePage): diff --git a/pages/tutorial_page.py b/pages/tutorial_page.py index 1ea460c..5846963 100644 --- a/pages/tutorial_page.py +++ b/pages/tutorial_page.py @@ -6,7 +6,7 @@ from elements.button_element import ButtonElement from pages.base_page import BasePage from elements.base_element import BaseElement -from utils.Locators import TutorialPageLocators +from utils.locators import TutorialPageLocators class TutorialPage(BasePage): def __init__(self, page): diff --git a/tests/test_home.py b/tests/test_home.py index 5645cdb..2e0dc97 100644 --- a/tests/test_home.py +++ b/tests/test_home.py @@ -1,9 +1,10 @@ -import random - import allure -from utils.Assertions import Assertions -import utils.Constants as Constants -from utils.Random import Random +import pytest + +from utils.assertions import Assertions +import utils.constants as Constants +from utils.random import Random +from utils.data_generators import HomeTestsDataGenerator @allure.title("Home page transitions") def test_home_check_transitions(home_page, tutorial_page): @@ -24,18 +25,17 @@ def test_home_check_sections(home_page): Assertions.assert_all_elements_are_visible(block_elements) @allure.title("Home page verify search tutorial input") -def test_home_verify_search(home_page, tutorial_page): - tutorial_to_search = Constants.Tutorials.PYTHON - tutorial_to_select = Constants.Titles.JAVA_TUTORIAL +@pytest.mark.parametrize("text_to_search, text_to_select, title_text", list(HomeTestsDataGenerator.verify_search_generator())) +def test_home_verify_search(home_page, tutorial_page, text_to_search, text_to_select, title_text): invalid_tutorial_to_search = Random.get_random_letter_string(10) - options_found = home_page.enter_tutorial_and_get_all_options(tutorial_to_search) - Assertions.assert_text_contain_all_values(tutorial_to_search, options_found) + options_found = home_page.enter_tutorial_and_get_all_options(text_to_search) + Assertions.assert_text_contain_all_values_ignoring_case(text_to_search, options_found) options_found = home_page.enter_tutorial_and_get_all_options(invalid_tutorial_to_search) Assertions.assert_count(options_found, 1) Assertions.assert_is_visible(home_page.no_tutorials_found) - home_page.enter_tutorial_and_select_option(tutorial_to_select) + home_page.enter_tutorial_and_select_option(text_to_select) Assertions.assert_is_visible(tutorial_page.tutorial_title) - Assertions.assert_text_equals_ignoring_case(tutorial_page.tutorial_title, Constants.Titles.JAVA_TUTORIAL) + Assertions.assert_text_equals_ignoring_case(tutorial_page.tutorial_title, title_text) diff --git a/tests/test_tutorial.py b/tests/test_tutorial.py index 9075eca..fa23ddc 100644 --- a/tests/test_tutorial.py +++ b/tests/test_tutorial.py @@ -1,7 +1,7 @@ import allure -from utils import Constants -from utils.Assertions import Assertions +from utils import constants +from utils.assertions import Assertions @allure.description("Check tutorial titles changing") def test_tutorial_verify_titles(home_page, tutorial_page): diff --git a/utils/Assertions.py b/utils/assertions.py similarity index 89% rename from utils/Assertions.py rename to utils/assertions.py index 5b9d512..53393a2 100644 --- a/utils/Assertions.py +++ b/utils/assertions.py @@ -54,6 +54,12 @@ def assert_text_contain_all_values(text: str, texts_list: list[str]): for t in texts_list: assert text in t + @staticmethod + @allure.step("Check text contains all values from list ignoring case") + def assert_text_contain_all_values_ignoring_case(text: str, texts_list: list[str]): + for t in texts_list: + assert text.lower() in t.lower() + @staticmethod @allure.step("Check element count") def assert_count(elements, count: int): diff --git a/utils/Constants.py b/utils/constants.py similarity index 93% rename from utils/Constants.py rename to utils/constants.py index 44d7c2d..3662dae 100644 --- a/utils/Constants.py +++ b/utils/constants.py @@ -1,5 +1,3 @@ -import allure - class Titles: HTML_TUTORIAL = "HTML Tutorial" JAVA_TUTORIAL = "JAVA Tutorial" diff --git a/utils/data_generators.py b/utils/data_generators.py new file mode 100644 index 0000000..1ba8e5d --- /dev/null +++ b/utils/data_generators.py @@ -0,0 +1,7 @@ + +class HomeTestsDataGenerator: + @staticmethod + def verify_search_generator(): + yield "Java", "Java Array Tutorial", "Java Arrays" + yield "Java", "JavaScript Array Tutorial", "JavaScript Arrays" + yield "Python", "Python Arrays", "Python Arrays" \ No newline at end of file diff --git a/utils/Locators.py b/utils/locators.py similarity index 100% rename from utils/Locators.py rename to utils/locators.py diff --git a/utils/Random.py b/utils/random.py similarity index 100% rename from utils/Random.py rename to utils/random.py