def context_choices_insert(context, exists, kind): util = context.util exists = True if exists == "contains" else False search_for = None if kind == "inserting new elements": search_for = "^Create new [^ ]+$" elif kind == "creating elements before the selected element": search_for = "^Create new .+? before" elif kind == "creating elements after the selected element": search_for = "^Create new .+? after" elif kind == "wrapping text in new elements": search_for = "^Wrap in " else: raise ValueError("can't search for choices of this kind: " + kind) if exists: count = len(util.find_descendants_by_text_re(".wed-context-menu", search_for)) assert_not_equal(count, 0, "there should be options") else: # We first need to make sure the menu is up because # find_descendants_by_text_re will return immediately. util.find_element((By.CLASS_NAME, "wed-context-menu")) count = len(util.find_descendants_by_text_re(".wed-context-menu", search_for, True)) assert_equal(count, 0, "there should not be options")
def context_choices_insert(context, exists, kind): util = context.util exists = True if exists == "contains" else False search_for = None if kind == "inserting new elements": search_for = "^Create new [^ ]+$" elif kind == "creating elements before the selected element": search_for = "^Create new .+? before" elif kind == "creating elements after the selected element": search_for = "^Create new .+? after" elif kind == "wrapping text in new elements": search_for = "^Wrap in " else: raise ValueError("can't search for choices of this kind: " + kind) if exists: count = len( util.find_descendants_by_text_re(".wed-context-menu", search_for)) assert_not_equal(count, 0, "there should be options") else: # We first need to make sure the menu is up because # find_descendants_by_text_re will return immediately. util.find_element((By.CLASS_NAME, "wed-context-menu")) count = len( util.find_descendants_by_text_re(".wed-context-menu", search_for, True)) assert_equal(count, 0, "there should not be options")
def step_impl(context, choice, new=None, name=None): util = context.util driver = context.driver # The following branches also normalize ``choice`` to shorter values if choice == "the first context menu option": choice = "first" link = util.wait( EC.element_to_be_clickable( (By.CSS_SELECTOR, ".wed-context-menu li>a"))) elif choice == "a choice for wrapping text in new elements": choice = "wrap" link = util.wait( EC.element_to_be_clickable((By.PARTIAL_LINK_TEXT, "Wrap in "))) elif (choice == "a choice for creating an element before the selected element"): choice = "before" link = [ x for x in util.find_descendants_by_text_re( ".wed-context-menu", "^Create new .+? before") if x.tag_name == "a" ][0] util.wait(lambda *_: link.is_displayed()) elif (choice == "a choice for creating an element after the selected element"): choice = "after" link = [ x for x in util.find_descendants_by_text_re( ".wed-context-menu", "^Create new .+? after") if x.tag_name == "a" ][0] util.wait(lambda *_: link.is_displayed()) elif choice.startswith("a choice for creating a new"): choice = "new" link = util.wait( EC.element_to_be_clickable( (By.PARTIAL_LINK_TEXT, "Create new " + new))) elif choice.startswith("the choice named"): choice = None link = util.wait( EC.element_to_be_clickable((By.PARTIAL_LINK_TEXT, name))) else: raise ValueError("can't handle this type of choice: " + choice) # Record some information likely to be useful later. for_element = getattr(context, "context_menu_for", None) if for_element: info = {} context.context_menu_pre_transformation_info = info if choice in ("before", "after"): info["preceding"], info["following"] = \ get_real_siblings(driver, for_element) elif choice == "new": info["children"] = driver.execute_script( """ return jQuery(arguments[0]).children("._real").toArray(); """, for_element) context.clicked_context_menu_item = \ util.get_text_excluding_children(link).strip() link.click()
def step_impl(context, choice, new=None, name=None): util = context.util driver = context.driver # The following branches also normalize ``choice`` to shorter values if choice == "the first context menu option": choice = "first" link = util.wait(EC.element_to_be_clickable( (By.CSS_SELECTOR, ".wed-context-menu li>a"))) elif choice == "a choice for wrapping text in new elements": choice = "wrap" link = util.wait(EC.element_to_be_clickable((By.PARTIAL_LINK_TEXT, "Wrap in "))) elif (choice == "a choice for creating an element before the selected element"): choice = "before" link = [x for x in util.find_descendants_by_text_re( ".wed-context-menu", "^Create new .+? before") if x.tag_name == "a"][0] util.wait(lambda *_: link.is_displayed()) elif (choice == "a choice for creating an element after the selected element"): choice = "after" link = [x for x in util.find_descendants_by_text_re( ".wed-context-menu", "^Create new .+? after") if x.tag_name == "a"][0] util.wait(lambda *_: link.is_displayed()) elif choice.startswith("a choice for creating a new"): choice = "new" link = util.wait(EC.element_to_be_clickable((By.PARTIAL_LINK_TEXT, "Create new " + new))) elif choice.startswith("the choice named"): choice = None link = util.wait(EC.element_to_be_clickable((By.PARTIAL_LINK_TEXT, name))) else: raise ValueError("can't handle this type of choice: " + choice) # Record some information likely to be useful later. for_element = getattr(context, "context_menu_for", None) if for_element: info = {} context.context_menu_pre_transformation_info = info if choice in ("before", "after"): info["preceding"], info["following"] = \ get_real_siblings(driver, for_element) elif choice == "new": info["children"] = driver.execute_script(""" return jQuery(arguments[0]).children("._real").toArray(); """, for_element) context.clicked_context_menu_item = \ util.get_text_excluding_children(link).strip() # On Edge, the autoscrolling is crap. It brings the element only half into # view. if util.edge: driver.execute_script("arguments[0].scrollIntoView();", link) link.click()
def context_choices_insert(context, what): util = context.util search_for = '^Create new ' + what + ' after' assert_not_equal(len(util.find_descendants_by_text_re(".wed-context-menu", search_for)), 0, "Number of elements found")
def context_choices_insert(context, what): util = context.util search_for = '^Create new ' + what + ' after' assert_not_equal( len(util.find_descendants_by_text_re(".wed-context-menu", search_for)), 0, "Number of elements found")
def context_choices_insert(context): util = context.util driver = context.driver search_for = '^Create new note after' items = util.find_descendants_by_text_re(".wed-context-menu", search_for) assert_not_equal(len(items), 0, "Number of elements found") item = items[0] assert_true(driver.execute_script(""" var el = arguments[0]; var $element = jQuery(el); var $gui_root = wed_editor.$gui_root; var pos = $element.offset(); var gui_pos = $gui_root.offset(); pos.top = pos.top - gui_pos.top; return pos.top > $gui_root.outerHeight(); """, item), "Outside editor panel")
def context_choices_insert(context): util = context.util driver = context.driver search_for = '^Create new note after' items = util.find_descendants_by_text_re(".wed-context-menu", search_for) assert_not_equal(len(items), 0, "Number of elements found") item = items[0] assert_true( driver.execute_script( """ var el = arguments[0]; var $element = jQuery(el); var $guiRoot = wed_editor.$guiRoot; var pos = $element.offset(); var gui_pos = $guiRoot.offset(); pos.top = pos.top - gui_pos.top; return pos.top > $guiRoot.outerHeight(); """, item), "Outside editor panel")