diff --git a/tests_e2e/components/address_filter_component.py b/tests_e2e/components/address_filter_component.py new file mode 100644 index 0000000..57618a6 --- /dev/null +++ b/tests_e2e/components/address_filter_component.py @@ -0,0 +1,28 @@ +from playwright.sync_api import Locator + +from tests_e2e.components.facet_component import FacetComponent + + +class AddressFilterComponent: + def __init__(self, element: Locator): + self.element = element + + @property + def filter_countries(self) -> FacetComponent: + return FacetComponent(self.element.locator("[data-test-id='select-address-filter-countries']")) + + @property + def filter_regions(self) -> FacetComponent: + return FacetComponent(self.element.locator("[data-test-id='select-address-filter-regions']")) + + @property + def filter_cities(self) -> FacetComponent: + return FacetComponent(self.element.locator("[data-test-id='select-address-filter-cities']")) + + @property + def filter_keyword_input(self) -> Locator: + return self.element.locator("[data-test-id='select-address-filter-keyword-input']") + + @property + def apply_button(self) -> Locator: + return self.element.locator("[data-test-id='select-address-filter-apply-button']") diff --git a/tests_e2e/components/address_items_component.py b/tests_e2e/components/address_items_component.py new file mode 100644 index 0000000..c838a33 --- /dev/null +++ b/tests_e2e/components/address_items_component.py @@ -0,0 +1,12 @@ +from playwright.sync_api import Locator + +from tests_e2e.components.facet_component import FacetComponent + + +class AddressItemsComponent: + def __init__(self, element: Locator): + self.element = element + + @property + def radio_buttons(self) -> Locator: + return self.element.locator("[data-test-id='select-address-map-modal-radio-button']") diff --git a/tests_e2e/components/checkout_shipping_details_component.py b/tests_e2e/components/checkout_shipping_details_component.py index 5bee287..d7010cc 100644 --- a/tests_e2e/components/checkout_shipping_details_component.py +++ b/tests_e2e/components/checkout_shipping_details_component.py @@ -21,7 +21,9 @@ def pickup_point_section(self) -> Locator: @property def address_selector_component(self) -> AddressSelectorComponent: - return AddressSelectorComponent(self.element.locator("[data-test-id='checkout.shipping-details-section.shipping-address-section']")) + return AddressSelectorComponent( + self.element.locator("[data-test-id='checkout.shipping-details-section.shipping-address-section']") + ) @property def shipping_method_selector(self) -> Locator: @@ -36,3 +38,6 @@ def switch_delivery_option(self, option: Literal["pickup", "shipping"]) -> None: def select_shipping_method(self, shipping_method: str) -> None: self.shipping_method_selector.click() self.element.locator(f"[data-shipping-method-id='{shipping_method}']").click() + + def select_pickup_point(self) -> None: + self.pickup_point_section.locator("[data-test-id='select-address-button']").click() diff --git a/tests_e2e/components/facet_component.py b/tests_e2e/components/facet_component.py new file mode 100644 index 0000000..6ea1f50 --- /dev/null +++ b/tests_e2e/components/facet_component.py @@ -0,0 +1,10 @@ +from playwright.sync_api import Locator + + +class FacetComponent: + def __init__(self, element: Locator): + self.element = element + + @property + def open_button(self) -> Locator: + return self.element.locator("[data-test-id='facet-filter-open-button']") diff --git a/tests_e2e/tests/test_e2e_bopis_map.py b/tests_e2e/tests/test_e2e_bopis_map.py new file mode 100644 index 0000000..6fa9499 --- /dev/null +++ b/tests_e2e/tests/test_e2e_bopis_map.py @@ -0,0 +1,69 @@ +import os +import time +from typing import Any + +import allure +import pytest +from playwright.sync_api import Page, expect + +from fixtures.anonymous_catalog_requests import AnonymousCatalogRequests +from tests_e2e.components.address_filter_component import AddressFilterComponent +from tests_e2e.components.address_items_component import AddressItemsComponent +from tests_e2e.components.edit_address_modal_component import EditAddressModalComponent +from fixtures.requests_tracker import RequestsTracker +from tests_e2e.pages.cart_page import CartPage +from tests_e2e.pages.category_page import CategoryPage + + +@pytest.mark.e2e +@allure.title("BOPIS map test (E2E)") +def test_e2e_remove_cart_item( + config: dict[str, Any], + dataset: dict[str, Any], + page: Page, + anonymous_catalog_requests: AnonymousCatalogRequests, + requests_tracker: RequestsTracker, + product_quantity_control: str, +): + print(f"{os.linesep}Running E2E test of BOPIS map...", end=" ") + + anonymous_catalog_requests.toggle(True) + + page.set_viewport_size({"width": 1920, "height": 1080}) + + category_to_browse = next( + category for category in dataset["categories"] if category["id"] == "category-acme-laptops" + ) + product_to_add_to_cart = next( + product for product in dataset["products"] if product["id"] == "product-acme-laptop-hp-pavilion-16-ag0087nr" + ) + + category_page = CategoryPage( + config, + page, + category_to_browse["seoInfos"][0]["semanticUrl"], + product_quantity_control, + ) + category_page.navigate() + + category_page.add_product_to_cart(product_to_add_to_cart["code"], 2) + + cart_page = CartPage(config, page) + cart_page.navigate() + + cart_page.shipping_details_section_component.switch_delivery_option("pickup") + cart_page.shipping_details_section_component.select_pickup_point() + + addresses_filter = AddressFilterComponent(page.locator("[data-test-id='select-address-filter']")) + expect(addresses_filter.element).to_be_visible() + + addresses_list = AddressItemsComponent(page.locator("[data-test-id='select-address-map-modal-list']")) + expect(addresses_list.element).to_be_visible() + + number_of_radio_buttons = len(addresses_list.radio_buttons.all()) + + number_of_radio_buttons_expected = len(dataset["pickupLocations"]) + + assert ( + number_of_radio_buttons == number_of_radio_buttons_expected + ), f"Number of pickup locations is not {number_of_radio_buttons_expected}, but {number_of_radio_buttons}"