Example #1
0
File: caret.py Project: nenadg/wed
def step_impl(context):
    util = context.util
    parent = context.selection_parent
    text = context.expected_selection

    # It may take a bit.
    util.wait(lambda *_: util.get_text_excluding_children(parent) == text)
Example #2
0
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)
Example #3
0
def step_impl(context):
    util = context.util
    parent = context.selection_parent
    text = context.expected_selection

    # It may take a bit.
    util.wait(lambda *_: util.get_text_excluding_children(parent) == text)
Example #4
0
def step_impl(context, choice):
    driver = context.driver
    util = context.util

    initial_level = wedutil.get_label_visibility_level(util)
    context.caret_position_before_label_visibility_change = \
        wedutil.caret_screen_pos(driver)

    # 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)

    if not util.osx:
        util.ctrl_x({
            "decreases": "[",
            "increases": "]",
        }[choice])

    else:
        # On OSX, we have to use the toolbar.
        context.execute_steps(u"""\
When the user clicks the toolbar button "{}"
        """.format({
            "decreases": "Decrease label visibility level",
            "increases": "Increase label visibility level",
        }[choice]))

    util.wait(lambda *_: wedutil.get_label_visibility_level(util) == expected)
Example #5
0
File: caret.py Project: nenadg/wed
def step_impl(context):
    driver = context.driver
    util = context.util
    prev_pos = context.caret_screen_position

    util.wait(lambda *_: wedutil.caret_screen_pos(driver)["top"] == prev_pos[
        "top"] - context.scrolled_editor_pane_by)
Example #6
0
def step_impl(context):
    driver = context.driver
    util = context.util
    prev_pos = context.caret_screen_position

    util.wait(lambda *_: wedutil.caret_screen_pos(driver)["top"] ==
              prev_pos["top"] - context.scrolled_editor_pane_by)
Example #7
0
def step_impl(context):
    util = context.util

    def cond(*_):
        _, n_displayed = get_labels_stats(context.driver)
        return n_displayed > context.number_of_visible_labels

    util.wait(cond)
Example #8
0
def step_impl(context):
    util = context.util

    def cond(*_):
        n_labels, n_displayed = get_labels_stats(context.driver)
        assert_true(n_labels)
        return n_displayed == 0

    util.wait(cond)
Example #9
0
def step_impl(context):
    util = context.util

    def cond(driver):
        return driver.execute_script("""
        var filter = document.querySelector(".wed-context-menu input");
        return document.activeElement === filter;
        """)

    util.wait(cond)
Example #10
0
def step_impl(context):
    util = context.util

    def cond(driver):
        return driver.execute_script("""
        var filter = document.querySelector(".wed-context-menu input");
        return document.activeElement === filter;
        """)

    util.wait(cond)
Example #11
0
def step_impl(context, choice):
    util = context.util

    if choice == "the first context menu option":
        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":
        link = util.wait(EC.element_to_be_clickable((By.PARTIAL_LINK_TEXT,
                                                     "Wrap in ")))
    else:
        raise ValueError("can't handle this type of choice: " + choice)
    context.clicked_context_menu_item = \
        util.get_text_excluding_children(link).strip()
    link.click()
Example #12
0
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()
Example #13
0
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()
Example #14
0
def step_impl(context):
    driver = context.driver
    util = context.util

    link = util.wait(
        EC.element_to_be_clickable((By.PARTIAL_LINK_TEXT, "Wrap in ")))

    while not (driver.switch_to_active_element() == link):
        ActionChains(driver) \
            .send_keys(Keys.ARROW_DOWN) \
            .perform()

    context.clicked_context_menu_item = \
        util.get_text_excluding_children(link).strip()
Example #15
0
def step_impl(context):
    driver = context.driver
    util = context.util

    link = util.wait(EC.element_to_be_clickable((By.PARTIAL_LINK_TEXT,
                                                 "Wrap in ")))

    while not (driver.switch_to_active_element() == link):
        ActionChains(driver) \
            .send_keys(Keys.ARROW_DOWN) \
            .perform()

    context.clicked_context_menu_item = \
        util.get_text_excluding_children(link).strip()
Example #16
0
def step_impl(context):
    util = context.util

    util.wait(lambda *_: util.get_selection_text() ==
              context.expected_selection)
Example #17
0
def step_impl(context):
    util = context.util
    parent = context.selection_parent

    # It may take a bit.
    util.wait(lambda *_: not len(util.get_text_excluding_children(parent)))
Example #18
0
File: caret.py Project: nenadg/wed
def step_impl(context):
    util = context.util
    parent = context.selection_parent

    # It may take a bit.
    util.wait(lambda *_: not len(util.get_text_excluding_children(parent)))
Example #19
0
File: caret.py Project: nenadg/wed
def step_impl(context):
    util = context.util

    util.wait(
        lambda *_: util.get_selection_text() == context.expected_selection)