def __init__(self, driver: WebDriver, timeout: int = 8):
     super().__init__(driver, _URL, timeout)
     self.header = Header(self._wait)
     self.products = InventoryItems(InventoryPageLoc.ITEMS, self._wait)
     self.__label = BasePageElement(InventoryPageLoc.LABEL, self._wait)
     self.__sort_dropdown = SelectElement(InventoryPageLoc.SORT_DROPDOWN,
                                          self._wait)
def test_page_without_root():
    driver = get_driver('chrome')
    wait = WebDriverWait(driver, 5)
    driver.get('https://www.google.com/')
    locator = (By.NAME, 'q')
    element = BasePageElement(locator, wait=wait)
    element.write('Selenium')
    assert element.get_value() == 'Selenium'
    driver.quit()
def test_base_page_with_root():
    driver = get_driver('chrome')
    driver.get('https://www.google.com/')
    root_element = driver.find_element_by_class_name('SDkEP')
    locator = (By.NAME, 'q')
    element = BasePageElement(locator, root=root_element)
    element.write('Selenium')
    assert element.get_value() == 'Selenium'
    driver.quit()
Esempio n. 4
0
 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)
Esempio n. 5
0
 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)
class InventoryPage(BasePage):
    """Sauce lab login."""
    def __init__(self, driver: WebDriver, timeout: int = 8):
        super().__init__(driver, _URL, timeout)
        self.header = Header(self._wait)
        self.products = InventoryItems(InventoryPageLoc.ITEMS, self._wait)
        self.__label = BasePageElement(InventoryPageLoc.LABEL, self._wait)
        self.__sort_dropdown = SelectElement(InventoryPageLoc.SORT_DROPDOWN,
                                             self._wait)

    def get_label(self) -> str:
        """Get page label."""
        return self.__label.get_text()

    def sort_by(self, option: InventorySortOptions):
        """Sort by specified value"""
        self.__sort_dropdown.select_by_value(option.value)

    def get_sort_value(self) -> str:
        """Get select sort value."""
        print(self.__sort_dropdown)
        return self.__sort_dropdown.get_selected_value()

    def open_cart(self):
        self.header.goto_cart()
        return CartPage(self._wait._driver, self._wait._timeout)

    def click_cart(self):
        return self.header.goto_cart()

    def display_menu(self):
        self.header.open_menu()

    def click_logout(self):
        return self.header.logout()
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()
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()
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. 11
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)
Esempio n. 12
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()
 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)
Esempio n. 14
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()
Esempio n. 15
0
 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)
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. 17
0
 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 __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)
Esempio n. 19
0
 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 __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)