Skip to content

Commit

Permalink
'InformationBlock' class was created in oct/pages/product_page.py.
Browse files Browse the repository at this point in the history
'open_brand_page' method, 'open_share_link' method were moved from the 'ProductPage(Page)' class to 'InformationBlock' class.
'add_to_wish_list' method was created and added to 'InformationBlock' class. This method adds the product to the wish list.
'MessageBlock' class was created in oct/pages/product_page.py.
'has_wish_list_message' method was created and added to 'MessageBlock' class. This method checks that the message about adding product to the wish list is displayed.
'information_block' method and 'messages' method were created and added to 'ProductPage(Page)' class. adding_to_wish_list.py module in oct/tests/web was created for implementation and running the test case.
  • Loading branch information
Flower1111 committed Mar 26, 2019
1 parent de10944 commit 8edc1b9
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 13 deletions.
54 changes: 43 additions & 11 deletions oct/pages/product_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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'
Expand All @@ -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
21 changes: 21 additions & 0 deletions oct/tests/web/adding_to_wish_list.py
Original file line number Diff line number Diff line change
@@ -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()
2 changes: 1 addition & 1 deletion oct/tests/web/brand.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand Down
2 changes: 1 addition & 1 deletion oct/tests/web/share.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 8edc1b9

Please sign in to comment.