def test_recently_viewed_products(browser, live_server, settings): shop = get_default_shop() category = get_default_category() category.shops.add(shop) category.status = CategoryStatus.VISIBLE category.save() category_url = reverse("wshop:category", kwargs={ "pk": category.pk, "slug": category.slug }) products = [] for i in range(1, 7): products.append(new_product(i, shop, category)) browser = initialize_front_browser_test(browser, live_server) for i, product in enumerate(products, 1): product_url = reverse("wshop:product", kwargs={ "pk": product.pk, "slug": product.slug }) browser.visit(live_server + product_url) wait_until_appeared(browser, ".product-main") browser.visit(live_server + category_url) wait_until_appeared(browser, ".categories-nav") items = browser.find_by_css(".recently-viewed li") assert items.first.text == product.name, "recently clicked product on top" assert len(items) == min(i, 5)
def _visit_list_view(browser, live_server, list_view_name): url = reverse("wshop_admin:%s.list" % list_view_name) browser.visit("%s%s" % (live_server, url)) wait_until_condition( browser, lambda x: x.is_text_present(list_view_settings[list_view_name] ["page_header"])) wait_until_appeared(browser, ".picotable-item-info")
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 _test_customer_using_search(browser, person): click_element(browser, "#customer-search .select2") wait_until_appeared(browser, "input.select2-search__field") browser.find_by_css( "input.select2-search__field").first.value = person.name wait_until_appeared( browser, ".select2-results__option:not([aria-live='assertive'])") browser.execute_script( '$($(".select2-results__option")[0]).trigger({type: "mouseup"})') wait_until_condition( browser, lambda x: len(x.find_by_css(".view-details-link")) == 1)
def set_status(browser, order, status): click_element(browser, "button.set-status-button") form_action = reverse("wshop_admin:order.set-status", kwargs={"pk": order.pk}) click_element( browser, "button[formaction='%s'][value='%s']" % (form_action, status.pk)) wait_until_appeared(browser, "div[class='message success']") wait_until_condition( browser, condition=lambda x: x.is_text_present("Order %s" % order.pk)) order.refresh_from_db() assert order.status.pk == status.pk
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 _test_regions(browser, person): with pytest.raises(ElementDoesNotExist): browser.find_by_css("input[name='billing-region_code']").first assert browser.find_by_css("input[name='billing-region']").first browser.select("billing-country", "US") wait_until_appeared(browser, "select[name='billing-region_code']") with pytest.raises(ElementDoesNotExist): browser.find_by_css("input[name='billing-region']").first browser.select("billing-region_code", "CA") browser.select("billing-country", "CG") # Congo does not have regions defined wait_until_appeared(browser, "input[name='billing-region']") browser.select("billing-country", person.default_billing_address.country)
def _test_customer_data(browser, person): browser.driver.execute_script("window.scrollTo(0, 200);") # check defaults assert browser.find_by_css( "input[name='save-address']").first.checked == True assert browser.find_by_css( "input[name='ship-to-billing-address']").first.checked == False assert browser.find_by_css( "input[name='order-for-company']").first.checked == False assert not browser.find_by_css( "input[name='billing-tax_number']").first['required'] browser.find_by_css("input[name=ship-to-billing-address]").check() assert browser.find_by_css( "input[name=ship-to-billing-address]").first.checked browser.find_by_css("input[name='order-for-company']").check() assert browser.find_by_css("input[name='order-for-company']").first.checked wait_until_condition( browser, lambda x: x.find_by_css("input[name='billing-tax_number']"). first['required']) assert len(browser.find_by_css("input[name='shipping-name']") ) == 0, "shipping address column is hidden" browser.find_by_css("input[name='order-for-company']").uncheck() click_element(browser, "#select-existing-customer") browser.windows.current = browser.windows[1] wait_until_appeared(browser, "a") # click second row - first row is admin browser.find_by_css("tbody tr")[1].find_by_css("a").click() # Wait until there is only one window left # after that is safe to switch the current window # back and test the results of the customer pick. wait_until_condition(browser, lambda x: len(browser.windows) == 1, timeout=30) browser.windows.current = browser.windows[0] # check fields were set wait_until_condition( browser, lambda x: x.find_by_name("billing-name").value == person.name) assert browser.find_by_name("billing-name").value == person.name assert browser.find_by_name( "billing-street").value == person.default_billing_address.street assert browser.find_by_name( "billing-city").value == person.default_billing_address.city assert browser.find_by_name( "billing-country").value == person.default_billing_address.country click_element(browser, "#clear-customer") wait_until_condition( browser, lambda x: "new customer" in x.find_by_css( "#customer-description").text)
def _test_confirm(browser): total = sum([ decimal.Decimal(total_el.value) for total_el in browser.find_by_css("input[name='total']") ]) assert str(total) in browser.find_by_css( ".order-footer h2").text, "order total is correct" click_element(browser, ".order-footer button") wait_until_appeared(browser, ".btn-danger") # wait until the back button appears assert len( browser.find_by_css("table tbody tr") ) == 4, "1 line items, 2 methods, 1 total line shown in confirmation table" # click confirm click_element(browser, ".btn-success") wait_until_appeared(browser, "#details-section") assert Order.objects.count() == 1, "order created"
def _set_settings(browser, setting_type): used_settings = list_view_settings[setting_type] default_column_count = used_settings["default_column_count"] addable_fields = used_settings["addable_fields"] # not selected by default for idx, text in addable_fields: assert not browser.is_text_present(text) #wshop_tests/browser/front/test_category_view.py settings_xpath = "(//a[contains(text(),'Settings')])[2]" # go to settings browser.find_by_xpath(settings_xpath).click() # select settings for idx, (index_key, text) in enumerate(addable_fields): expected_index = default_column_count + 1 + idx assert browser.is_text_present(text) browser.find_by_xpath("//ul[@id='source-sortable']/li[%d]/button" % index_key).first.click() wait_until_appeared_xpath( browser, "//ul[@id='target-sortable']/li[%d]/button" % expected_index) # save settings browser.find_by_css(".btn.btn-success").first.click() wait_until_appeared(browser, ".picotable-item-info") for idx, text in addable_fields: wait_until_condition(browser, lambda x: x.is_text_present(text)) # go back to settings browser.find_by_xpath(settings_xpath).click() wait_until_appeared_xpath(browser, "//a[contains(text(),'Reset Defaults')]") # reset to defaults browser.find_by_xpath("//a[contains(text(),'Reset Defaults')]").click() # wait wait_until_appeared(browser, ".picotable-item-info") # not selected by default for idx, text in addable_fields: assert not browser.is_text_present(text)
def _test_add_lines(browser): line_items_before = browser.find_by_id("lines").find_by_css( '.list-group-item') click_element(browser, "#add-line") wait_until_condition( browser, lambda x: len(x.find_by_css("#lines .list-group-item")) == len(line_items_before) + 1) # Make sure that the lines is present before # selecting product for the order line. original_window_name = browser.windows.current.name wait_until_condition( browser, lambda x: x.is_element_present_by_css( "#lines .list-group-item:last-child a")) click_element(browser, "#lines .list-group-item:last-child a") browser.windows.current = browser.windows[1] wait_until_appeared(browser, "a") browser.find_by_css("tbody tr")[1].find_by_css("a").click() # Wait until there is only one window left # after that is safe to switch the current window # back and test the results of the product pick. wait_until_condition(browser, lambda x: len(browser.windows) == 1, timeout=30) browser.windows.current = browser.windows[0] browser.windows.current.close_others() wait_until_condition( browser, lambda x: browser.windows.current.name == original_window_name, timeout=30) wait_until_condition( browser, lambda x: x.find_by_css( '#lines .list-group-item:last-child input[name="total"]').first. value == "10") last_line_item = browser.find_by_css("#lines .list-group-item:last-child") assert last_line_item.find_by_css( 'input[name="quantity"]').first.value == "1", "1 piece added" assert last_line_item.find_by_css( 'input[name="total"]').first.value == "10", "line item total is 10"
def guest_ordering_test(browser, live_server): browser.fill("login-username", "test-username") click_element(browser, "button[name='login']") wait_until_appeared(browser, "div.form-group.passwordinput.required.has-error") browser.fill("login-password", "test-password") click_element(browser, "button[name='login']") wait_until_condition( browser, lambda x: x.is_text_present( "Please enter a correct username and password.")) wait_until_appeared(browser, "div.alert.alert-danger") click_element(browser, "button[data-id='id_checkout_method_choice-register']") click_element(browser, "li[data-original-index='0'] a") click_element(browser, "div.clearfix button.btn.btn-primary.btn-lg.pull-right") wait_until_condition(browser, lambda x: x.is_text_present("Checkout: Addresses")) url = reverse("wshop:checkout", kwargs={"phase": "checkout_method"}) browser.visit("%s%s" % (live_server, url))
def _test_refund_view(browser, live_server, order): url = reverse("wshop_admin:order.create-refund", kwargs={"pk": order.pk}) browser.visit("%s%s" % (live_server, url)) wait_until_condition( browser, lambda x: x.is_text_present("Refunded: %s" % format_money( order.shop.create_price("0.00")))) assert len(browser.find_by_css("#id_form-0-line_number option") ) == 12 # blank + arbitrary amount + num lines click_element(browser, "#select2-id_form-0-line_number-container") wait_until_appeared(browser, "input.select2-search__field") browser.execute_script( '$($(".select2-results__option")[1]).trigger({type: "mouseup"})' ) # select arbitrary amount wait_until_condition(browser, lambda x: len(x.find_by_css("#id_form-0-text"))) wait_until_condition(browser, lambda x: len(x.find_by_css("#id_form-0-amount"))) browser.find_by_css("#id_form-0-text").first.value = "test" browser.find_by_css("#id_form-0-amount").first.value = "900" click_element(browser, "#add-refund") click_element(browser, "#select2-id_form-1-line_number-container") wait_until_appeared(browser, "input.select2-search__field") browser.execute_script( '$($(".select2-results__option")[2]).trigger({type: "mouseup"})' ) # select first line assert decimal.Decimal( browser.find_by_css( "#id_form-1-amount").first.value) == decimal.Decimal("100.00") assert int( decimal.Decimal( browser.find_by_css("#id_form-1-quantity").first.value)) == 10 click_element(browser, "button[form='create_refund']") _check_create_refund_link(browser, order, True) # can still refund quantity _check_order_details_visible(browser) order.refresh_from_db() assert not order.taxful_total_price assert order.is_paid() assert not order.is_fully_shipped()
def test_product_create(browser, admin_user, live_server, settings): activate("en") shop = get_default_shop() get_default_product_type() get_default_sales_unit() get_default_tax_class() configuration.set(None, "wshop_product_tour_complete", True) object_created.connect(_add_custom_product_created_message, sender=Product, dispatch_uid="object_created_signal_test") initialize_admin_browser_test(browser, live_server, settings) browser.driver.set_window_size(1920, 1080) url = reverse("wshop_admin:shop_product.new") browser.visit("%s%s" % (live_server, url)) sku = "testsku" name = "Some product name" price_value = 10 short_description = "short but gold" browser.fill("base-sku", sku) browser.fill("base-name__en", name) browser.fill("base-short_description__en", short_description) browser.fill("shop%s-default_price_value" % shop.pk, price_value) configuration.set(None, "wshop_category_tour_complete", True) _add_primary_category(browser, shop) _add_additional_category(browser, shop) click_element(browser, "button[form='product_form']") wait_until_appeared(browser, "div[class='message success']") product = Product.objects.filter(sku=sku).first() assert product.log_entries.filter( identifier=OBJECT_CREATED_LOG_IDENTIFIER).count() == 1 object_created.disconnect(sender=Product, dispatch_uid="object_created_signal_test") shop_product = product.get_shop_instance(shop) assert shop_product.categories.count() == 2
def _test_quick_add_lines(browser): assert browser.find_by_css("input[name='auto-add']").first.checked == True # add line automatically just by searching and finding direct match click_element(browser, "#quick-add .select2") wait_until_condition( browser, lambda x: len( browser.find_by_css("#quick-add .select2-container--open")) == 1) browser.find_by_css( "input.select2-search__field").first.value = "test-sku1" wait_until_condition( browser, lambda x: len(x.find_by_css("#lines .list-group-item")) == 1) line_items = browser.find_by_css("#lines .list-group-item") assert len(browser.find_by_css("#quick-add .select2-container--open") ) == 1, "select is open after add" assert line_items.first.find_by_css( 'input[name="quantity"]').first.value == '1', "one piece added" browser.find_by_css( "input.select2-search__field").first.value = "test-sku1" wait_until_condition( browser, lambda x: x.find_by_css('#lines input[name="quantity"]').first .value == '2') line_items = browser.find_by_id("lines").find_by_css('.list-group-item') assert len(line_items) == 1, "only one line item exists" assert line_items.first.find_by_css( 'input[name="quantity"]').first.value == '2', "two pieces added" # add line automatically by searching and clicking on match browser.find_by_css("input.select2-search__field").first.value = "test-sku" wait_until_appeared( browser, ".select2-results__option:not([aria-live='assertive'])") browser.execute_script( '$($(".select2-results__option")[0]).trigger({type: "mouseup"})') wait_until_condition( browser, lambda x: x.find_by_css('#lines input[name="quantity"]').first .value == '3') assert line_items.first.find_by_css( 'input[name="quantity"]').first.value == '3', "three pieces added" # add line manually browser.uncheck("auto-add") click_element(browser, "#quick-add .select2") wait_until_appeared(browser, "input.select2-search__field") browser.find_by_css( "input.select2-search__field").first.value = "test-sku0" wait_until_appeared( browser, ".select2-results__option:not([aria-live='assertive'])") browser.execute_script( '$($(".select2-results__option")[0]).trigger({type: "mouseup"})') wait_until_condition( browser, lambda x: len(x.find_by_css('#lines .list-group-item')) == 2) line_items = browser.find_by_id("lines").find_by_css('.list-group-item') assert len(line_items) == 2, "two line items exist" click_element(browser, "#lines .list-group-item:last-child .delete button") wait_until_condition( browser, lambda x: len(x.find_by_css("#lines .list-group-item")) == 1)
def test_product_detail(browser, admin_user, live_server, settings): shop = get_default_shop() product = create_product("test_sku", shop, default_price=10) configuration.set(None, "wshop_product_tour_complete", True) initialize_admin_browser_test(browser, live_server, settings) url = reverse("wshop_admin:shop_product.edit", kwargs={"pk": product.get_shop_instance(shop).pk}) browser.visit("%s%s" % (live_server, url)) assert browser.find_by_id("id_base-sku").value == product.sku # Test product save new_sku = "some-new-sku" browser.find_by_id("id_base-sku").fill(new_sku) browser.execute_script("window.scrollTo(0,0)") click_element(browser, "button[form='product_form']") wait_until_condition( browser, condition=lambda x: x.is_text_present("Product edited")) product.refresh_from_db() check_product_name(browser, product, new_sku) # Test that toolbar action item is there dropdowns = browser.find_by_css(".btn.dropdown-toggle") for dropdown in dropdowns: if "Actions" in dropdown.text: dropdown.click() wait_until_appeared(browser, "a[href='#%s']" % product.sku) click_element(browser, "a[href='#%s']" % product.sku) # Make sure that the tabs is clickable in small devices browser.driver.set_window_size(480, 960) click_element(browser, "#product-images-section", header_height=320) click_element(browser, "#additional-details-section", header_height=320)
def _visit_orders_list_view(browser, live_server): url = reverse("wshop_admin:order.list") browser.visit("%s%s" % (live_server, url)) wait_until_condition(browser, condition=lambda x: x.is_text_present("Orders")) wait_until_appeared(browser, ".picotable-item-info")
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 _goto_page(browser, page_number): click_element(browser, "a[rel='%s']" % page_number) wait_until_appeared(browser, "li.active a[rel='%s']" % page_number)
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 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