def navigate_to_checkout(browser, product): wait_until_condition(browser, lambda x: x.is_text_present("Newest Products")) wait_until_condition(browser, lambda x: x.is_text_present(product.name)) click_element(browser, "#product-%s" % product.pk) # open product from product list click_element(browser, "#add-to-cart-button-%s" % product.pk) # add product to basket wait_until_appeared(browser, ".cover-wrap") wait_until_disappeared(browser, ".cover-wrap") click_element( browser, "#navigation-basket-partial") # open upper basket navigation menu click_element(browser, "a[href='/basket/']") # click the link to basket in dropdown wait_until_condition( browser, lambda x: x.is_text_present("Shopping cart")) # we are in basket page wait_until_condition( browser, lambda x: x.is_text_present(product.name)) # product is in basket click_element(browser, "a[href='/checkout/']") # click link that leads to checkout
def register_test(browser, live_server, test_username, test_email, test_password): click_element(browser, "button[data-id='id_checkout_method_choice-register']") click_element(browser, "li[data-original-index='1'] a") click_element(browser, "div.clearfix button.btn.btn-primary.btn-lg.pull-right") wait_until_condition(browser, lambda x: x.is_text_present("Register")) browser.find_by_id("id_username").fill(test_username) browser.find_by_id("id_email").fill(test_email) browser.find_by_id("id_password1").fill(test_password) browser.find_by_id("id_password2").fill("typo-%s" % test_password) click_element(browser, "div.clearfix button.btn.btn-primary.btn-lg.pull-right") wait_until_appeared(browser, "div.form-group.passwordinput.required.has-error") browser.find_by_id("id_password1").fill(test_password) browser.find_by_id("id_password2").fill(test_password) click_element(browser, "div.clearfix button.btn.btn-primary.btn-lg.pull-right") wait_until_condition(browser, lambda x: x.is_text_present("Addresses")) # Reload here just in case since there might have been reload with JS # which might cause issues with tests since the elements is in cache browser.reload() # Log out and go back to checkout choice phase click_element(browser, "div.top-nav i.menu-icon.fa.fa-user") click_element(browser, "a[href='/logout/']") # Ensure that the language is still english. It seems that the language might change # during the logout. browser.find_by_id("language-changer").click() browser.find_by_xpath('//a[@class="language"]').first.click() # There is no products on basket anymore so let's add one product = Product.objects.first() product_url = reverse("wshop:product", kwargs={ "pk": product.pk, "slug": product.slug }) browser.visit("%s%s" % (live_server, product_url)) click_element(browser, "#add-to-cart-button-%s" % product.pk) # add product to basket wait_until_appeared(browser, ".cover-wrap") wait_until_disappeared(browser, ".cover-wrap") browser.visit("%s%s" % (live_server, "/checkout/"))
def _add_product_to_basket_from_category(live_server, browser, first_category, shop): url = reverse("wshop:category", kwargs={ "pk": first_category.pk, "slug": first_category.slug }) browser.visit("%s%s" % (live_server, url)) wait_until_condition(browser, lambda x: x.is_text_present(first_category.name)) # Make sure that the correct price is visible product = Product.objects.filter(sku="test-sku-2").first() selector = "#product-%s div.price-line span.lead strong" % product.id wait_until_condition(browser, lambda x: "720" in x.find_by_css(selector).first.text) # Test product price update new_price = 42 shop_product = product.get_shop_instance(shop) shop_product.default_price_value = new_price shop_product.save() discount_amount = 5 _create_catalog_category_campaign(first_category, shop, discount_amount) browser.reload() wait_until_condition( browser, lambda x: str(new_price - discount_amount) in x.find_by_css( selector).first.text) # Go to product detail and update the price one more time click_element(browser, selector) product_detail_price_selector = "#product-price-div-%s span.product-price strong" % product.id wait_until_appeared(browser, product_detail_price_selector) wait_until_condition( browser, lambda x: str(new_price - discount_amount) in x.find_by_css( product_detail_price_selector).first.text) last_price = 120.53 shop_product = product.get_shop_instance(shop) shop_product.default_price_value = last_price shop_product.save() new_discount_amount = 10 _create_catalog_category_campaign(first_category, shop, new_discount_amount) browser.reload() wait_until_condition( browser, lambda x: str(last_price - new_discount_amount) in x. find_by_css(product_detail_price_selector).first.text) # Add product to basket and navigate to basket view click_element(browser, "#add-to-cart-button-%s" % product.pk) # add product to basket wait_until_appeared(browser, ".cover-wrap") wait_until_disappeared(browser, ".cover-wrap") click_element( browser, "#navigation-basket-partial") # open upper basket navigation menu click_element(browser, "a[href='/basket/']") # click the link to basket in dropdown wait_until_condition( browser, lambda x: x.is_text_present("Shopping cart")) # we are in basket page wait_until_condition( browser, lambda x: x.is_text_present(product.name)) # product is in basket
def login_and_finish_up_the_checkout(browser, live_server, test_username, test_email, test_password): browser.fill("login-username", test_email) browser.fill("login-password", test_password) click_element(browser, "button[name='login']") wait_until_condition(browser, lambda x: x.is_text_present("Addresses"), timeout=100) # Reload here just in case since there might have been reload with JS # which might cause issues with tests since the elements is in cache browser.reload() # This should be first order upcoming assert Order.objects.count() == 0 # Fnish the checkout customer_name = "Test Tester" customer_street = "Test Street" customer_city = "Test City" customer_region = "CA" customer_country = "US" # Fill all necessary information browser.fill("billing-name", customer_name) browser.fill("billing-street", customer_street) browser.fill("billing-city", customer_city) wait_until_appeared(browser, "#id_billing-region") browser.select("billing-country", customer_country) wait_until_disappeared(browser, "#id_billing-region") wait_until_appeared(browser, "select[name='billing-region_code']") browser.select("billing-region_code", customer_region) click_element(browser, "#addresses button[type='submit']") wait_until_condition( browser, lambda x: x.is_text_present("This field is required.")) browser.fill("shipping-name", customer_name) browser.fill("shipping-street", customer_street) browser.fill("shipping-city", customer_city) wait_until_appeared(browser, "#id_shipping-region") browser.select("shipping-country", customer_country) wait_until_disappeared(browser, "#id_shipping-region") wait_until_appeared(browser, "select[name='shipping-region_code']") click_element(browser, "#addresses button[type='submit']") wait_until_condition(browser, lambda x: x.is_text_present("Shipping & Payment")) pm = get_default_payment_method() sm = get_default_shipping_method() wait_until_condition(browser, lambda x: x.is_text_present(sm.name) ) # shipping method name is present wait_until_condition( browser, lambda x: x.is_text_present(pm.name)) # payment method name is present click_element(browser, ".btn.btn-primary.btn-lg.pull-right" ) # click "continue" on methods page wait_until_condition(browser, lambda x: x.is_text_present("Confirmation") ) # we are indeed in confirmation page product = Product.objects.first() # See that all expected texts are present wait_until_condition(browser, lambda x: x.is_text_present(product.name)) wait_until_condition(browser, lambda x: x.is_text_present(sm.name)) wait_until_condition(browser, lambda x: x.is_text_present(pm.name)) wait_until_condition(browser, lambda x: x.is_text_present("Delivery")) wait_until_condition(browser, lambda x: x.is_text_present("Billing")) # check that user information is available wait_until_condition(browser, lambda x: x.is_text_present(customer_name)) wait_until_condition(browser, lambda x: x.is_text_present(customer_street)) wait_until_condition(browser, lambda x: x.is_text_present(customer_city)) wait_until_condition(browser, lambda x: x.is_text_present("United States")) browser.execute_script( 'document.getElementById("id_accept_terms").checked=true' ) # click accept terms click_element(browser, ".btn.btn-primary.btn-lg") # click "place order" wait_until_condition(browser, lambda x: x.is_text_present( "Thank you for your order!")) # order succeeded # Let's make sure the order now has a customer assert Order.objects.count() == 1 order = Order.objects.first() assert order.customer == PersonContact.objects.filter( user__username=test_username).first() assert order.customer.name == customer_name assert order.customer.default_shipping_address is not None assert order.customer.default_billing_address is not None assert order.customer.user.username == test_username
def test_browser_checkout_horizontal(browser, live_server, settings): # initialize product_name = "Test Product" get_default_shop() pm = get_default_payment_method() sm = get_default_shipping_method() product = create_orderable_product(product_name, "test-123", price=100) OrderStatus.objects.create(identifier="initial", role=OrderStatusRole.INITIAL, name="initial", default=True) # initialize test and go to front page browser = initialize_front_browser_test(browser, live_server) # check that front page actually loaded wait_until_condition(browser, lambda x: x.is_text_present("Welcome to Default!")) wait_until_condition(browser, lambda x: x.is_text_present("Newest Products")) wait_until_condition(browser, lambda x: x.is_text_present(product_name)) click_element(browser, "#product-%s" % product.pk) # open product from product list click_element(browser, "#add-to-cart-button-%s" % product.pk) # add product to basket wait_until_appeared(browser, ".cover-wrap") wait_until_disappeared(browser, ".cover-wrap") click_element( browser, "#navigation-basket-partial") # open upper basket navigation menu click_element(browser, "a[href='/basket/']") # click the link to basket in dropdown wait_until_condition( browser, lambda x: x.is_text_present("Shopping cart")) # we are in basket page wait_until_condition( browser, lambda x: x.is_text_present(product_name)) # product is in basket click_element(browser, "a[href='/checkout/']") # click link that leads to checkout customer_name = "Test Tester" customer_street = "Test Street" customer_city = "Test City" customer_region = "CA" customer_country = "US" # Fill all necessary information browser.fill("billing-name", customer_name) browser.fill("billing-street", customer_street) browser.fill("billing-city", customer_city) browser.select("billing-country", customer_country) wait_until_appeared(browser, "select[name='billing-region_code']") browser.select("billing-region_code", customer_region) click_element(browser, "#addresses button[type='submit']") wait_until_condition( browser, lambda x: x.is_text_present( "There were errors on submitted form fields. Please check them and try again." )) # Fill the errors browser.fill("shipping-name", customer_name) browser.fill("shipping-street", customer_street) browser.fill("shipping-city", customer_city) browser.select("shipping-country", customer_country) click_element(browser, "#addresses button[type='submit']") wait_until_condition( browser, lambda x: x.is_text_present("Checkout: Shipping & Payment")) wait_until_condition(browser, lambda x: x.is_text_present(sm.name) ) # shipping method name is present wait_until_condition( browser, lambda x: x.is_text_present(pm.name)) # payment method name is present click_element(browser, ".btn.btn-primary.btn-lg.pull-right" ) # click "continue" on methods page wait_until_condition(browser, lambda x: x.is_text_present( "Checkout: Confirmation")) # we are indeed in confirmation page # See that all expected texts are present wait_until_condition(browser, lambda x: x.is_text_present(product_name)) wait_until_condition(browser, lambda x: x.is_text_present(sm.name)) wait_until_condition(browser, lambda x: x.is_text_present(pm.name)) wait_until_condition(browser, lambda x: x.is_text_present("Delivery")) wait_until_condition(browser, lambda x: x.is_text_present("Billing")) # check that user information is available wait_until_condition(browser, lambda x: x.is_text_present(customer_name)) wait_until_condition(browser, lambda x: x.is_text_present(customer_street)) wait_until_condition(browser, lambda x: x.is_text_present(customer_city)) wait_until_condition(browser, lambda x: x.is_text_present("United States")) browser.execute_script( 'document.getElementById("id_accept_terms").checked=true' ) # click accept terms click_element(browser, ".btn.btn-primary.btn-lg") # click "place order" wait_until_condition(browser, lambda x: x.is_text_present( "Thank you for your order!")) # order succeeded