def second_category_sort_test(browser, live_server, shop, category): url = reverse("shuup:category", kwargs={"pk": category.pk, "slug": category.slug}) browser.visit("%s%s" % (live_server, url)) wait_until_condition(browser, lambda x: x.is_element_present_by_css("button[data-id='id_limit']"), timeout=30) # Set limit to 24 click_element(browser, "button[data-id='id_limit']") click_element(browser, "button[data-id='id_limit'] + .dropdown-menu li[data-original-index='1'] a") wait_until_condition(browser, lambda x: len(x.find_by_css(".product-card")) == 13, timeout=30) # Check that visibility change affects the product count shop_products = ShopProduct.objects.filter(primary_category_id=category.id)[:3] for sp in shop_products: sp.visibility = ShopProductVisibility.NOT_VISIBLE sp.save() cache.clear() browser.reload() wait_until_condition(browser, lambda x: len(x.find_by_css(".product-card")) == 10) for sp in shop_products: sp.visibility = ShopProductVisibility.ALWAYS_VISIBLE sp.save() cache.clear() browser.reload() wait_until_condition(browser, lambda x: len(x.find_by_css(".product-card")) == 13, timeout=30)
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"
def _test_customer_data(browser, person): # 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.check("ship-to-billing-address") browser.check("order-for-company") assert len(browser.find_by_css("input[name='shipping-name']")) == 0, "shipping address column is hidden" assert browser.find_by_css("input[name='billing-tax_number']").first['required'], "tax number is required" browser.uncheck("order-for-company") 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() 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
def test_category_tour(browser, admin_user, live_server, settings): shop = factories.get_default_shop() shop2 = factories.get_shop(identifier="shop2") admin_user_2 = factories.create_random_user(is_staff=True, is_superuser=True) admin_user_2.set_password("password") admin_user_2.save() shop.staff_members.add(admin_user) shop.staff_members.add(admin_user_2) for user in [admin_user, admin_user_2]: initialize_admin_browser_test(browser, live_server, settings, username=user.username, tour_complete=False) wait_until_condition(browser, lambda x: x.is_text_present("Welcome!")) browser.visit(live_server + "/sa/categories/new") wait_until_condition(browser, lambda x: x.is_text_present("Add a new product category"), timeout=30) wait_until_condition(browser, lambda x: x.is_element_present_by_css(".shepherd-button.btn-primary")) click_element(browser, ".shepherd-button.btn-primary") wait_until_condition(browser, lambda x: not x.is_element_present_by_css(".shepherd-button")) wait_until_condition(browser, lambda x: is_tour_complete(shop, "category", user)) # check whether the tour is shown again browser.visit(live_server + "/sa/categories/new") wait_until_condition(browser, lambda x: not x.is_text_present("Add a new product category")) browser.visit(live_server + "/logout") browser.visit(live_server + "/sa") assert is_tour_complete(shop2, "category", user) is False
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, "shuup_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) url = reverse("shuup_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, "shuup_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 _save_category(iframe): # TODO: Revise! It seems that iframes are hard for Travis time.sleep(3) # Let's just wait here to the iFrame to open fully (for Chrome and headless) wait_until_appeared(iframe, "button[form='category_form']") try: click_element(iframe, "button[form='category_form']") except selenium.common.exceptions.SessionNotCreatedException as e: click_element(iframe, "button[form='category_form']")
def test_product_tour(browser, admin_user, live_server, settings): shop = factories.get_default_shop() shop2 = factories.get_shop(identifier="shop2") admin_user_2 = factories.create_random_user(is_staff=True, is_superuser=True) admin_user_2.set_password("password") admin_user_2.save() product = factories.get_default_product() shop_product = product.get_shop_instance(shop) shop.staff_members.add(admin_user) shop.staff_members.add(admin_user_2) for user in [admin_user, admin_user_2]: initialize_admin_browser_test(browser, live_server, settings, username=user.username, tour_complete=False) wait_until_condition(browser, lambda x: x.is_text_present("Welcome!")) browser.visit(live_server + "/sa/products/%d/" % shop_product.pk) wait_until_condition(browser, lambda x: x.is_text_present(shop_product.product.name)) # as this is added through javascript, add an extra timeout wait_until_condition(browser, lambda x: x.is_text_present("You are adding a product."), timeout=30) wait_until_condition(browser, lambda x: x.is_element_present_by_css(".shepherd-button.btn-primary")) click_element(browser, ".shepherd-button.btn-primary") category_targets = [ "a.shepherd-enabled[href='#basic-information-section']", "a.shepherd-enabled[href='#additional-details-section']", "a.shepherd-enabled[href='#manufacturer-section']", "a.shepherd-enabled[href*='-additional-section']", "a.shepherd-enabled[href='#product-media-section']", "a.shepherd-enabled[href='#product-images-section']", "a.shepherd-enabled[href='#contact-group-pricing-section']", "a.shepherd-enabled[href='#contact-group-discount-section']" ] # Scroll top before starting to click. For some reason the first # item is not found without this. For Firefox or Chrome the browser # does not do any extra scroll which could hide the first item. # Steps are scrollTo false on purpose since the scrollTo true is the # config which does not work in real world. browser.execute_script("window.scrollTo(0,0)") for target in category_targets: try: wait_until_condition(browser, lambda x: x.is_element_present_by_css(target)) browser.find_by_css(".shepherd-button.btn-primary").last.click() except ElementNotInteractableException: move_to_element(browser, ".shepherd-button.btn-primary") wait_until_condition(browser, lambda x: x.is_element_present_by_css(target)) browser.find_by_css(".shepherd-button.btn-primary").last.click() wait_until_condition(browser, lambda x: is_tour_complete(shop, "product", user)) # check whether the tour is shown again browser.visit(live_server + "/sa/products/%d/" % shop_product.pk) wait_until_condition(browser, lambda x: not x.is_text_present("You are adding a product."), timeout=20) assert is_tour_complete(shop2, "product", user) is False browser.visit(live_server + "/logout") browser.visit(live_server + "/sa")
def set_status(browser, order, status): click_element(browser, "button.set-status-button") form_action = reverse("shuup_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 second_category_page_change(browser, live_server, shop, category): url = reverse("shuup:category", kwargs={"pk": category.pk, "slug": category.slug}) browser.visit("%s%s" % (live_server, url)) assert not browser.is_text_present("Sort") # Sort shouldn't be available since default configurations wait_until_condition(browser, lambda x: len(x.find_by_css(".product-card")) == 12) click_element(browser, "#next_page a") wait_until_condition(browser, lambda x: len(x.find_by_css(".product-card")) == 1, timeout=30) click_element(browser, "#previous_page a") wait_until_condition(browser, lambda x: len(x.find_by_css(".product-card")) == 12, timeout=30)
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")) == 5, "2 line items, 2 methods, 1 total line shown in confirmation table" # click confirm click_element(browser, ".btn-success") wait_until_appeared(browser, "#details-status-section") assert Order.objects.count() == 1, "order created"
def _activate_basket_campaign_through_coupon(browser, category, shop): # We should already be at basket so let's verify the total wait_until_condition(browser, lambda x: "110.53" in x.find_by_css("div.total-price strong").first.text) coupon_code = _create_coupon_campaign(category, shop) browser.fill("code", coupon_code) click_element(browser, "#submit-code") wait_until_condition(browser, lambda x: x.is_text_present(coupon_code)) wait_until_condition(browser, lambda x: "-€22.11" in x.find_by_css("div.product-sum h4.price").last.text) wait_until_condition(browser, lambda x: "€88.42" in x.find_by_css("div.total-price strong").first.text)
def test_xtheme_snippet_injection(browser, admin_user, live_server, settings): shop = factories.get_default_shop() initialize_admin_browser_test(browser, live_server, settings) url = reverse("shuup_admin:xtheme_snippet.new") browser.visit("%s%s" % (live_server, url)) wait_until_condition(browser, lambda x: x.is_text_present("New Snippet")) browser.execute_script("$(\"[name='location']\").val('body_end').trigger('change')") browser.execute_script("$(\"[name='snippet_type']\").val('inline_js').trigger('change')") browser.execute_script("window.CodeMirror.editors['id_snippet-snippet'].setValue('alert(\"works\")');") click_element(browser, "button[type='submit']") wait_until_appeared(browser, "div[class='message success']") url = reverse("shuup:index") browser.visit("%s%s" % (live_server, url)) def has_alert(browser): try: return browser.get_alert().text == "works" except: return False wait_until_condition(browser, has_alert) browser.get_alert().accept() theme = get_current_theme(shop) snippet = Snippet.objects.filter(shop=shop).first() snippet.themes = [theme.identifier] snippet.save() cache.clear() browser.visit("%s%s" % (live_server, url)) wait_until_condition(browser, has_alert) browser.get_alert().accept() snippet.themes = ["doesnt-exist"] snippet.save() cache.clear() browser.visit("%s%s" % (live_server, url)) wait_until_condition(browser, lambda x: x.is_text_present("Welcome to Default!")) with pytest.raises(Exception): browser.get_alert() # delete the snippet url = reverse("shuup_admin:xtheme_snippet.edit", kwargs=dict(pk=snippet.pk)) browser.visit("%s%s" % (live_server, url)) assert Snippet.objects.filter(shop=shop).exists() click_element(browser, ".shuup-toolbar button.btn.btn-danger") browser.get_alert().accept() wait_until_condition(browser, lambda x: not Snippet.objects.filter(shop=shop).exists())
def test_home_tour(browser, admin_user, live_server, settings): shop = factories.get_default_shop() shop2 = factories.get_shop(identifier="shop2") admin_user_2 = factories.create_random_user(is_staff=True, is_superuser=True) admin_user_2.set_password("password") admin_user_2.save() shop.staff_members.add(admin_user) shop.staff_members.add(admin_user_2) for user in [admin_user, admin_user_2]: initialize_admin_browser_test(browser, live_server, settings, username=user.username, tour_complete=False) wait_until_condition(browser, lambda x: x.is_text_present("Welcome!")) browser.visit(live_server + "/sa/home") wait_until_condition(browser, lambda x: x.is_text_present("Hi, new shop owner!"), timeout=30) wait_until_condition(browser, lambda x: x.is_element_present_by_css(".shepherd-button.btn-primary")) click_element(browser, ".shepherd-button.btn-primary") category_targets = [ ".shepherd-enabled[data-target-id='category-1'", ".shepherd-enabled[data-target-id='category-2'", ".shepherd-enabled[data-target-id='category-3'", ".shepherd-enabled[data-target-id='category-5'", ".shepherd-enabled[data-target-id='category-9'", ".shepherd-enabled[data-target-id='category-4'", ".shepherd-enabled[data-target-id='category-6'", ".shepherd-enabled[data-target-id='category-7'", ".shepherd-enabled[data-target-id='category-8'", ".shepherd-enabled#site-search", ".shepherd-enabled.shop-btn.visit-store", ] for target in category_targets: wait_until_condition(browser, lambda x: x.is_element_present_by_css(target)) move_to_element(browser, ".shepherd-button.btn-primary") browser.find_by_css(".shepherd-button.btn-primary").last.click() wait_until_condition(browser, lambda x: x.is_text_present("We're done!"), timeout=30) move_to_element(browser, ".shepherd-button.btn-primary") browser.find_by_css(".shepherd-button.btn-primary").last.click() wait_until_condition(browser, lambda x: is_tour_complete(shop, "home", user)) # check whether the tour is shown again browser.visit(live_server + "/sa/home") wait_until_condition(browser, lambda x: not x.is_text_present("Hi, new shop owner!")) browser.visit(live_server + "/logout") browser.visit(live_server + "/sa") wait_until_condition(browser, lambda x: not x.is_text_present("Hi, new shop owner!")) assert is_tour_complete(shop2, "home", user) is False
def _add_additional_category(browser, shop): assert Category.objects.count() == 1 select_id = "id_shop%s-categories" % shop.pk wait_until_condition(browser, lambda x: len(x.find_by_css("#%s option[selected='']" % select_id)) == 1) browser.execute_script('$("#%s").parent().find("span.quick-add-btn a.btn").click();' % select_id) with browser.get_iframe('create-object-iframe') as iframe: wait_until_condition(iframe, lambda x: x.is_text_present("New category")) category_test_name = "Test Category 2" iframe.fill("base-name__en", category_test_name) click_element(iframe, "button[form='category_form']") wait_until_condition(browser, lambda x: x.is_text_present("New product")) assert Category.objects.count() == 2 wait_until_condition(browser, lambda x: len(x.find_by_css("#%s option[selected='']" % select_id)) == 2)
def change_addresses(live_server, browser, order): edit_url = reverse("shuup_admin:order.edit-addresses", kwargs={"pk": order.pk}) browser.visit("%s%s" % (live_server, edit_url)) order_edited_log_entries = order.log_entries.filter(identifier=ADDRESS_EDITED_LOG_IDENTIFIER).count() edit_address_title = "Save -- Order %s" % order.pk wait_until_condition(browser, condition=lambda x: x.is_text_present(edit_address_title)) # Do nothing just hit the save click_element(browser, "button[form='edit-addresses']") assert order.log_entries.filter(identifier=ADDRESS_EDITED_LOG_IDENTIFIER).count() == order_edited_log_entries # Update billing address email browser.visit("%s%s" % (live_server, edit_url)) wait_until_condition(browser, condition=lambda x: x.is_text_present(edit_address_title)) new_email = "*****@*****.**" browser.fill("billing_address-email", new_email) assert new_email != order.billing_address.email click_element(browser, "button[form='edit-addresses']") check_log_entries_count(browser, order, order_edited_log_entries + 1) order.refresh_from_db() assert new_email == order.billing_address.email assert order.billing_address.email != order.shipping_address.email assert order.billing_address.pk != order.shipping_address.pk # Update shipping address postal code browser.visit("%s%s" % (live_server, edit_url)) wait_until_condition(browser, condition=lambda x: x.is_text_present(edit_address_title)) new_postal_code = "20540" browser.fill("shipping_address-postal_code", new_postal_code) assert new_postal_code != order.shipping_address.postal_code click_element(browser, "button[form='edit-addresses']") check_log_entries_count(browser, order, order_edited_log_entries + 2) order.refresh_from_db() assert new_postal_code == order.shipping_address.postal_code assert order.billing_address.postal_code != order.shipping_address.postal_code assert order.billing_address.pk != order.shipping_address.pk # Now update both same time browser.visit("%s%s" % (live_server, edit_url)) wait_until_condition(browser, condition=lambda x: x.is_text_present(edit_address_title)) click_element(browser, "#billing-to-shipping") new_name = "%s (edited)" % order.billing_address.name browser.fill("billing_address-name", new_name) click_element(browser, "button[form='edit-addresses']") check_log_entries_count(browser, order, order_edited_log_entries + 4) order.refresh_from_db() assert new_name == order.shipping_address.name assert order.billing_address.name == order.shipping_address.name assert order.billing_address.email == order.shipping_address.email
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, "shuup_product_tour_complete", True) initialize_admin_browser_test(browser, live_server, settings) url = reverse("shuup_admin:product.edit", kwargs={"pk": product.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']") product.refresh_from_db() assert product.sku == 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() 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 _test_refund_view(browser, live_server, order): url = reverse("shuup_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") wait_until_appeared(browser, ".select2-results__option[aria-selected='false']") 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" move_to_element(browser, "#add-refund") click_element(browser, "#add-refund") # New line starts here... move_to_element(browser, "#add-refund") click_element(browser, "#select2-id_form-1-line_number-container") wait_until_appeared(browser, "input.select2-search__field") elem = browser.find_by_css("input.select2-search__field").first elem._element.send_keys("line 1") elem._element.send_keys(Keys.RETURN) 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 second_category_sort_test(browser, live_server, shop, category): url = reverse("shuup:category", kwargs={"pk": category.pk, "slug": category.slug}) browser.visit("%s%s" % (live_server, url)) assert not browser.is_text_present("Sort") # Sort shouldn't be available since default configurations wait_until_condition(browser, lambda x: len(x.find_by_css(".product-card")) == 12) click_element(browser, "#next_page a") wait_until_condition(browser, lambda x: len(x.find_by_css(".product-card")) == 1, timeout=30) click_element(browser, "#previous_page a") wait_until_condition(browser, lambda x: len(x.find_by_css(".product-card")) == 12, timeout=30) # Activate limit page size changer set_configuration( shop=shop, data={ "sort_products_by_name": True, "sort_products_by_name_ordering": 1, "sort_products_by_price": True, "sort_products_by_price_ordering": 2, "limit_product_list_page_size": True } ) browser.reload() # Set limit to 24 click_element(browser, "button[data-id='id_limit']") click_element(browser, "button[data-id='id_limit'] + .dropdown-menu li[data-original-index='1'] a") wait_until_condition(browser, lambda x: len(x.find_by_css(".product-card")) == 13)
def test_quick_add(browser, admin_user, live_server, settings): shop = get_default_shop() get_default_product_type() get_default_sales_unit() get_default_tax_class() initialize_admin_browser_test(browser, live_server, settings) url = reverse("shuup_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) wait_until_appeared(browser, "#id_shop%d-primary_category ~ .quick-add-btn a.btn" % shop.id) click_element(browser, "#id_shop%d-primary_category ~ .quick-add-btn a.btn" % shop.id) wait_until_appeared(browser, "#create-object-iframe") with browser.get_iframe('create-object-iframe') as iframe: assert Category.objects.count() == 0 wait_until_appeared(iframe, "input[name='base-name__en']") iframe.fill("base-name__en", "Test Category") time.sleep(3) # Let's just wait here to the iFrame to open fully (for Chrome and headless) wait_until_appeared(iframe, "button[form='category_form']") click_element(browser, "button[form='category_form']") wait_until_condition(browser, condition=lambda x: Category.objects.count() == 1, timeout=20) assert Category.objects.first().name == "Test Category" # click to edit the button click_element(browser, "#id_shop%d-primary_category ~ .edit-object-btn a.btn" % shop.id) with browser.get_iframe('create-object-iframe') as iframe: wait_until_appeared(iframe, "input[name='base-name__en']") new_cat_name = "Changed Name" iframe.fill("base-name__en", new_cat_name) time.sleep(3) # Let's just wait here to the iFrame to open fully (for Chrome and headless) wait_until_appeared(iframe, "button[form='category_form']") click_element(iframe, "button[form='category_form']") wait_until_condition(browser, condition=lambda x: Category.objects.first().name == new_cat_name, timeout=20) click_element(browser, "button[form='product_form']") wait_until_appeared(browser, "div[class='message success']")
def _test_create_full_refund(browser, live_server, order): url = reverse("shuup_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")))) wait_until_condition(browser, lambda x: x.is_text_present("Remaining: %s" % format_money(order.taxful_total_price))) url = reverse("shuup_admin:order.create-full-refund", kwargs={"pk": order.pk}) click_element(browser, "a[href='%s']" % url) wait_until_condition(browser, lambda x: x.is_text_present("Refund Amount: %s" % format_money(order.taxful_total_price))) click_element(browser, "#create-full-refund") wait_until_appeared(browser, "#order_details") _check_create_refund_link(browser, order, False) order.refresh_from_db() assert not order.taxful_total_price assert order.is_paid() assert order.is_fully_shipped()
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("shuup:checkout", kwargs={"phase": "checkout_method"}) browser.visit("%s%s" % (live_server, url))
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 _add_primary_category(browser, shop): assert Category.objects.count() == 0 select_id = "id_shop%s-primary_category" % shop.pk move_to_element(browser, "#%s" % select_id, header_height=100) # Quick add new primary category wait_until_appeared(browser, "#id_shop%d-primary_category ~ .quick-add-btn a.btn" % shop.id) click_element(browser, "#id_shop%d-primary_category ~ .quick-add-btn a.btn" % shop.id) wait_until_appeared(browser, "#create-object-iframe") with browser.get_iframe('create-object-iframe') as iframe: wait_until_appeared(iframe, "input[name='base-name__en']") iframe.fill("base-name__en", "Test Category") _save_category(iframe) wait_until_condition(browser, condition=lambda x: not x.is_element_present_by_id("create-object-overlay")) check_category_count(browser, 1) wait_until_condition(browser, lambda x: len(x.find_by_css("#%s option" % select_id)) == 1)
def _add_product_to_basket_from_category(live_server, browser, first_category, shop): url = reverse("shuup: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_category_product_discount(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_category_product_discount(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_xtheme_plugin_form_language_order(admin_user, browser, live_server, settings, default_language): """ Test that the first language option is the Parler default As you can see, we check for that the page has loaded and we use a sleep of 1 second. This is necessary specially into iframes. On this test, when we click to add a new plugin row or after a row selection, the iframe content is changed through a request, like a internal link when user clicks on a anchor. We have to make sure the NEW content is loaded before doing any element check, because it looks like the iframe won't find the correct elements if you start checking that before the new content gets loaded. """ with override_settings(PARLER_DEFAULT_LANGUAGE_CODE=default_language): browser = initialize_admin_browser_test(browser, live_server, settings) browser.visit(live_server + "/") # Start edit wait_until_condition(browser, lambda x: page_has_loaded(x), timeout=20) wait_until_appeared(browser, ".xt-edit-toggle button[type='submit']") click_element(browser, ".xt-edit-toggle button[type='submit']") placeholder_selector = "#xt-ph-front_content-xtheme-person-contact-layout" placeholder_name = "front_content" wait_until_condition(browser, lambda x: x.is_element_present_by_css(placeholder_selector)) click_element(browser, placeholder_selector) with browser.get_iframe("xt-edit-sidebar-iframe") as iframe: # make sure all scripts are loaded wait_until_condition(iframe, lambda x: page_has_loaded(x), timeout=20) wait_until_condition(iframe, lambda x: x.is_text_present("Edit Placeholder: %s" % placeholder_name)) wait_until_appeared(iframe, "button.layout-add-row-btn") time.sleep(1) wait_until_condition(iframe, lambda x: page_has_loaded(x), timeout=20) # click to add a new row click_element(iframe, "button.layout-add-row-btn") time.sleep(1) wait_until_condition(iframe, lambda x: page_has_loaded(x), timeout=20) # select the last row (the added one) click_element(iframe, "button.layout-add-row-btn") iframe.find_by_css("div.layout-cell").last.click() time.sleep(1) wait_until_condition(iframe, lambda x: page_has_loaded(x), timeout=20) # select the TextPlugin wait_until_appeared(iframe, "select[name='general-plugin']") iframe.select("general-plugin", "text") time.sleep(1) wait_until_condition(iframe, lambda x: page_has_loaded(x), timeout=20) wait_until_appeared(iframe, "ul.editor-tabs") # check the languages order languages = [el.text for el in iframe.find_by_css("ul.editor-tabs li a")] assert languages[0] == default_language
def test_gdpr_consent(browser, live_server, settings): shop = get_default_shop() index_url = reverse("shuup:index") # create a GDPR setting for the shop shop_gdpr = GDPRSettings.get_for_shop(shop) shop_gdpr.cookie_banner_content = "my cookie banner content" shop_gdpr.cookie_privacy_excerpt = "my cookie privacyexcerpt" shop_gdpr.enabled = True shop_gdpr.save() # Enable GDPR browser = initialize_front_browser_test(browser, live_server) browser.visit("%s%s" % (live_server, index_url)) wait_until_appeared(browser, ".gdpr-consent-warn-bar") assert (len(browser.find_by_css(".gdpr-consent-preferences")) == 1) click_element(browser, "#agree-btn") wait_until_condition(browser, lambda x: len(x.find_by_css(".gdpr-consent-warn-bar")) == 0) wait_until_condition(browser, lambda x: len(x.find_by_css(".gdpr-consent-preferences")) == 0)
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() object_created.connect(_add_custom_product_created_message, sender=Product, dispatch_uid="object_created_signal_test") initialize_admin_browser_test(browser, live_server, settings) url = reverse("shuup_admin:shop_product.new") browser.visit("%s%s" % (live_server, url)) wait_until_condition(browser, condition=lambda x: x.is_text_present("New shop product")) sku = "testsku" name = "Some product name" price_value = 10 short_description = "short but gold" move_to_element(browser, "#id_base-sku") 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) _add_primary_category(browser, shop) _add_additional_category(browser, shop) move_to_element(browser, "button[form='product_form']") try: click_element(browser, "button[form='product_form']") wait_until_appeared(browser, "div[class='message success']") except selenium.common.exceptions.WebDriverException as e: # TODO: Revise! # Give a product save second chance it seems that the save can # lag a little and the success message doesn't happen fast # enough every single time. 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 show_sorts_for_the_category_only(browser, category): set_configuration(category=category, data={"sort_products_by_name": True}) browser.reload() wait_until_condition(browser, lambda x: x.is_text_present("Sort")) wait_until_condition(browser, lambda x: len(x.find_by_css("#id_sort option")) == 2) click_element(browser, "button[data-id='id_sort']") set_configuration( category=category, data={ "sort_products_by_name": True, "sort_products_by_name_ordering": 1, "sort_products_by_price": True, "sort_products_by_price_ordering": 2, "sort_products_by_date_created": True, "sort_products_by_date_created_ordering": 3 } ) browser.reload() wait_until_condition(browser, lambda x: len(x.find_by_css("#id_sort option")) == 5)
def test_dashbord_tour(browser, admin_user, live_server, settings): shop = factories.get_default_shop() shop2 = factories.get_shop(identifier="shop2") admin_user_2 = factories.create_random_user(is_staff=True, is_superuser=True) admin_user_2.set_password("password") admin_user_2.save() shop.staff_members.add(admin_user) shop.staff_members.add(admin_user_2) # test with admin_user 1 initialize_admin_browser_test(browser, live_server, settings, shop=shop, tour_complete=False) wait_until_condition(browser, lambda x: x.is_text_present("Welcome!")) wait_until_condition(browser, lambda x: x.is_text_present("Quicklinks")) wait_until_condition(browser, lambda x: x.is_element_present_by_css("#menu-button")) wait_until_condition(browser, lambda x: x.is_text_present("This is the dashboard for your store."), timeout=30) wait_until_condition(browser, lambda x: x.is_element_present_by_css(".shepherd-button.btn-primary")) click_element(browser, ".shepherd-button.btn-primary") wait_until_condition(browser, lambda x: not x.is_element_present_by_css(".shepherd-button")) wait_until_condition(browser, lambda x: is_tour_complete(shop, "dashboard", admin_user)) browser.visit(live_server + "/logout") browser.visit(live_server + "/sa") # test with admin_user 2 initialize_admin_browser_test(browser, live_server, settings, shop=shop, tour_complete=False, username=admin_user_2.username) wait_until_condition(browser, lambda x: x.is_text_present("Welcome!")) wait_until_condition(browser, lambda x: x.is_element_present_by_css("#menu-button")) wait_until_condition(browser, lambda x: x.is_text_present("This is the dashboard for your store."), timeout=30) wait_until_condition(browser, lambda x: x.is_element_present_by_css(".shepherd-button.btn-primary")) click_element(browser, ".shepherd-button.btn-primary") wait_until_condition(browser, lambda x: not x.is_element_present_by_css(".shepherd-button")) wait_until_condition(browser, lambda x: is_tour_complete(shop, "dashboard", admin_user_2)) # check whether the tour is shown again browser.visit(live_server + "/sa") wait_until_condition(browser, lambda x: not x.is_text_present("This is the dashboard for your store.")) assert is_tour_complete(shop2, "dashboard", admin_user) is False assert is_tour_complete(shop2, "dashboard", admin_user_2) is False
def test_xtheme_plugin_form_selected_language_pane(admin_user, browser, live_server, settings, language): """ Test that the current language is selected by default """ browser = initialize_admin_browser_test(browser, live_server, settings, language=language) browser.visit(live_server + "/") # Start edit wait_until_condition(browser, lambda x: page_has_loaded(x), timeout=20) wait_until_appeared(browser, ".xt-edit-toggle button[type='submit']") click_element(browser, ".xt-edit-toggle button[type='submit']") placeholder_selector = "#xt-ph-front_content-xtheme-person-contact-layout" wait_until_condition(browser, lambda x: x.is_element_present_by_css(placeholder_selector)) click_element(browser, placeholder_selector) with browser.get_iframe("xt-edit-sidebar-iframe") as iframe: # make sure all scripts are loaded wait_until_condition(iframe, lambda x: page_has_loaded(x), timeout=20) wait_until_condition(iframe, lambda x: x.is_text_present("front_content")) wait_until_appeared(iframe, "button.layout-add-row-btn") time.sleep(1) wait_until_condition(iframe, lambda x: page_has_loaded(x), timeout=20) # click to add a new row click_element(iframe, "button.layout-add-row-btn") time.sleep(1) wait_until_condition(iframe, lambda x: page_has_loaded(x), timeout=20) # select the last row (the added one) click_element(iframe, "button.layout-add-row-btn") iframe.find_by_css("div.layout-cell").last.click() time.sleep(1) wait_until_condition(iframe, lambda x: page_has_loaded(x), timeout=20) # select the TextPlugin wait_until_appeared(iframe, "select[name='general-plugin']") iframe.select("general-plugin", "text") time.sleep(1) wait_until_condition(iframe, lambda x: page_has_loaded(x), timeout=20) wait_until_appeared(iframe, "ul.editor-tabs") # check the active language assert language == iframe.find_by_css("ul.editor-tabs li.active a").first.text
def _add_product_to_basket_from_category(live_server, browser, first_category, shop): url = reverse("shuup: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_carousel_multi_slide(browser, admin_user, live_server, settings): shop = factories.get_default_shop() filer_image = factories.get_random_filer_image() initialize_admin_browser_test(browser, live_server, settings, shop=shop) wait_until_condition(browser, lambda x: x.is_text_present("Welcome!")) assert not Carousel.objects.exists() browser.visit(live_server + "/sa/carousels/new") wait_until_condition(browser, lambda x: x.is_text_present("New Carousel")) browser.fill("base-name", "Carrot") click_element(browser, "button[form='carousel_form']") wait_until_appeared(browser, "div[class='message success']") assert Carousel.objects.count() == 1 carousel = Carousel.objects.first() browser.visit(live_server + "/sa/carousels/%d/" % carousel.pk) wait_until_condition(browser, lambda x: x.is_text_present(carousel.name)) click_element(browser, "a[href='#slides-section']") wait_until_appeared(browser, ".slide-add-new-panel") # add 4 slides click_element(browser, ".slide-add-new-panel") click_element(browser, ".slide-add-new-panel") click_element(browser, ".slide-add-new-panel") click_element(browser, ".slide-add-new-panel") wait_until_condition(browser, lambda x: x.is_text_present("Slide 3")) # delete slide3 wait_until_appeared(browser, "a[href='#collapse3']") click_element(browser, "a[href='#collapse3']") wait_until_appeared(browser, "#collapse3 .btn-remove-slide") click_element(browser, "#collapse3 .btn-remove-slide") wait_until_condition(browser, lambda x: not x.is_text_present("Slide 3")) click_element(browser, "button[form='carousel_form']") wait_until_appeared(browser, "a[href='#slides-section'].errors") click_element(browser, "a[href='#slides-section']") for slide_id in [0, 1, 2]: wait_until_appeared(browser, "a[href='#collapse%d']" % (slide_id + 1)) click_element(browser, "a[href='#collapse%d']" % (slide_id + 1)) browser.find_by_css("[name='slides-%d-caption__en']" % slide_id).fill("Slide") click_element(browser, "[name='slides-%d-category_link'] + .select2" % slide_id) wait_until_appeared( browser, ".select2-container #select2-id_slides-%d-category_link-results li" % slide_id) click_element( browser, ".select2-container #select2-id_slides-%d-category_link-results li:last-child" % slide_id) browser.find_by_css("#id_slides-%d-image__en-dropzone" % slide_id).click() wait_until_condition(browser, lambda b: len(b.windows) == 2) # change to the media browser window browser.windows.current = browser.windows[1] # click to select the picture wait_until_appeared(browser, "a.file-preview") click_element(browser, "a.file-preview") # back to the main window wait_until_condition(browser, lambda b: len(b.windows) == 1) browser.windows.current = browser.windows[0] wait_until_appeared(browser, ".dz-image img[alt='%s']" % filer_image.name) click_element(browser, "button[form='carousel_form']") wait_until_appeared(browser, "div[class='message success']")
def test_carousel_create(browser, admin_user, live_server, settings): shop = factories.get_default_shop() filer_image = factories.get_random_filer_image() factories.get_default_category() initialize_admin_browser_test(browser, live_server, settings, shop=shop) wait_until_condition(browser, lambda x: x.is_text_present("Welcome!")) assert not Carousel.objects.exists() browser.visit(live_server + "/sa/carousels/new") wait_until_condition(browser, lambda x: x.is_text_present("New Carousel")) browser.fill("base-name", "Carrot") click_element(browser, "button[form='carousel_form']") wait_until_appeared(browser, "div[class='message success']") assert Carousel.objects.count() == 1 carousel = Carousel.objects.first() browser.visit(live_server + "/sa/carousels/%d/" % carousel.pk) time.sleep(1) wait_until_condition(browser, lambda x: x.is_text_present(carousel.name)) click_element(browser, "a[href='#slides-section']") wait_until_appeared(browser, ".slide-add-new-panel") # add 1 slide click_element(browser, ".slide-add-new-panel") wait_until_condition(browser, lambda x: x.is_text_present("Slide 1")) wait_until_appeared(browser, "a[href='#collapse1']") click_element(browser, "a[href='#collapse1']") browser.find_by_css( "#slide_1-en [name='slides-__slide_prefix__-caption__en']").fill( "New Slide") click_element(browser, "[name='slides-__slide_prefix__-category_link'] + .select2") wait_until_appeared( browser, ".select2-container #select2-id_slides-__slide_prefix__-category_link-results li" ) click_element( browser, ".select2-container #select2-id_slides-__slide_prefix__-category_link-results li:last-child" ) browser.find_by_css("#slide_1-en [data-dropzone='true']").click() wait_until_condition(browser, lambda b: len(b.windows) == 2) # change to the media browser window browser.windows.current = browser.windows[1] # click to select the picture wait_until_appeared(browser, "a.file-preview") click_element(browser, "a.file-preview") # back to the main window wait_until_condition(browser, lambda b: len(b.windows) == 1) browser.windows.current = browser.windows[0] wait_until_appeared(browser, ".dz-image img[alt='%s']" % filer_image.name) click_element(browser, "button[form='carousel_form']") wait_until_appeared(browser, "div[class='message success']")
def test_browser_checkout_addresses_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_city1 = "Los Angeles" customer_city2 = "Blumenau" customer_city3 = "Vancouver" customer_region1 = "CA" customer_region2 = "SC" customer_region3 = "BC" customer_country1 = "US" customer_country2 = "BR" customer_country3 = "CA" # Fill all billing address fields with USA address browser.fill("billing-name", customer_name) browser.fill("billing-street", customer_street) browser.fill("billing-city", customer_city1) browser.select("billing-country", customer_country1) wait_until_appeared(browser, "select[name='billing-region_code']") browser.select("billing-region_code", customer_region1) # Fill all shipping address fields - Brazil address browser.fill("shipping-name", customer_name) browser.fill("shipping-street", customer_street) browser.fill("shipping-city", customer_city2) browser.select("shipping-country", customer_country2) wait_until_appeared(browser, "select[name='shipping-region_code']") browser.select("shipping-region_code", customer_region2) # Actually, click to send to billing address (copy billing to shipping) browser.find_by_css("label[for='same_as_billing']").first.click() # check whether fields are disable and the values are equals wait_until_condition( browser, lambda x: x.find_by_name("shipping-region_code").has_class("disabled")) wait_until_condition( browser, lambda x: x.find_by_name("shipping-country").has_class("disabled")) billing_country = browser.find_by_name("billing-country").first shipping_country = browser.find_by_name("shipping-country").first wait_until_appeared(browser, "select[name='billing-region_code']") wait_until_appeared(browser, "select[name='shipping-region_code']") billing_region_code = browser.find_by_name("billing-region_code").first shipping_region_code = browser.find_by_name("shipping-region_code").first assert billing_country.value == shipping_country.value assert billing_region_code.value == shipping_region_code.value # Actually, send to Canada browser.find_by_css("label[for='same_as_billing']").first.click() wait_until_condition( browser, lambda x: not x.find_by_name("shipping-region_code"). has_class("disabled")) wait_until_condition( browser, lambda x: not x.find_by_name("shipping-country").has_class("disabled")) browser.fill("shipping-city", customer_city3) browser.select("shipping-country", customer_country3) wait_until_appeared(browser, "select[name='shipping-region_code']") browser.select("shipping-region_code", customer_region3) # continue 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 # back to address phase, we want to send to Brazil nstead address_link = browser.find_by_text("1. Addresses") address_link.click() # all values must be there with correct saved values billing_country = browser.find_by_name("billing-country").first wait_until_appeared(browser, "select[name='billing-region_code']") billing_region_code = browser.find_by_name("billing-region_code").first shipping_country = browser.find_by_name("shipping-country").first wait_until_appeared(browser, "select[name='shipping-region_code']") shipping_region_code = browser.find_by_name("shipping-region_code").first assert billing_country.value == customer_country1 assert billing_region_code.value == customer_region1 assert shipping_country.value == customer_country3 assert shipping_region_code.value == customer_region3 # Fill shipping with Brazil and Billing with Canada browser.fill("shipping-city", customer_city2) browser.select("shipping-country", customer_country2) wait_until_appeared(browser, "select[name='shipping-region_code']") browser.select("shipping-region_code", customer_region2) browser.fill("billing-city", customer_city3) browser.select("billing-country", customer_country3) wait_until_appeared(browser, "select[name='billing-region_code']") browser.select("billing-region_code", customer_region3) # continue click_element(browser, "#addresses button[type='submit']") wait_until_condition( browser, lambda x: x.is_text_present("Checkout: Shipping & Payment")) 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_city2)) wait_until_condition(browser, lambda x: x.is_text_present(customer_city3)) wait_until_condition(browser, lambda x: x.is_text_present("Canada")) wait_until_condition(browser, lambda x: x.is_text_present("Brazil")) browser.execute_script( 'document.getElementById("id_accept_terms").checked=true' ) # click accept terms click_element(browser, ".btn.btn-primary.btn-lg") wait_until_condition( browser, lambda x: x.is_text_present("Thank you for your order!"))
def test_browser_checkout_addresses_vertical(browser, live_server, settings): with override_settings(SHUUP_CHECKOUT_VIEW_SPEC=( "shuup.front.views.checkout:SinglePageCheckoutView")): # 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 wait_until_appeared(browser, "h4.panel-title") customer_name = "Test Tester" customer_street = "Test Street" customer_city1 = "Los Angeles" customer_city2 = "Chiedo" customer_region1 = "CA" customer_region2 = "My Region Name" customer_country1 = "US" customer_country2 = "AR" # Doesn't have region codes # Fill all billing address fields with USA address browser.fill("billing-name", customer_name) browser.fill("billing-street", customer_street) browser.fill("billing-city", customer_city1) browser.select("billing-country", customer_country1) wait_until_appeared(browser, "select[name='billing-region_code']") browser.select("billing-region_code", customer_region1) # Click to send to billing address (copy billing to shipping) browser.find_by_css("label[for='same_as_billing']").first.click() # continue click_element(browser, "#addresses button[type='submit']") wait_until_condition(browser, lambda x: x.is_text_present("Shipping & Payment")) # continue on methods page click_element(browser, ".btn.btn-primary.btn-lg.pull-right") wait_until_condition(browser, lambda x: x.is_text_present("Confirmation")) # See that all expected texts are present 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_city1)) wait_until_condition(browser, lambda x: x.is_text_present("United States")) # back to address phase, we want to send to Argentina browser.find_by_css("a[data-phase='addresses']").first.click() # all values must be there with correct saved values billing_country = browser.find_by_name("billing-country").first wait_until_appeared(browser, "select[name='billing-region_code']") billing_region_code = browser.find_by_name("billing-region_code").first shipping_country = browser.find_by_name("shipping-country").first wait_until_appeared(browser, "select[name='shipping-region_code']") shipping_region_code = browser.find_by_name( "shipping-region_code").first assert billing_country.value == customer_country1 assert billing_region_code.value == customer_region1 assert shipping_country.value == customer_country1 assert shipping_region_code.value == customer_region1 # same_as_billing is not checked assert not browser.find_by_css( "label[for='same_as_billing']").first.checked # click on same as billing twice, so we copy and clean the field, just to try messing browser.find_by_css("label[for='same_as_billing']").first.click() browser.find_by_css("label[for='same_as_billing']").first.click() # region field should be enabled wait_until_condition( browser, lambda x: not x.find_by_name("shipping-region_code"). has_class("disabled")) # Fill all shipping address fields - Argentina address browser.fill("shipping-name", customer_name) browser.fill("shipping-street", customer_street) browser.fill("shipping-city", customer_city2) browser.select("shipping-country", customer_country2) browser.fill("shipping-region", customer_region2) # continue click_element(browser, "#addresses button[type='submit']") wait_until_condition(browser, lambda x: x.is_text_present("Shipping & Payment")) # continue click_element(browser, ".btn.btn-primary.btn-lg.pull-right") wait_until_condition(browser, lambda x: x.is_text_present("Confirmation")) 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_city1)) wait_until_condition(browser, lambda x: x.is_text_present(customer_city2)) wait_until_condition(browser, lambda x: x.is_text_present(customer_region1)) wait_until_condition(browser, lambda x: x.is_text_present(customer_region2)) wait_until_condition(browser, lambda x: x.is_text_present("Argentina")) 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