class ContactCheckout:
    """Represent Contact Info section"""

    def __init__(self, wait: WebDriverWait):
        self._wait = wait
        self._firstname = BasePageElement(CheckoutItemLoc.F_NAME, wait=wait)
        self._lastname = BasePageElement(CheckoutItemLoc.L_NAME, wait=wait)
        self._postal_code = BasePageElement(CheckoutItemLoc.ZIPCODE, wait=wait)
        self._error_msg = BasePageElement(CheckoutItemLoc.ERROR_MSG, wait=wait)
        self._cancel_btn = BasePageElement(CheckoutItemLoc.BTN_BACK, wait=wait)
        self._continue_btn = BasePageElement(CheckoutItemLoc.BTN_CONT, wait=wait)

    def fill_info(self, firstname="", lastname="", postal_code=""):
        self._firstname.write(firstname)
        self._lastname.write(lastname)
        self._postal_code.write(postal_code)

    def checkout(self):
        self._continue_btn.click()

    def back_to_cart(self):
        self._cancel_btn.click()

    def get_error_msg(self):
        return self._error_msg.get_text()
Esempio n. 2
0
class Google(BasePage):
    """Google base page."""

    def __init__(self, driver: WebDriver, timeout: int = 5):
        super().__init__(driver, _URL, timeout)
        self.__search_textbox = BasePageElement(GoogleLocators.SEARCH_TEXT_BOX, wait=self._wait)
        self.__search_btn = BasePageElement(GoogleLocators.SEARCH_BTN, wait=self._wait)
        self.__feeling_lucky_btn = BasePageElement(GoogleLocators.FEELING_LUCKY_BTN, wait=self._wait)

    def search(self, value):
        """Simple search."""
        self.__search_textbox.write(value)
        self.__search_btn.click()

    def feeling_lucky(self, value):
        """Feeling lucky search."""
        self.__search_textbox.write(value)
        self.__feeling_lucky_btn.click()
class CheckoutOver:
    def __init__(self, wait: WebDriverWait):
        self._wait = wait
        self._subtotal = BasePageElement(CheckoutOverviewLoc.ITEM_TOTAL,
                                         wait=wait)
        self._total = BasePageElement(CheckoutOverviewLoc.TOTAL, wait=wait)
        self._tax = BasePageElement(CheckoutOverviewLoc.TAX, wait=wait)
        self._cancel_btn = BasePageElement(CheckoutOverviewLoc.BTN_CANCEL,
                                           wait=wait)
        self._finish_btn = BasePageElement(CheckoutOverviewLoc.BTN_FINISH,
                                           wait=wait)
        self._thanks_order_msg = BasePageElement(
            CheckoutOverviewLoc.THANKS_ORDER_MSG, wait=wait)
        self._order_dispatch_msg = BasePageElement(
            CheckoutOverviewLoc.ORDER_DISPATCH_MSG, wait=wait)
        self._title = BasePageElement(CheckoutOverviewLoc.TITLE_LABEL,
                                      wait=wait)
        self._img_pony = BasePageElement(CheckoutOverviewLoc.IMG_PONY,
                                         wait=wait)

    def cancel_check(self):
        self._cancel_btn.click()

    def finish(self):
        self._finish_btn.click()

    def get_subtotal(self) -> str:
        return self._subtotal.get_text()

    def get_total(self) -> str:
        return self._total.get_text()

    def get_tax(self) -> str:
        return self._tax.get_text()

    def get_thanks_msg(self) -> str:
        return self._thanks_order_msg.get_text()

    def get_img_displayed(self) -> str:
        return self._img_pony.wait_until_loaded()

    def get_title(self) -> str:
        return self._title.get_text()
class InventoryDetailsPage(InventoryItemMixin, BasePage):
    """Implements inventory item details"""
    def __init__(self, driver: WebDriver, timeout: int = 5):
        super().__init__(driver, _URL, timeout)
        self._title = BasePageElement(InventoryDetailsLoc.TITLE,
                                      wait=self._wait)
        self._description = BasePageElement(InventoryDetailsLoc.DESCRIPTION,
                                            wait=self._wait)
        self._price = BasePageElement(InventoryDetailsLoc.PRICE,
                                      wait=self._wait)
        self._inv_btn = BasePageElement(InventoryDetailsLoc.BTN,
                                        wait=self._wait)
        self._back_btn = BasePageElement(InventoryDetailsLoc.BACK_BTN,
                                         wait=self._wait)
        self.header = Header(self._wait)

    def back(self):
        """Go back to details page."""
        self._back_btn.click()
Esempio n. 5
0
class InventoryItem(InventoryItemMixin):
    """Represents inventory item."""
    def __init__(self, wait: WebDriverWait, root: WebElement):
        self._wait = wait
        self._title = BasePageElement(InventoryItemLoc.TITLE,
                                      wait=wait,
                                      root=root)
        self._description = BasePageElement(InventoryItemLoc.DESCRIPTION,
                                            wait=wait,
                                            root=root)
        self._price = BasePageElement(InventoryItemLoc.PRICE,
                                      wait=wait,
                                      root=root)
        self._inv_btn = BasePageElement(InventoryItemLoc.BTN,
                                        wait=wait,
                                        root=root)

    def open_details(self):
        """Open product details"""
        self._title.click()
        return InventoryDetailsPage(self._wait._driver, self._wait._timeout)
class Header:
    """Represents inventory item."""

    def __init__(self, wait: WebDriverWait):
        self._wait = wait
        self._link = BasePageElement(HeaderLoc.LINK, wait=wait)
        self._badge = BasePageElement(HeaderLoc.BADGE, wait=wait)
        self._burger_btn = BasePageElement(HeaderLoc.BURGER_BTN, wait=wait)
        self._logout_link = BasePageElement(HeaderLoc.LOGOUT_LINK, wait=wait)

    def get_total_cart_items(self) -> int:
        """Get total items in cart"""
        try:
            return int(self._badge.get_text())
        except Exception:
            return 0

    def goto_cart(self):
        """Go to cart."""
        self._link.click()

    def open_menu(self):
        """Open menu"""
        self._burger_btn.click()

    def logout(self):
        "Logout"
        self._logout_link.click()
Esempio n. 7
0
class CartPage(InventoryItemMixin, BasePage):
    """Implements inventory item details"""
    def __init__(self, driver: WebDriver, timeout: int = 5):
        super().__init__(driver, _URL, timeout)
        self._quantity = BasePageElement(CartItemLoc.QTY, wait=self._wait)
        self._title = BasePageElement(CartItemLoc.TITLE, wait=self._wait)
        self._description = BasePageElement(CartItemLoc.DESCRIPTION,
                                            wait=self._wait)
        self._price = BasePageElement(CartItemLoc.PRICE, wait=self._wait)
        self._inv_btn = BasePageElement(CartItemLoc.BTN, wait=self._wait)
        self._back_shop = BasePageElement(CartItemLoc.BTN_SHOP,
                                          wait=self._wait)
        self._check_btn = BasePageElement(CartItemLoc.BTN_CHECK,
                                          wait=self._wait)
        self.header = Header(self._wait)

    def get_quantity(self):
        """Get product quantity"""
        return self._quantity.get_text()

    def back(self):
        """Go back to inventory page"""
        self._back_shop.click()

    def remove_from_cart(self):
        """Remove product from cart"""
        self._inv_btn.click()

    def checkout(self):
        """Continue with checkout"""
        self._check_btn.click()
Esempio n. 8
0
class LoginPage(BasePage):
    """Sauce lab login."""
    def __init__(self, driver: WebDriver, timeout: int = 5):
        super().__init__(driver, _URL, timeout)
        self.__user = BasePageElement(LoginPageLoc.USER, wait=self._wait)
        self.__password = BasePageElement(LoginPageLoc.PASSWORD,
                                          wait=self._wait)
        self.__login = BasePageElement(LoginPageLoc.LOGIN, wait=self._wait)
        self.__error_msg = BasePageElement(LoginPageLoc.ERROR_MSG,
                                           wait=self._wait)

    def login(self, user, password):
        """Login to sauce lab"""
        self.__user.write(user)
        self.__password.write(password)
        self.__login.click()
        return InventoryPage(self._driver, self._timeout)

    def get_error_message(self) -> str:
        """Get login error message
        :return: Error message
        """
        return self.__error_msg.get_text()