def step_impl(context, choice): driver = context.driver util = context.util if choice == "decreases": key = "[" elif choice == "increases": key = "]" else: raise ValueError("unexpected choice: " + choice) initial_level = wedutil.get_label_visibility_level(util) context.caret_position_before_label_visibility_change = \ wedutil.caret_screen_pos(driver) util.ctrl_equivalent_x(key) # We don't allow the increase or decrease to do nothing. if choice == "decreases": expected = initial_level - 1 elif choice == "increases": expected = initial_level + 1 else: raise ValueError("unexpected choice: " + choice) util.wait(lambda *_: wedutil.get_label_visibility_level(util) == expected)
def step_impl(context): driver = context.driver util = context.util # Set it only if we don't already have one. if not getattr(context, "context_menu_trigger", None): pos = wedutil.caret_selection_pos(driver) trigger = Trigger(location={"left": int(pos["left"]), "top": int(pos["top"])}, size={'width': 0, 'height': 0}) context.context_menu_trigger = trigger context.context_menu_for = None util.ctrl_equivalent_x("/")
def step_impl(context): driver = context.driver util = context.util # Set it only if we don't already have one. if not getattr(context, "context_menu_trigger", None): pos = wedutil.caret_selection_pos(driver) trigger = Trigger(location={ "left": int(pos["left"]), "top": int(pos["top"]) }, size={ 'width': 0, 'height': 0 }) context.context_menu_trigger = trigger context.context_menu_for = None util.ctrl_equivalent_x("/")
def step_impl(context, choice): driver = context.driver util = context.util class_name = None if choice == "a placeholder": parent, where = driver.execute_script(""" var $ph = jQuery("._placeholder"); var $parent = $ph.closest("._real"); return [$parent[0], $ph[0]]; """) elif choice == "text": where = util.find_element((By.CLASS_NAME, "title")) parent = where else: raise ValueError("unknown choice: " + choice) max_tries = 5 while True: # IF YOU CHANGE THIS, CHANGE THE TRIGGER wedutil.click_until_caret_in(util, where) util.ctrl_equivalent_x("/") try: # We don't want to check too fast so we do use an explicit # wait by way of ``util``. util.find_element((By.CLASS_NAME, "wed-context-menu")) # If we get here, the menu exists. break except TimeoutException: # The menu did not come up. Probably something messed up # the caret between ``click_until_caret_in`` and # ``ctrl_equivalent_x``. Try again or decide that it just # won't happen. max_tries -= 1 if max_tries == 0: raise Exception("tried multiple times to bring up " "the contextual menu, but was " "unsuccessful") # THIS TRIGGER WORKS ONLY BECAUSE OF .click(where) above. context.context_menu_trigger = Trigger(util, where) context.context_menu_for = parent