예제 #1
0
def test_selenum():
    caps = DesiredCapabilities.INTERNETEXPLORER
    caps['nativeEvents'] = False
    driver = Ie(capabilities=caps)
    driver = Ie()
    driver.get('worldshop.eu')

    search_text_box = driver.find_element_by_name('term')
    search_text_box.send_keys('t-shirt')

    loupe_button = driver.find_element_by_name('searchButton')
    loupe_button.click()
    results = driver.find_element_by_xpath('//div[@class="ProductNumber"]/span')
    match = re.search('\d+', results.text)
    print(match.group())
    assert int(match.group()) == 95

    tshirt_image = driver.find_element_by_xpath('//div[@class="ProductListItem"]/a[@class="PictureLink"]/div[@class="ProductPicture"]/img[@title="TOMMY HILFIGER, Herren T-Shirt FLAG TEE, Dunkelblau"]')
    tshirt_image.click()
    size_selectbox = Select(driver.find_element_by_name('variantChooser:variantChooserSelect'))
    size_selectbox.select_by_visible_text("L")

    WebDriverWait(driver, timeout=10).until(EC.element_to_be_clickable((By.XPATH,'//a[@class="AddToCartLink"]/span')))
    add_to_chart = driver.find_element_by_xpath('//a[@class="AddToCartLink"]/span')
    add_to_chart.click()

    WebDriverWait(driver, timeout=5).until(EC.visibility_of_element_located((By.CLASS_NAME, 'CartMessageBox')))
    add_to_cart_popup = driver.find_element_by_class_name('CartMessageBox')
    assert add_to_cart_popup.is_displayed() is True

    continue_shopping = driver.find_element_by_xpath('//img[@title="Continue Shopping"]')
    continue_shopping.click()

    cart_number = driver.find_element_by_xpath('//a/span[@class="Quantity"]')
    quantity = cart_number.text
    assert int(quantity) == 1

    your_price = driver.find_element_by_xpath('//div[@class="PriceCash"]/span[@class="PriceCashValue"]').get_attribute('data-price')
    basket_price = driver.find_element_by_xpath('//li[@class="Clearfix"][1]/span[@class="Value"]').text
    print(driver.find_element_by_xpath('//li[@class="Clearfix"][1]/span[@class="Value"]').text)
    basket_price_re = re.match('\d+', basket_price)
    print(basket_price_re.group())
    assert int(your_price) == int(basket_price_re.group())

    for i in range(4):
        WebDriverWait(driver, timeout=10).until(
            EC.element_to_be_clickable((By.XPATH, '//a[@class="AddToCartLink"]/span')))
        add_to_chart = driver.find_element_by_xpath('//a[@class="AddToCartLink"]/span')
        add_to_chart.click()

        WebDriverWait(driver, timeout=5).until(EC.visibility_of_element_located((By.CLASS_NAME, 'CartMessageBox')))
        add_to_cart_popup = driver.find_element_by_class_name('CartMessageBox')
        assert add_to_cart_popup.is_displayed() is True

        continue_shopping = driver.find_element_by_xpath('//img[@title="Continue Shopping"]')
        continue_shopping.click()

        cart_number = driver.find_element_by_xpath('//a/span[@class="Quantity"]')
        quantity = cart_number.text

        basket_price = driver.find_element_by_xpath('//li[@class="Clearfix"][1]/span[@class="Value"]').text
        print(driver.find_element_by_xpath('//li[@class="Clearfix"][1]/span[@class="Value"]').text)
        basket_price_re = re.match('\d+', basket_price)

    assert int(5 * your_price) == int(basket_price_re.group())
예제 #2
0
def test_selenium():
    caps = DesiredCapabilities.INTERNETEXPLORER
    caps['nativeEvents'] = False  #zeby przyspieszyc wpisywanie
    driver = Ie(capabilities=caps)
    driver.get('http://www.worldshop.eu')
    # driver.implicitly_wait() #czekanie w sekundach
    search_text_box = driver.find_element_by_name('term')
    search_text_box.send_keys('t-shirt')
    search_button = driver.find_element_by_name('searchButton')
    search_button.click()
    total_text = driver.find_element_by_xpath(
        './/div[@class="ProductNumber"]/span')
    match = re.search('\d+', total_text.text)
    #print(match.group())
    assert int(match.group()) == 95

    choose_tshirt = driver.find_element_by_xpath(
        './/img[@title="Hugo Boss, Herren T-Shirt, Teeos, Medium Grey"]')
    choose_tshirt.click()

    choose_size = driver.find_element_by_class_name('arrow_btn')
    choose_size.click()

    size_selectbox = Select(
        driver.find_element_by_name('variantChooser:variantChooserSelect'))
    size_selectbox.select_by_visible_text('XXL')

    #WebDriverWait(driver, timeout=5).until(EC.element_to_be_clickable((By.XPATH, './/a/span[text()="Add to shopping cart"]')))
    # add_to_cart = driver.find_element_by_xpath('.//a/span[text()="Add to shopping cart"]')  #[@class="AddToCartLink"]')
    amount = 0
    price = 0
    for i in range(5):
        WebDriverWait(driver, timeout=5).until(
            EC.element_to_be_clickable((By.CLASS_NAME, 'AddToCartLink')))
        add_to_cart = driver.find_element_by_class_name('AddToCartLink')
        add_to_cart.click()

        WebDriverWait(driver, timeout=5).until(
            EC.element_to_be_clickable((By.CLASS_NAME, 'CartMessageBox')))
        pop_up = driver.find_element_by_class_name('CartMessageBox')

        assert pop_up.is_displayed()

        continue_button = driver.find_element_by_xpath(
            './/img[@src="/medias/sys_master/button_en_primary_cockpit_localized-global-buy-moreHD_mw164.png?1476853411000"]'
        )
        continue_button.click()
        amount += 1
        price1 = driver.find_element_by_class_name('PriceCashValue')
        match_price1 = re.search('\d+', price1.text)
        price += int(match_price1.group())

    amount_read = driver.find_element_by_class_name('Quantity')
    assert int(amount_read.text) == amount

    price2 = driver.find_element_by_xpath(
        './/div[@class="Total"]/ol/li[1]/span[@class="Value"]')
    match_price2 = re.search('\d+', price2.text)

    assert price == int(match_price2.group())

    basket_button = driver.find_element_by_class_name('ToCartButton')
    basket_button.click()

    remove_button = driver.find_element_by_xpath('.//a[@class="DeleteAction"]')
    remove_button.click()

    WebDriverWait(driver, timeout=5).until(
        EC.invisibility_of_element_located(
            (By.XPATH, './/a[@class="DeleteAction"]')))
    WebDriverWait(driver, timeout=5).until(
        EC.element_to_be_clickable(
            (By.XPATH, './/div[@class="CartHeader"]/h1/strong[2]')))
    amount_article = driver.find_element_by_xpath(
        './/div[@class="CartHeader"]/h1/strong[2]'
    )  #[contains(@class= ...] -> jak wystepuje spacja w nazwie klasy

    assert int(amount_article.text) == 0