diff --git a/oct/pages/product_page.py b/oct/pages/product_page.py index 7e7cb3d..92d9017 100644 --- a/oct/pages/product_page.py +++ b/oct/pages/product_page.py @@ -3,11 +3,48 @@ from oct.pages.base import Page +class InformationBlock: + def __init__(self, browser: Remote): + self._browser = browser + + def open_brand_page(self) -> None: + brand_name = self._browser.find_element_by_xpath( + '//*[@id="content"]/div[1]/div[2]/ul[1]/li[1]/a' + ) + brand_name.click() + + def open_share_link(self) -> None: + self._browser.find_element_by_xpath( + '//*[@id="content"]/div/div[2]/div[3]/div/a[4]/a[1]' + ).click() + + def add_to_wish_list(self) -> None: + self._browser.find_element_by_xpath( + '//*[@id="content"]/div[1]/div[2]/div[1]/button[1]' + ).click() + + +class MessageBlock: + def __init__(self, browser: Remote): + self._browser = browser + + def has_wish_list_message(self) -> bool: + try: + self._browser.find_element_by_css_selector( + "#product-product > div.alert.alert-success.alert-dismissible" + ) + return True + except NoSuchElementException: + return False + + class ProductPage(Page): def __init__(self, browser: Remote, product_id: str, product_name: str): self._browser = browser self._product_id = product_id self._product_name = product_name + self._info_block = InformationBlock(browser) + self._message_block = MessageBlock(browser) def open(self) -> None: self._browser.get( @@ -18,17 +55,6 @@ def open(self) -> None: def loaded(self) -> bool: return self._product_name in self._browser.title - def open_brand_page(self) -> None: - brand_name = self._browser.find_element_by_xpath( - '//*[@id="content"]/div[1]/div[2]/ul[1]/li[1]/a' - ) - brand_name.click() - - def open_share_link(self) -> None: - self._browser.find_element_by_xpath( - '//*[@id="content"]/div/div[2]/div[3]/div/a[4]/a[1]' - ).click() - def open_product_image(self) -> None: product_img = self._browser.find_element_by_xpath( '//*[@id="content"]/div[1]/div[1]/ul[1]/li[2]/a/img' @@ -46,3 +72,9 @@ def open_review_link(self) -> None: self._browser.find_element_by_xpath( '// * [ @ id = "content"] / div / div[1] / ul[2] / li[2] / a' ).click() + + def information_block(self) -> InformationBlock: + return self._info_block + + def messages(self) -> MessageBlock: + return self._message_block diff --git a/oct/tests/web/adding_to_wish_list.py b/oct/tests/web/adding_to_wish_list.py new file mode 100644 index 0000000..f36e665 --- /dev/null +++ b/oct/tests/web/adding_to_wish_list.py @@ -0,0 +1,21 @@ +# pylint: disable=no-self-use # pyATS-related exclusion +from selenium.webdriver import Remote +from pyats.aetest import Testcase, test +from oct.browsers import Chrome +from oct.tests import run_testcase +from oct.pages.product_page import ProductPage + + +class AddingProductToWishList(Testcase): + @test + def test_adding_to_wish_list(self, grid: str) -> None: + chrome: Remote = Chrome(grid) + product_page = ProductPage(chrome, "41", "iMac") + product_page.open() + product_page.loaded() + product_page.information_block().add_to_wish_list() + assert product_page.messages().has_wish_list_message() + + +if __name__ == "__main__": + run_testcase() diff --git a/oct/tests/web/brand.py b/oct/tests/web/brand.py index 191a0e9..523900d 100644 --- a/oct/tests/web/brand.py +++ b/oct/tests/web/brand.py @@ -15,7 +15,7 @@ def test(self, grid: str) -> None: chrome: Remote = Chrome(grid) product_page = ProductPage(chrome, "41", "IMac") product_page.open() - product_page.open_brand_page() + product_page.information_block().open_brand_page() assert BrandPage(chrome, "8", "Apple").loaded() diff --git a/oct/tests/web/share.py b/oct/tests/web/share.py index 384ac14..75f5ddc 100644 --- a/oct/tests/web/share.py +++ b/oct/tests/web/share.py @@ -15,7 +15,7 @@ def test(self, grid: str) -> None: chrome: Remote = Chrome(grid) product_page = ProductPage(chrome, "34", "iPod Shuffle") product_page.open() - product_page.open_share_link() + product_page.information_block().open_share_link() share_page = ShareWindow(chrome) assert share_page.is_open_popup_share()