def test_single_page_checkout_with_login_and_register(browser, live_server, settings): cache.clear() # Avoid caches from past tests # initialize product_name = "Test Product" get_default_shop() get_default_payment_method() 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) wait_until_condition(browser, lambda x: x.is_text_present("Welcome to Default!")) navigate_to_checkout(browser, product) # Let's assume that after addresses the checkout is normal wait_until_condition(browser, lambda x: x.is_text_present("Checkout Method")) test_username = "******" test_email = "*****@*****.**" test_password = "******" register_test(browser, live_server, test_username, test_email, test_password) login_and_finish_up_the_checkout(browser, live_server, test_username, test_email, test_password)
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 second_test_query(browser, live_server, url): browser.visit("%s%s?q=Test" % (live_server, url)) wait_until_condition(browser, lambda x: len(x.find_by_css(".product-card")) == 7) expected_first_prod_id = "product-%s" % Product.objects.filter( sku="sku-4").first().id wait_until_condition( browser, lambda x: x.find_by_css(".product-card").first["id"] == expected_first_prod_id) expected_second_prod_id = "product-%s" % Product.objects.filter( sku="sku-10").first().id wait_until_condition( browser, lambda x: x.find_by_css(".product-card")[1]["id"] == expected_second_prod_id) expected_third_prod_id = "product-%s" % Product.objects.filter( sku="sku-8").first().id wait_until_condition( browser, lambda x: x.find_by_css(".product-card")[2]["id"] == expected_third_prod_id) expected_last_prod_id = "product-%s" % Product.objects.filter( sku="sku-2").first().id wait_until_condition( browser, lambda x: x.find_by_css(".product-card").last["id"] == expected_last_prod_id)
def test_product_descriptions(browser, live_server, settings): activate("en") cache.clear() shop = get_default_shop() product = create_product("product1", shop=shop, description="<b>My HTML description</b>", short_description="some short of description instead", supplier=get_default_supplier()) sp = ShopProduct.objects.get(product=product, shop=shop) sp.primary_category = get_default_category() sp.categories.add(get_default_category()) sp.save() # initialize test and go to front page browser = initialize_front_browser_test(browser, live_server) # view product detail page url = reverse("wshop:product", kwargs={"pk": product.pk, "slug": product.slug}) browser.visit("%s%s" % (live_server, url)) wait_until_condition(browser, lambda x: x.is_text_present(product.short_description)) assert product.description in browser.html # product preview url = reverse("wshop:xtheme_extra_view", kwargs={"view": "products"}) browser.visit("%s%s" % (live_server, url)) product_div_name = "product-{}".format(product.pk) wait_until_condition(browser, lambda x: x.find_by_css("#{} button.btn".format(product_div_name))) browser.execute_script("$('#{} button.btn').click();".format(product_div_name)) assert product.short_description == browser.find_by_css("#{} p.description".format(product_div_name))[0].html
def _check_row_count(browser, expected_row_count): picotable = browser.find_by_id("picotable") tbody = picotable.find_by_tag("tbody").first wait_until_condition( browser, lambda x: len(x.find_by_css("#picotable tbody tr")) == expected_row_count) # technically this is handled above, but do the assertion anyways ;) assert len( browser.find_by_css("#picotable tbody tr")) == expected_row_count
def hide_sorts_for_shop(browser, shop): set_configuration(shop=shop, data={ "sort_products_by_name": False, "sort_products_by_price": False }) browser.reload() wait_until_condition(browser, lambda x: not x.is_text_present("sort"), timeout=20)
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 categories_filter_test(browser, first_cat, second_cat, third_cat): # Add all products in second category to also in first category for shop_product in ShopProduct.objects.filter( primary_category=second_cat): shop_product.categories.add(first_cat) # Add one product including first_cat also to third_cat shop_product = ShopProduct.objects.filter( primary_category=first_cat).last() shop_product.categories.add(third_cat) # Activate categories filter for current category which is the first one set_configuration(category=first_cat, data={ "sort_products_by_name": True, "sort_products_by_name_ordering": 1, "sort_products_by_price": True, "sort_products_by_price_ordering": 2, "filter_products_by_category": True }) browser.reload() wait_until_condition( browser, lambda x: x.is_element_present_by_id("categories-%s" % third_cat.id)) browser.execute_script("$('#categories-%s').click();" % third_cat.id) wait_until_condition(browser, lambda x: len(x.find_by_css(".product-card")) == 1) browser.execute_script("$('#categories-%s').click();" % second_cat.id) wait_until_condition(browser, lambda x: len(x.find_by_css(".product-card")) == 1) browser.execute_script("$('#categories-%s').click();" % third_cat.id) wait_until_condition(browser, lambda x: len(x.find_by_css(".product-card")) == 12)
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 browser.execute_script( '$("#%s").parent().find("span.quick-add-btn a.btn").click();' % select_id) wait_until_condition(browser, condition=lambda x: x.find_by_id( "create-object-content-pane").has_class("open")) with browser.get_iframe('create-object-iframe') as iframe: 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) click_element(iframe, "button[form='category_form']") 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)) == 2) wait_until_condition( browser, lambda x: len( x.find_by_css("#%s option[selected='selected']" % select_id)) == 1)
def test_product_detail(browser, admin_user, live_server, settings): activate(settings.PARLER_DEFAULT_LANGUAGE_CODE) shop = get_default_shop() order = create_empty_order(shop=shop) order.save() initialize_admin_browser_test(browser, live_server, settings) url = reverse("wshop_admin:order.detail", kwargs={"pk": order.pk}) browser.visit("%s%s" % (live_server, url)) wait_until_condition( browser, condition=lambda x: x.is_text_present("Order %s" % order.pk)) change_addresses(live_server, browser, order) set_status(browser, order, OrderStatus.objects.get_default_processing()) assert order.can_set_complete() set_status(browser, order, OrderStatus.objects.get_default_complete())
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 change_addresses(live_server, browser, order): edit_url = reverse("wshop_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() wait_until_condition( browser, condition=lambda x: x.is_text_present("Edit Addresses")) # 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 Addresses")) 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 Addresses")) 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 Addresses")) 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 sort_category_products_test(browser, category): # Lowest price first click_element(browser, "button[data-id='id_sort']") click_element(browser, "li[data-original-index='2'] a") expected_first_prod_id = "product-%s" % Product.objects.filter( sku="test-sku-3").first().id wait_until_condition( browser, lambda x: x.find_by_css(".product-card").first["id"] == expected_first_prod_id) # Name from A-Z click_element(browser, "button[data-id='id_sort']") click_element(browser, "li[data-original-index='0'] a") expected_first_prod_id = "product-%s" % Product.objects.filter( sku="test-sku-2").first().id wait_until_condition( browser, lambda x: x.find_by_css(".product-card").first["id"] == expected_first_prod_id) # Name from Z-A click_element(browser, "button[data-id='id_sort']") click_element(browser, "li[data-original-index='1'] a") expected_first_prod_id = "product-%s" % Product.objects.filter( sku="test-sku-3").first().id wait_until_condition( browser, lambda x: x.find_by_css(".product-card").first["id"] == expected_first_prod_id) # Highest price first click_element(browser, "button[data-id='id_sort']") click_element(browser, "li[data-original-index='3'] a") expected_first_prod_id = "product-%s" % Product.objects.filter( sku="test-sku-2").first().id wait_until_condition( browser, lambda x: x.find_by_css(".product-card").first["id"] == expected_first_prod_id) # Date created click_element(browser, "button[data-id='id_sort']") click_element(browser, "li[data-original-index='4'] a") expected_first_prod_id = "product-%s" % Product.objects.filter( shop_products__primary_category=category).order_by( "-created_on").first().id wait_until_condition( browser, lambda x: x.find_by_css(".product-card").first["id"] == expected_first_prod_id)
def _test_language_change(browser): assert browser.is_element_present_by_css("h2[class='block-title']") # By default the initialization the admin should be in English found_customer_details_en = False for block_title in browser.find_by_css("h2[class='block-title']"): if "Customer Details" in block_title.text: found_customer_details_en = True assert found_customer_details_en # Make sure that the translations is handled correctly and change to Finnish browser.find_by_id("dropdownMenu").click() browser.find_by_xpath('//a[@data-value="fi"]').first.click() wait_until_condition( browser, condition=lambda x: x.is_text_present("Asiakkaan tiedot")) # And back in English browser.find_by_id("dropdownMenu").click() browser.find_by_xpath('//a[@data-value="en"]').first.click() wait_until_condition( browser, condition=lambda x: x.is_text_present("Customer Details"))
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 test_generic_script_template(browser, admin_user, live_server, settings, script_template_cls): initialize(browser, live_server, settings) url = reverse("wshop_admin:notify.script.list") browser.visit("%s%s" % (live_server, url)) wait_until_condition(browser, lambda x: x.is_element_present_by_css("div.btn-toolbar a.btn.btn-info")) post_initialize() # find the button to load from template browser.find_by_css("div.btn-toolbar a.btn.btn-info").first.click() identifier = script_template_cls.identifier form_id = "form-" + identifier button_id = "#{} button.btn.btn-success".format(form_id) wait_until_condition(browser, lambda x: x.is_element_present_by_css(button_id)) click_element(browser, button_id) config_url = reverse("wshop_admin:notify.script-template-config", kwargs={"id": identifier}) wait_until_condition(browser, lambda b: b.url.endswith(config_url), timeout=15) wait_until_condition(browser, lambda b: b.is_text_present("Configure the Script Template")) # click to create the script browser.execute_script(""" $(document).ready(function(){ $('#lang-en .summernote-editor').summernote('editor.insertText', 'NEW CONTENT'); }); """) browser.find_by_id("id_en-subject").fill("custom subject!") browser.find_by_css("form button.btn.btn-lg.btn-primary").first.click() wait_until_condition(browser, lambda b: b.url.endswith(reverse("wshop_admin:notify.script.list"))) script = Script.objects.first() serialized_steps = script.get_serialized_steps() assert len(serialized_steps) == 1 assert len(serialized_steps[0]["actions"]) == 1 assert len(serialized_steps[0]["conditions"]) == 0 assert serialized_steps[0]["actions"][0]["recipient"]["variable"] == "customer_email" assert serialized_steps[0]["actions"][0]["template_data"]["en"]["subject"] == "custom subject!" assert "NEW CONTENT" in serialized_steps[0]["actions"][0]["template_data"]["en"]["body"]
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_category_product_filters_2(browser, live_server, settings): cache.clear() # Avoid cache from past tests shop, first_cat, second_cat, third_cat, first_manufacturer = initialize_db( ) # Activate limit page size changer for the shop 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 }) # 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!")) url = reverse("wshop:category", kwargs={ "pk": first_cat.pk, "slug": first_cat.slug }) browser.visit("%s%s" % (live_server, url)) wait_until_condition(browser, lambda x: x.is_text_present("First Category")) wait_until_condition(browser, lambda x: x.is_text_present("Sort")) assert not browser.is_text_present( "Manufacturers") # Since not in default configuration second_category_sort_test(browser, live_server, shop, second_cat) second_category_sort_with_price_filter(browser, second_cat)
def test_category_product_filters_1(browser, live_server, settings): cache.clear() # Avoid cache from past tests shop, first_cat, second_cat, third_cat, first_manufacturer = initialize_db( ) # 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!")) url = reverse("wshop:category", kwargs={ "pk": first_cat.pk, "slug": first_cat.slug }) browser.visit("%s%s" % (live_server, url)) wait_until_condition(browser, lambda x: x.is_text_present("First Category")) wait_until_condition(browser, lambda x: x.is_text_present("Sort")) assert not browser.is_text_present( "Manufacturers") # Since not in default configuration hide_sorts_for_shop(browser, shop) show_sorts_for_the_category_only(browser, first_cat) second_category_page_change(browser, live_server, shop, second_cat)
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_dummy_script_template(browser, admin_user, live_server, settings): initialize(browser, live_server, settings) with override_provides("notify_script_template", ["wshop.testing.notify_script_templates:DummyScriptTemplate"]): url = reverse("wshop_admin:notify.script.list") browser.visit("%s%s" % (live_server, url)) wait_until_condition(browser, lambda x: x.is_element_present_by_css("div.btn-toolbar a.btn.btn-info")) post_initialize() # find the button to load from template browser.find_by_css("div.btn-toolbar a.btn.btn-info").first.click() identifier = DummyScriptTemplate.identifier form_id = "form-" + identifier wait_until_condition(browser, lambda x: x.is_element_present_by_id(form_id)) btn_create_css = "#{} button.btn.btn-success".format(form_id) wait_until_condition(browser, lambda x: x.is_element_present_by_css(btn_create_css)) click_element(browser, btn_create_css) wait_until_condition(browser, lambda b: b.url.endswith(reverse("wshop_admin:notify.script.list"))) script = Script.objects.first() serialized_steps = script.get_serialized_steps() assert len(serialized_steps) == 1 assert len(serialized_steps[0]["actions"]) == 0 assert len(serialized_steps[0]["conditions"]) == 1 assert serialized_steps[0]["conditions"][0]["v1"]["constant"] assert not serialized_steps[0]["conditions"][0]["v2"]["constant"] # edit the script url = reverse("wshop_admin:notify.script.edit", kwargs={"pk": script.pk}) browser.visit("%s%s" % (live_server, url)) wait_until_condition(browser, lambda b: b.is_text_present("Edit Script Information")) # should exist only a single button to edit the script content assert len(browser.find_by_css("div.btn-toolbar a.btn.btn-info")) == 1 assert "Edit Script Contents" in browser.find_by_css("div.btn-toolbar a.btn.btn-info").first.text
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 test_search_product_list(browser, live_server, settings): activate("en") # initialize cache.clear() shop = get_default_shop() for name, sku, price in PRODUCT_DATA: create_orderable_product(name, sku, price=price) # 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!")) url = reverse("wshop:product_search") browser.visit("%s%s?q=test product" % (live_server, url)) wait_until_condition(browser, lambda x: len(x.find_by_css(".product-card")) == 9) check_default_ordering(browser) # basic_sorting_test(browser) second_test_query(browser, live_server, url)
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 second_category_sort_with_price_filter(browser, category): set_configuration(category=category, data={ "filter_products_by_price": True, "filter_products_by_price_range_min": 5, "filter_products_by_price_range_max": 12, "filter_products_by_price_range_size": 3 }) browser.reload() wait_until_condition( browser, lambda x: len(x.find_by_css("#id_price_range option")) == 5) browser.select("price_range", "-5") wait_until_condition(browser, lambda x: len(x.find_by_css(".product-card")) == 4) browser.select("price_range", "12-") wait_until_condition(browser, lambda x: len(x.find_by_css(".product-card")) == 2) browser.select("price_range", "8-11") wait_until_condition(browser, lambda x: len(x.find_by_css(".product-card")) == 3)
def second_category_sort_test(browser, live_server, shop, category): url = reverse("wshop: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() 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() browser.reload() wait_until_condition(browser, lambda x: len(x.find_by_css(".product-card")) == 13, timeout=30)
def manufacturer_filter_test(browser, category, manufacturer): wait_until_condition(browser, lambda x: len(x.find_by_css(".product-card")) == 3) 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, "filter_products_by_manufacturer": True }) browser.reload() wait_until_condition(browser, lambda x: x.is_text_present("Manufacturers")) browser.execute_script("$('#manufacturers-%s').click();" % manufacturer.id) wait_until_condition(browser, lambda x: len(x.find_by_css(".product-card")) == 1)