def test_summernote_editor_picture(browser, admin_user, live_server, settings): activate("en") factories.get_default_shop() factories.get_default_product_type() factories.get_default_sales_unit() factories.get_default_tax_class() filer_image = factories.get_random_filer_image() initialize_admin_browser_test(browser, live_server, settings) browser.driver.set_window_size(1920, 1080) url = reverse("E-Commerce_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")) img_icon_selector = "#id_base-description__en-editor-wrap i[class='note-icon-picture']" move_to_element(browser, img_icon_selector) click_element(browser, img_icon_selector) 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] # make sure the image was added to the editor wait_until_appeared( browser, "#id_base-description__en-editor-wrap .note-editable img[src='%s']" % filer_image.url, timeout=20)
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 _test_methods(browser, shipping_method, payment_method): # check defaults assert browser.find_by_name("shipping").value == "0" assert browser.find_by_name("payment").value == "0" move_to_element(browser, "select[name='shipping']") browser.select("shipping", shipping_method.pk) move_to_element(browser, "select[name='payment']") browser.select("payment", payment_method.pk)
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 _test_regions(browser, person): with pytest.raises(ElementDoesNotExist): browser.find_by_css("input[name='billing-region_code']").first assert browser.find_by_css("input[name='billing-region']").first move_to_element(browser, "input[name='billing-region']") # To ensure all inputs required test is available browser.select("billing-country", "US") wait_until_appeared(browser, "select[name='billing-region_code']") with pytest.raises(ElementDoesNotExist): browser.find_by_css("input[name='billing-region']").first browser.select("billing-region_code", "CA") browser.select("billing-country", "CG") # Congo does not have regions defined wait_until_appeared(browser, "input[name='billing-region']") browser.select("billing-country", person.default_billing_address.country)
def _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 _test_refund_view(browser, live_server, order): url = reverse("E-Commerce_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 try: click_element(browser, "#select2-id_form-0-line_number-container") wait_until_appeared(browser, "input.select2-search__field") except selenium.common.exceptions.TimeoutException as e: # For some reason first click happen before the element is not ready so # let's re-click when timeout happens. The actual functionality seem # to work nicely. 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 _set_settings(browser, setting_type, creator): 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) browser.find_by_css(".E-Commerce-toolbar .btn.btn-inverse").first.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 move_to_element(browser, ".E-Commerce-toolbar .btn.btn-success") browser.find_by_css(".E-Commerce-toolbar .btn.btn-success").first.click() _check_picotable_item_info(browser, creator) if creator: for idx, text in addable_fields: wait_until_condition(browser, lambda x: x.is_text_present(text)) # go back to settings browser.find_by_css(".E-Commerce-toolbar .btn.btn-inverse").first.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 _check_picotable_item_info(browser, creator) # not selected by default if creator: for idx, text in addable_fields: assert not browser.is_text_present(text)
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("E-Commerce_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 _goto_page(browser, page_number): click_element(browser, "a[rel='%s']" % page_number) element = "li.active a[rel='%s']" % page_number wait_until_appeared(browser, element) move_to_element(browser, element)
def test_generic_custom_email_script_template(browser, admin_user, live_server, settings, script_template_cls): initialize(browser, live_server, settings) url = reverse("E-Commerce_admin:notify.script.list") browser.visit("%s%s" % (live_server, url)) wait_until_condition(browser, lambda x: x.is_element_present_by_css(".E-Commerce-toolbar a.btn.btn-default")) post_initialize() # find the button to load from template browser.find_by_css(".E-Commerce-toolbar a.btn.btn-default").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("E-Commerce_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")) browser.execute_script(""" $(document).ready(function(){ // EN $("#id_en-subject").val("custom subject!"); $('#lang-en .summernote-editor').summernote('editor.insertText', 'Hi'); // FINNISH $('.nav.nav-tabs a[href="#lang-fi"]').tab('show'); $("#id_fi-subject").val("FINNISH subject!"); $('#lang-fi .summernote-editor').summernote('editor.insertText', 'Hi Finland!'); }); """) # fill form move_to_element(browser, "#id_base-send_to") browser.select('base-send_to', 'other') browser.find_by_id("id_base-recipient").fill("*****@*****.**") browser.find_by_css("form button.btn.btn-lg.btn-primary").first.click() wait_until_condition(browser, lambda b: b.url.endswith(reverse("E-Commerce_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"]["constant"] == "*****@*****.**" assert serialized_steps[0]["actions"][0]["template_data"]["en"]["subject"] == "custom subject!" assert "Hi" in serialized_steps[0]["actions"][0]["template_data"]["en"]["body"] assert serialized_steps[0]["actions"][0]["template_data"]["fi"]["subject"] == "FINNISH subject!" assert "Hi Finland!" in serialized_steps[0]["actions"][0]["template_data"]["fi"]["body"] # edit the script url = reverse("E-Commerce_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")) # find the button to edit the script content through template editor browser.find_by_css(".E-Commerce-toolbar a.btn.btn-primary").last.click() edit_url = reverse("E-Commerce_admin:notify.script-template-edit", kwargs={"pk": script.pk}) wait_until_condition(browser, lambda b: b.url.endswith(edit_url)) wait_until_condition(browser, lambda b: b.is_text_present("Configure the Script Template")) # fill form browser.execute_script(""" $(document).ready(function(){ $('#lang-en .summernote-editor').summernote('editor.insertText', 'Changed'); }); """) browser.find_by_id("id_en-subject").fill("changed subject!") move_to_element(browser, "#id_base-send_to") browser.select('base-send_to', 'customer') browser.find_by_css("form button.btn.btn-lg.btn-primary").first.click() # hit save wait_until_condition(browser, lambda b: b.url.endswith(reverse("E-Commerce_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"] == "changed subject!" assert "Changed" in serialized_steps[0]["actions"][0]["template_data"]["en"]["body"]