Example #1
0
def add_to_cart(driver):
    """
    Clicks the "Add to Cart" button on a product page

    :param driver: selenium webdriver
    :return: None
    """
    wait.until_visible(driver, PRODUCT_TITLE)
    wait.until_visible(driver, ADD_TO_CART_BUTTON)
    dom.click_element(driver, ADD_TO_CART_BUTTON)
Example #2
0
def test_amazon_search_summary(selenium, search_term):
    """
    This test validates adding an "Amazon's Choice" item to the cart shows up in the cart list.
    """
    # search for results
    do_search(selenium, search_term)

    # add Amazon's Choice pick to cart
    dom.click_element(selenium, AMAZON_CHOICE)
    product_name = dom.get_element(selenium, PRODUCT_TITLE).text
    add_to_cart(selenium)

    # verify added item in cart
    go_to_cart(selenium)
    verify_items_in_cart(selenium, product_name)
Example #3
0
def test_amazon_search_summary(selenium, search_term):
    """
    This test validates the expected summary of a search is shown on the first and second search results page.
    Search terms used are defined in the parameterize pytest marker above.
    """
    # search for results
    do_search(selenium, search_term)
    # verify results shown for search
    verify_search_result_summary(selenium,
                                 low=1,
                                 high=48,
                                 expected_search_term=search_term)

    dom.click_element(selenium, NEXT_BUTTON)
    verify_search_result_summary(selenium,
                                 low=49,
                                 high=96,
                                 expected_search_term=search_term)
Example #4
0
def do_search(driver, text, enter_to_search=True):
    """
    Enters in a term and then searches by either pressing the enter key or clicking the search button.

    :param driver: selenium webdriver
    :param text: str, text to search for
    :param enter_to_search: bool, do search either with enter key (True) or by clicking the search button (False)
    :return: None
    """
    # format text
    text = "{}{}".format(text, ENTER_KEY) if enter_to_search else str(text)
    # input value
    dom.set_element_value(driver, INPUT_FIELD, text)

    # if click needed to do search
    if not enter_to_search:
        dom.click_element(driver, INPUT_SEARCH_BUTTON)

    # wait until search results have loaded
    wait.until_visible(driver, UPPER_RESULT_INFO)
Example #5
0
def open_url(request, selenium):
    """
    Navigates to a webpage defined as a global dict.

    The name of the global dict should be defined in the test module before
    the test function and follow the below example:
        URL = {
            'link': 'url link',
            'title': 'url page title'
            'pop-up': 'css'
        }
    """
    url_info = getattr(request.module, 'URL')
    url.go_to_url(selenium, url_info['link'])
    wait.until_page_title_is(selenium, url_info['title'])

    # close any pop-ups that appear after navigating to page
    if 'pop-up' in url_info:
        wait.until_visible(selenium, url_info['pop-up'])
        dom.click_element(selenium, url_info['pop-up'])
def test_google_search(selenium):
    """
    This test validates:
        1. search page loads after entering search
        2. users can view second page of results
    """
    search_term = "cat pictures"
    ENTER_KEY = u"\ue007"

    # search for results
    dom.set_element_value(selenium, INPUT_FIELD, search_term + ENTER_KEY)
    # wait until search results have loaded
    wait.until_visible(selenium, RESULT_STATS)

    # click to view second page of search results
    dom.click_element(selenium, NAVIGATION_PAGES.format("2"))

    # validate second page loads and is showing stats
    wait.until_visible(selenium, RESULT_STATS)
    verify_prefix(selenium, RESULT_STATS, 'Page 2 of about')