This repository has been archived by the owner on Dec 7, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pages.py
73 lines (61 loc) · 2.98 KB
/
pages.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""Page objects to abstract interaction with pages"""
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.ui import WebDriverWait, Select
from config import TIMEOUT, log
from elements import SizeSelect
from checkers import RolledDown, UrlChanged
from locators import (
BasePageLocators,
ConsumerProductCategoryPageLocators,
ProductPageLocators,
AddToShoppingCartPageLocators
)
consumer_menu_locator = BasePageLocators.consumer_menu_locator
featured_product_locator = ConsumerProductCategoryPageLocators.FEATURED_PRODUCT_LOCATOR
size_select_locator = ProductPageLocators.SIZE_SELECT_LOCATOR
buy_form_locator = ProductPageLocators.BUY_FORM_LOCATOR
upsell_items_locator = AddToShoppingCartPageLocators.UPSELL_ITEMS_SELECTOR
class BasePage(object):
"""Base class to initialize the base page that will be called from all pages"""
def __init__(self, driver):
self.driver = driver
class_name = self.__class__.__name__
log.debug("Wrap {} inside {}".format(driver.current_url, class_name))
@property
def current_url(self):
return self.driver.current_url
def wait_for_url_change(self):
WebDriverWait(self.driver, TIMEOUT).until(UrlChanged(self.driver))
def go_to_consumer_product_category(self, consumer, product_category):
"""Navigate to consumer type product category, e.g. mens t-shirts"""
driver = self.driver
consumer_menu = driver.find_element(*consumer_menu_locator(consumer))
ActionChains(driver).move_to_element(consumer_menu).perform()
category_rolled_down = RolledDown(product_category)
product_category_menu = WebDriverWait(driver, TIMEOUT).until(category_rolled_down)
ActionChains(driver).click(product_category_menu).perform()
self.wait_for_url_change()
class MainPage(BasePage):
"""Main page (sportamore.se)"""
class ConsumerProductCategoryPage(BasePage):
"""Consumer type and product category page, e.g. sportamore.se/dam/klader/jackor/"""
def go_to_featured_product(self):
driver = self.driver
featured_product = driver.find_element(*featured_product_locator)
ActionChains(driver).click(featured_product).perform()
self.wait_for_url_change()
class ProductPage(BasePage):
"""Product page, e.g. https://www.sportamore.se/produkt/89563-blacc-glow-f-rosa"""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.size_select = SizeSelect(
self.driver.find_element(*size_select_locator))
def go_to_add_to_cart(self):
driver = self.driver
driver.find_element(*buy_form_locator).submit()
self.wait_for_url_change()
class AddToShoppingCartPage(BasePage):
"""Add to shopping cart page (https://www.sportamore.se/cart/add/)"""
def get_upsell_items(self):
upsell_items = self.driver.find_elements(*upsell_items_locator)
return {item.text.strip() for item in upsell_items} # strip due to padding