Ejemplo n.º 1
0
def test_add_prod_to_cart(driver):
    driver.get("http://localhost/litecart/public_html/en/")
    driver.implicitly_wait(60)
    for i in range(1, 4):
        #  выберем товар рандомно и добавим его в таблицу
        duck_crowd = driver.find_elements_by_xpath(
            ".//ul[@class='listing-wrapper products']//li")
        print("Total count of ducks:" + str(len(duck_crowd)))
        random_index = random.randint(0, len(duck_crowd) - 1)
        print("Index of random item:" + str(random_index))
        go = duck_crowd[random_index].find_element_by_xpath(
            "./a[@class='link']").click()
        driver.find_element_by_name('add_cart_product').click()
        sleep(10)
        wait = WebDriverWait(driver, 10)
        # driver.find_element_by_xpath("//*[@id='box-product']//form//td[@class='options']/strong").is_selected()
        # driver.find_element_by_xpath("//*[@id='box-product']//select/option[2]").click()
        # driver.find_element_by_name('add_cart_product').click()
        WebDriverWait(driver, 10).until(
            EC.text_to_be_present_in_element(
                (By.XPATH, ".//*[ @ id = 'cart']//a//span[@class='quantity']"),
                str(i)))
        # ждем что поменяется свойство текста у элемента потом щелкаем по главной странице
        driver.get("http://localhost/litecart/public_html/en/")
    # открыть корзину
    driver.get("http://localhost/litecart/public_html/en/checkout")
    sleep(10)
    order = driver.find_elements_by_xpath(
        ".//*[@id='order_confirmation-wrapper']/table/tbody/tr/td[@class='unit-cost']"
    )
    print("Total_order_distinct_prod:" + str(len(order)))
    for i in range(len(order)):
        driver.find_element_by_name('remove_cart_item').click()
        wait = WebDriverWait(driver, 10)
        wait.until(EC.staleness_of(order[i]))
Ejemplo n.º 2
0
def test_new_subscriber_registration(driver):
    # рандомный mail
    mail = generate_mail()
    driver.get("http://localhost/litecart/public_html/en/")
    driver.implicitly_wait(60)
    driver.find_element_by_link_text("New customers click here").click()

    find_and_fill_element(driver, 'tax_id', "1")
    find_and_fill_element(driver, 'company', "2")
    find_and_fill_element(driver, 'firstname', "3")
    find_and_fill_element(driver, 'lastname', "4")
    find_and_fill_element(driver, 'address1', "5")
    find_and_fill_element(driver, 'address2', "6")
    find_and_fill_element(driver, 'postcode', "123456")
    find_and_fill_element(driver, 'city', "8")
    find_and_fill_element(driver, 'email', mail[0])
    find_and_fill_element(driver, 'phone', "92112345678")
    find_and_fill_element(driver, 'password', "1234")
    find_and_fill_element(driver, 'confirmed_password', "1234")

    ###
    driver.find_element_by_name("create_account").click()

    ###
    driver.find_element_by_link_text("Logout").click()

    find_and_fill_element(driver, 'password', "1234")
    find_and_fill_element(driver, 'email', mail[0])
    driver.find_element_by_name("login").click()
    driver.find_element_by_link_text("Logout").click()
Ejemplo n.º 3
0
def test_sticker(driver):
    driver.get("http://localhost/litecart/public_html/en/")
    driver.implicitly_wait(60)
    sticker_sum = 0
    #  ищем всех уточек на странице
    ducks = driver.find_elements_by_xpath(
        ".//ul[@class='listing-wrapper products']//li")
    print("Total count of ducks:" + str(len(ducks)))
    #  ищем наклейку на каждой утке:
    for duck in ducks:
        sticker = duck.find_elements_by_xpath(
            ".//div[starts-with(@class,'sticker')]")
        print(len(sticker))
        sticker_sum = sticker_sum + len(sticker)

    assert len(ducks) == sticker_sum
Ejemplo n.º 4
0
def test_menu_header(driver):
    test_login(driver)
    link_array = []
    h1_array = []
    # основное меню
    menu = driver.find_elements_by_xpath(
        "//*[@id='app-']/a/span[@class='name']")  # количество пунктов
    for i in range(len(menu)):
        # после клика загрузится новая страница и все элементы, найденные ранее, будут считаться "протухшими" (stale),
        # с ними нельзя больше ничего делать # ищем список по новому и выбираем нужный элемент по индексу
        menu_el = driver.find_elements_by_xpath(
            "//*[@id='app-']/a/span[@class='name']")
        link_name = menu_el[i].text  # имя пункта главного меню
        print(str(i) + "." + link_name)
        # переходим к пункту основного меню
        menu_el[i].click()

        # ищем пункты подменю
        driver.implicitly_wait(5)
        sub_menu = driver.find_elements_by_xpath(
            "//ul[@class='docs']//li//span")
        print("Total submenu elements:" + str(len(sub_menu)))

        if len(sub_menu) < 1:
            head_title = driver.find_element_by_xpath(
                "//td[@id='content']//h1//span").text
            print("Main Link_text  : " + link_name)
            print("Head_title : " + head_title)
            link_array.append(link_name)
            h1_array.append(head_title)
        for j in range(len(sub_menu)):
            sub_menu_el = driver.find_elements_by_xpath(
                "//ul[@class='docs']//li//span")
            sub_menu_el[j].click()
            sub_menu_el = driver.find_elements_by_xpath(
                "//ul[@class='docs']//li//span")
            sub_m_link_name = sub_menu_el[j].text  # имя пункта главного меню
            head_title2 = driver.find_element_by_xpath(
                "//td[@id='content']//h1//span").text
            print("Link_text  : " + sub_m_link_name)
            print("Head_title : " + head_title2)
            link_array.append(sub_m_link_name)
            h1_array.append(head_title2)

    print(link_array)
    print(h1_array)
    assert len(link_array) == len(h1_array)
Ejemplo n.º 5
0
def test_error_in_browsers_log(driver):
    test_login(driver)
    driver.get(
        "http://localhost/litecart/public_html/admin/?app=catalog&doc=catalog&category_id=1"
    )
    # links = driver.find_elements_by_xpath(".//table[@class='dataTable']//td[./img and ./a]/a")
    links = driver.find_elements(
        By.CSS_SELECTOR, "table.dataTable [href*='product_id']:not([title]")
    links_count = len(links)
    log = []
    for i in xrange(links_count):
        links = driver.find_elements(
            By.CSS_SELECTOR,
            "table.dataTable [href*='product_id']:not([title]")
        links[i].click()
        print(links[i])
        driver.implicitly_wait(60)
        driver.find_element_by_name("cancel").click()
        for l in driver.get_log("browser"):
            log = log.append(l)
            print(log)
            assert (log == 0)
Ejemplo n.º 6
0
def geo_zones(driver, zones_page, flag):
    if flag == 1:
        test_login(driver)
        driver.implicitly_wait(60)

    driver.get(zones_page)
    #  получим все зоны
    rows = driver.find_elements_by_xpath(
        ".//*[@id='table-zones']//tr [not(contains (@class, 'header'))]")
    zones_name = []
    for elements in rows:
        # теперь пробежим по столбцам текущего tr из цикла
        column_z = elements.find_elements_by_tag_name("td")
        zones_name.append(column_z[2].text)
    # удалим последний элемент. list.pop([i]), потому что это поле используется для фильтров
    # Удаляет i-ый элемент и возвращает его. Если индекс не указан, удаляется последний элемент
    zones_name.pop()
    # print
    print(zones_name)
    sorted_zones_list = sorted(zones_name)
    # print(sorted_zones_list)
    assert zones_name == sorted_zones_list
Ejemplo n.º 7
0
def test_item_of_product_verify(driver):
    driver.get("http://localhost/litecart/public_html/en/")
    driver.implicitly_wait(60)
    duck_crowd = driver.find_elements_by_xpath(
        "//div[@id='box-campaigns']//ul[@class='listing-wrapper products']//li"
    )
    #  нужно сохранить аттрибуты товара для последующей проверки

    num_of_product = []
    link_for_product_page = []
    product_name = []
    product_price = []
    product_price_with_discount = []

    product_price_style_text_decoration = []
    product_price_style_font_size = []
    product_price_with_discount_style_font_weight = []
    product_price_with_discount_style_font_size = []

    i = 0
    for duck in duck_crowd:
        num_of_product.append(i)
        link_for_product_page.append(
            duck.find_element_by_xpath(".//a[@class='link']").get_attribute(
                'href'))
        product_name.append(
            duck.find_element_by_xpath(".//div[@class='name']").text)
        product_price.append(
            duck.find_element_by_xpath(
                ".//div[@class='price-wrapper']/s").text)
        #  проверка на то что скидки может не быть.
        product_price_with_discount.append(
            duck.find_element_by_xpath(
                ".//strong[@class='campaign-price']").text)
        #  работа со стилями
        product_price_style_text_decoration.append(
            duck.find_element_by_xpath("//s[@class='regular-price']").
            value_of_css_property('text-decoration'))
        product_price_style_font_size.append(
            duck.find_element_by_xpath("//s[@class='regular-price']").
            value_of_css_property('font-size'))
        product_price_with_discount_style_font_weight.append(
            duck.find_element_by_xpath("//strong[@class='campaign-price']").
            value_of_css_property('font-weight'))
        product_price_with_discount_style_font_size.append(
            duck.find_element_by_xpath("//strong[@class='campaign-price']").
            value_of_css_property('font-size'))

        print('ELEMENT' + str(i))
        print(product_name)
        print(product_price)
        print(product_price_with_discount)
        print(product_price_style_text_decoration)
        print(product_price_style_font_size)
        print(product_price_with_discount_style_font_weight)
        print(product_price_with_discount_style_font_size)
        i = i + 1

    print(link_for_product_page)
    #  перейдем по ссылке для сравнения каждого товара
    for j in range(len(num_of_product)):
        driver.get(link_for_product_page[j])
        # проведем сравнение
        n_product_name = driver.find_element_by_xpath(
            ".//*[@id='box-product']/div[1]/h1").text
        n_product_price = driver.find_element_by_xpath(
            ".//*[@id='box-product']//div[@class='information']//div["
            "@class='price-wrapper']/s").text
        #  проверка на то что скидки может не быть.
        n_product_price_with_discount = driver.find_element_by_xpath(
            ".//*[@id='box-product']//div["
            "@class='information']//div["
            "@class='price-wrapper']/strong").text
        #  работа со стилями
        n_product_price_style_text_decoration = driver.find_element_by_xpath(
            ".//*[@id='box-product']//div["
            "@class='information']//div["
            "@class='price-wrapper']/s").value_of_css_property(
                'text-decoration')
        n_product_price_style_font_size = driver.find_element_by_xpath(
            ".//*[@id='box-product']//div["
            "@class='information']//div["
            "@class='price-wrapper']/s").value_of_css_property('font-size')
        n_product_price_with_discount_style_font_weight = driver.find_element_by_xpath(
            ".//*[@id='box-product']//div["
            "@class='information']//div["
            "@class='price-wrapper']/strong").value_of_css_property(
                'font-weight')
        n_product_price_with_discount_style_font_size = driver.find_element_by_xpath(
            ".//*[@id='box-product']//div["
            "@class='information']//div["
            "@class='price-wrapper']/strong["
            "@class='campaign-price']").value_of_css_property('font-size')

    print('ELEMENT FROM PRODUCT_PAGE')
    print(n_product_name)

    print(n_product_price)
    print(n_product_price_with_discount)

    print(n_product_price_style_text_decoration)
    print(n_product_price_style_font_size)
    print(n_product_price_with_discount_style_font_weight)
    print(n_product_price_with_discount_style_font_size)

    assert n_product_name == product_name[j]

    assert n_product_price == product_price[j]
    assert n_product_price_with_discount == product_price_with_discount[j]

    assert n_product_price_style_text_decoration == product_price_style_text_decoration[
        j]
    assert n_product_price_style_font_size == product_price_style_font_size[j]
    assert n_product_price_with_discount_style_font_weight == product_price_with_discount_style_font_weight[
        j]
    assert n_product_price_with_discount_style_font_size == product_price_with_discount_style_font_size[
        j]