From 798f84b4cd287e24ca1cc5197a96b10aa46469c0 Mon Sep 17 00:00:00 2001 From: Konstantin <161002599+Grom-Zadira85@users.noreply.github.com> Date: Tue, 14 May 2024 23:18:03 +0300 Subject: [PATCH] add page.is_counter_number_visible() function instead of time.sleep (#49) Valid data has been added to test_mini_cart and _checkout --- pages/checkout_cart_page.py | 21 +++++++++-------- pages/home_page.py | 13 +++++++---- pages/locators.py | 2 +- pages/mini_cart.py | 32 +++++++++++++------------- tests/test_checkout.py | 25 ++++++++++---------- tests/test_mini_cart_from_main_page.py | 22 +++++++++--------- 6 files changed, 60 insertions(+), 55 deletions(-) diff --git a/pages/checkout_cart_page.py b/pages/checkout_cart_page.py index 6f137e58..259f1966 100644 --- a/pages/checkout_cart_page.py +++ b/pages/checkout_cart_page.py @@ -46,26 +46,27 @@ def check_color_button(): @allure.link("https://trello.com/c/lvLslLGD") -def checking_product_name_are_correct_in_checkout_cart_page(): - s(PL.NAME_ARGUS_ALL_WEATHER_TANK_CHECKOUT_CART).should(have.text("Argus All-Weather Tank")) +def checking_product_name_are_correct_in_checkout_cart_page(item_name): + s(PL.NAME_ARGUS_ALL_WEATHER_TANK_CHECKOUT_CART).should(have.text(item_name)) -def checking_size_are_correct_in_checkout_cart_page(): - s(PL.SIZE_M_ARGUS_ALL_WEATHER_TANK_CHECKOUT_CART).should(have.text("M")) +def checking_size_are_correct_in_checkout_cart_page(size): + s(PL.SIZE_M_ARGUS_ALL_WEATHER_TANK_CHECKOUT_CART).should(have.text(size)) -def checking_color_are_correct_in_checkout_cart_page(): - s(PL.COLOR_GRAY_ARGUS_CHECKOUT_CART).should(have.text("Gray")) +def checking_color_are_correct_in_checkout_cart_page(color): + s(PL.COLOR_GRAY_ARGUS_CHECKOUT_CART).should(have.text(color)) @allure.link("https://trello.com/c/SQ3op4DX") -def check_price_present_in_checkout_cart_page(): - s(PL.PRICE_ITEM_CHECKOUT_CART).should(be.present).should(have.text("$22.00")) +def check_price_present_in_checkout_cart_page(item_price): + s(PL.PRICE_ITEM_CHECKOUT_CART).should(be.present).should(have.text(item_price)) def check_qty_present_in_checkout_cart_page(): s(PL.QTY_FIELD_CHECKOUT_CART).should(be.present) -def check_subtotal_present_in_checkout_cart_page(): - s(PL.CART_SUBTOTAL_CHECKOUT_CART).should(be.present).should(have.text("$")) +def check_subtotal_present_in_checkout_cart_page(subtotal): + s(PL.CART_SUBTOTAL_CHECKOUT_CART).should(be.present).should(have.text(subtotal)) + diff --git a/pages/home_page.py b/pages/home_page.py index d6c89784..d5a70976 100644 --- a/pages/home_page.py +++ b/pages/home_page.py @@ -1,9 +1,8 @@ -from selene.support.shared.jquery_style import s, ss from selene import be +from selene.support.shared.jquery_style import s + from pages.base_page import BasePage -# from pages.basket_page import BasketPage from pages.locators import NavigatorLocators as NL, ProductLocators as PL -from pages.urls import main_page_link class HomePage(BasePage): @@ -28,4 +27,10 @@ def go_to_mini_cart(self): s(PL.MINI_BASKET_WINDOW).should(be.clickable).click() def go_to_checkout_cart(self): - s(PL.VIEW_AND_EDIT_CART_LINK).click() \ No newline at end of file + s(PL.VIEW_AND_EDIT_CART_LINK).click() + + def find_counter_number(self): + return s(PL.MINICART_COUNTER) + + def is_counter_number_visible(self): + return self.find_counter_number().should(be.visible) diff --git a/pages/locators.py b/pages/locators.py index 41fcbca3..1a0230c5 100644 --- a/pages/locators.py +++ b/pages/locators.py @@ -49,7 +49,7 @@ class ProductLocators: PRICE_ITEM_CHECKOUT_CART = '//*[@class="col price"] //*[text()="$22.00"]' CART_SUBTOTAL_CHECKOUT_CART = '//*[@class="col subtotal"] //*[text()="$22.00"]' QTY_FIELD_CHECKOUT_CART = '[class="field qty"] input' - + MINICART_COUNTER = '.counter-label' class HomeLocators: STORE_LOGO = 'a.logo' diff --git a/pages/mini_cart.py b/pages/mini_cart.py index 1b0cad6e..4eefc29d 100644 --- a/pages/mini_cart.py +++ b/pages/mini_cart.py @@ -27,32 +27,32 @@ def checking_the_link_opens_checkout_cart_page(): s(PL.VIEW_AND_EDIT_CART_LINK).click() -def checking_the_size_color_and_product_name_are_correct(): +def checking_the_size_color_and_product_name_are_correct(size, color, item_name): s(PL.SEE_DETAILS).click() - s(PL.SIZE_M).should(have.text("M")) - s(PL.COLOR_GRAY).should(have.text("Gray")) - s(PL.NAME_ITEM).should(have.text("Argus All-Weather Tank")) + s(PL.SIZE_M).should(have.text(size)) + s(PL.COLOR_GRAY).should(have.text(color)) + s(PL.NAME_ITEM).should(have.text(item_name)) -def checking_present_price_item_and_cart_subtotal_in_the_mini_cart(): - s(PL.PRICE_ITEM).should(have.text("$22.00")) - s(PL.CART_SUBTOTAL).should(have.text("$22.00")) +def checking_present_price_item_and_cart_subtotal_in_the_mini_cart(price, subtotal): + s(PL.PRICE_ITEM).should(have.text(price)) + s(PL.CART_SUBTOTAL).should(have.text(subtotal)) -def change_qty(): - s(PL.QTY_FIELD).should(be.clickable).send_keys(Keys.BACKSPACE + "7") +def change_qty(qty): + s(PL.QTY_FIELD).should(be.clickable).send_keys(Keys.BACKSPACE + qty) s(PL.UPDATE).click() -def should_be_quantity_change(): - s(PL.QTY_FIELD).should(have.value("7")) +def should_be_quantity_change(qty): + s(PL.QTY_FIELD).should(have.value(qty)) time.sleep(2) -def should_be_success_message(): +def should_be_success_message(text): s(".message-success").should(be.visible) + s(".message-success").should(have.text(text)) - -def should_be_change_subtotal(): - s(PL.PRICE_ITEM).should(have.text("$22.00")) - s(PL.CART_SUBTOTAL).should(have.text("$154.00")) +def should_be_change_subtotal(price, subtotal): + s(PL.PRICE_ITEM).should(have.text(price)) + s(PL.CART_SUBTOTAL).should(have.text(subtotal)) diff --git a/tests/test_checkout.py b/tests/test_checkout.py index 94b4263c..63bafe83 100644 --- a/tests/test_checkout.py +++ b/tests/test_checkout.py @@ -1,17 +1,16 @@ import time + import allure import pytest -import selene -from selene.support.shared.jquery_style import s, ss from selene import browser, be, have +from selene.support.shared.jquery_style import s + from pages import mini_cart, checkout_shipping, checkout_cart_page +from pages.home_page import HomePage from pages.locators import ProductLocators as PL from pages.product_page import ProductPage -from pages.user import Person -from selene.support.conditions import * -from selene.support import by from pages.urls import * -from pages.home_page import HomePage + @pytest.mark.skip def test_checkout_from_mini_cart(): @@ -41,21 +40,21 @@ def test_size_color_and_product_name_are_correct_in_the_checkout_cart_page_tc_00 page = HomePage(browser, main_page_link) page.open() page.add_to_cart_from_main_page() - time.sleep(2) + page.is_counter_number_visible() page.go_to_mini_cart() page.go_to_checkout_cart() - checkout_cart_page.checking_product_name_are_correct_in_checkout_cart_page() - checkout_cart_page.checking_size_are_correct_in_checkout_cart_page() - checkout_cart_page.checking_color_are_correct_in_checkout_cart_page() + checkout_cart_page.checking_product_name_are_correct_in_checkout_cart_page("Argus All-Weather Tank") + checkout_cart_page.checking_size_are_correct_in_checkout_cart_page("M") + checkout_cart_page.checking_color_are_correct_in_checkout_cart_page("Gray") @allure.link("https://trello.com/c/SQ3op4DX") def test_check_price_qty_and_cart_subtotal_present_in_checkout_cart_page_tc_005_001_017(): page = HomePage(browser, main_page_link) page.open() page.add_to_cart_from_main_page() - time.sleep(2) + page.is_counter_number_visible() page.go_to_mini_cart() page.go_to_checkout_cart() - checkout_cart_page.check_price_present_in_checkout_cart_page() - checkout_cart_page.check_subtotal_present_in_checkout_cart_page() + checkout_cart_page.check_price_present_in_checkout_cart_page("$22.00") + checkout_cart_page.check_subtotal_present_in_checkout_cart_page("$22.00") checkout_cart_page.check_qty_present_in_checkout_cart_page() diff --git a/tests/test_mini_cart_from_main_page.py b/tests/test_mini_cart_from_main_page.py index 7edfc7d2..a90c61c9 100644 --- a/tests/test_mini_cart_from_main_page.py +++ b/tests/test_mini_cart_from_main_page.py @@ -28,7 +28,7 @@ def test_color_and_clickability_of_view_and_edit_cart_link_in_the_mini_cart_tc_0 page = HomePage(browser, main_page_link) page.open() page.add_to_cart_from_main_page() - time.sleep(2) + page.is_counter_number_visible() page.go_to_mini_cart() # mini_cart = BasketPage(browser, main_page_link) mini_cart.check_color_of_view_and_edit_cart_link_in_the_mini_cart() @@ -47,7 +47,7 @@ def test_checking_the_link_opens_the_cart_page_tc_005_001_012(): page = HomePage(browser, main_page_link) page.open() page.add_to_cart_from_main_page() - time.sleep(2) + page.is_counter_number_visible() page.go_to_mini_cart() mini_cart.checking_the_link_opens_checkout_cart_page() @@ -57,9 +57,9 @@ def test_size_color_and_product_name_are_correct_tc_005_001_013(): page = HomePage(browser, main_page_link) page.open() page.add_to_cart_from_main_page() - time.sleep(2) + page.is_counter_number_visible() page.go_to_mini_cart() - mini_cart.checking_the_size_color_and_product_name_are_correct() + mini_cart.checking_the_size_color_and_product_name_are_correct("M", "Gray", "Argus All-Weather Tank") @allure.link("https://trello.com/c/p6iExP1c") @@ -67,9 +67,9 @@ def test_checking_present_price_item_and_cart_subtotal_in_the_mini_cart_tc_005_0 page = HomePage(browser, main_page_link) page.open() page.add_to_cart_from_main_page() - time.sleep(2) + page.is_counter_number_visible() page.go_to_mini_cart() - mini_cart.checking_present_price_item_and_cart_subtotal_in_the_mini_cart() + mini_cart.checking_present_price_item_and_cart_subtotal_in_the_mini_cart("$22.00", "$22.00") @allure.link("https://trello.com/c/uCZZgQks") @@ -77,9 +77,9 @@ def test_change_quantity_of_an_item_and_changes_price_in_cart_subtotal_mini_cart page = HomePage(browser, main_page_link) page.open() page.add_to_cart_from_main_page() - time.sleep(2) + page.is_counter_number_visible() page.go_to_mini_cart() - mini_cart.should_be_success_message() - mini_cart.change_qty() - mini_cart.should_be_quantity_change() - mini_cart.should_be_change_subtotal() + mini_cart.should_be_success_message("You added Argus All-Weather Tank to your shopping cart.") + mini_cart.change_qty("7") + mini_cart.should_be_quantity_change("7") + mini_cart.should_be_change_subtotal("$22.00", "$154.00")