本文整理汇总了Python中shuup.testing.browser_utils.click_element函数的典型用法代码示例。如果您正苦于以下问题:Python click_element函数的具体用法?Python click_element怎么用?Python click_element使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了click_element函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _test_quick_add_lines
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"
示例2: test_product_create
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
示例3: _save_category
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']")
示例4: second_category_sort_test
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)
示例5: _test_customer_data
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
示例6: test_category_tour
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
示例7: test_product_tour
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")
示例8: set_status
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
示例9: second_category_page_change
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)
示例10: _test_confirm
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"
示例11: _activate_basket_campaign_through_coupon
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)
示例12: test_xtheme_snippet_injection
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())
示例13: test_home_tour
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
示例14: _add_additional_category
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)
示例15: change_addresses
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 = "[email protected]"
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