示例#1
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()
示例#2
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)
示例#3
0
文件: caret.py 项目: 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)
示例#4
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()
示例#5
0
def step_impl(context, what):
    driver = context.driver
    util = context.util

    parent = util.find_element((By.CSS_SELECTOR, ".title"))
    label = parent.find_element_by_css_selector(".__start_label._title_label")

    if label.is_displayed():
        ActionChains(driver) \
            .click(label) \
            .perform()
    else:
        ActionChains(driver) \
            .move_to_element_with_offset(parent, 1, 1) \
            .click() \
            .perform()

    # We need to find the text inside the title element
    text = util.get_text_excluding_children(parent)
    start_index = text.find(what)
    assert_true(start_index >= 0, "should have found the text")
    if start_index > 0:
        util.send_keys(parent,
                       # Move the caret to the start of the selection
                       # we want.
                       [Keys.ARROW_RIGHT] * (start_index +
                                             1 if label.is_displayed() else 0))

    start = wedutil.caret_selection_pos(driver)
    util.send_keys(parent,
                   # Move to the end of the selection we want.
                   [Keys.ARROW_RIGHT] * len(what))
    end = wedutil.caret_selection_pos(driver)

    # We don't want to be too close to the edge to handle a problem when
    # labels are. The problem is that when the labels are invisible they
    # have 0 width and it is possible at least that the caret could be
    # put over the invisible label. (That is, instead of the caret being
    # put after the invisible start label, it would be put before the
    # invisible start label.) When a user selects manually, the visual
    # feedback tends to prevent this. In testing, we achieve the same
    # through shifting the boundaries inwards a bit.
    #
    # Note that we've deemed it unnecessary to change the
    # caret/selection code of wed to prevent the caret from moving over
    # an invisible label. The fix would be rather complicated but
    # selecting text by mouse when labels are invisible is a bit dodgy
    # **at any rate**, and we're not going to work around this
    # dodginess. For now, at least.
    start["left"] += 5
    end["left"] -= 5

    select_text(context, start, end)
    assert_equal(util.get_selection_text(), what,
                 "the selected text should be what we wanted to select")
    context.selection_parent = parent
    context.caret_screen_position = wedutil.caret_screen_pos(driver)
    context.element_to_test_for_text = parent
示例#6
0
文件: caret.py 项目: lddubeau/wed
def step_impl(context, what):
    driver = context.driver
    util = context.util

    parent = util.find_element((By.CSS_SELECTOR, ".title"))
    label = parent.find_element_by_css_selector(".__start_label._title_label")

    if label.is_displayed():
        ActionChains(driver) \
            .click(label) \
            .perform()
    else:
        ActionChains(driver) \
            .move_to_element_with_offset(parent, 1, 1) \
            .click() \
            .perform()

    # We need to find the text inside the title element
    text = util.get_text_excluding_children(parent)
    start_index = text.find(what)
    assert_true(start_index >= 0, "should have found the text")
    if start_index > 0:
        util.send_keys(parent,
                       # Move the caret to the start of the selection
                       # we want.
                       [Keys.ARROW_RIGHT] * (start_index +
                                             1 if label.is_displayed() else 0))

    start = wedutil.caret_selection_pos(driver)
    util.send_keys(parent,
                   # Move to the end of the selection we want.
                   [Keys.ARROW_RIGHT] * len(what))
    end = wedutil.caret_selection_pos(driver)

    # We don't want to be too close to the edge to handle a problem when
    # labels are. The problem is that when the labels are invisible they
    # have 0 width and it is possible at least that the caret could be
    # put over the invisible label. (That is, instead of the caret being
    # put after the invisible start label, it would be put before the
    # invisible start label.) When a user selects manually, the visual
    # feedback tends to prevent this. In testing, we achieve the same
    # through shifting the boundaries inwards a bit.
    #
    # Note that we've deemed it unnecessary to change the
    # caret/selection code of wed to prevent the caret from moving over
    # an invisible label. The fix would be rather complicated but
    # selecting text by mouse when labels are invisible is a bit dodgy
    # **at any rate**, and we're not going to work around this
    # dodginess. For now, at least.
    start["left"] += 5
    end["left"] -= 5

    select_text(context, start, end)
    assert_equal(util.get_selection_text(), what,
                 "the selected text should be what we wanted to select")
    context.selection_parent = parent
    context.caret_screen_position = wedutil.caret_screen_pos(driver)
    context.element_to_test_for_text = parent
示例#7
0
文件: caret.py 项目: nenadg/wed
def step_impl(context, what):
    driver = context.driver
    util = context.util

    parent = util.find_element((By.CSS_SELECTOR, ".title"))
    label = parent.find_element_by_css_selector(".__start_label._title_label")

    if label.is_displayed():
        ActionChains(driver) \
            .click(label) \
            .perform()
    else:
        ActionChains(driver) \
            .move_to_element_with_offset(parent, 1, 1) \
            .click() \
            .perform()

    # We need to find the text inside the title element
    text = util.get_text_excluding_children(parent)
    start_index = text.find(what)
    assert_true(start_index >= 0, "should have found the text")
    if start_index > 0:
        util.send_keys(
            parent,
            # Move the caret to the start of the selection
            # we want.
            [Keys.ARROW_RIGHT] *
            (start_index + 1 if label.is_displayed() else 0))

    start = wedutil.caret_selection_pos(driver)
    # On FF there's an off-by 1 issue in the CSS rendering which causes
    # a problem unless we perform this adjustment.
    start["left"] += 1

    util.send_keys(
        parent,
        # Move to the end of the selection we want.
        [Keys.ARROW_RIGHT] * len(what))

    end = wedutil.caret_selection_pos(driver)
    # On FF there's an off-by 1 issue in the CSS rendering which causes
    # a problem unless we perform this adjustment.
    end["left"] -= 1

    select_text(context, start, end)

    assert_equal(util.get_selection_text(), what,
                 "the selected text should be what we wanted to select")
    context.selection_parent = parent
    context.caret_screen_position = wedutil.caret_screen_pos(driver)
    context.element_to_test_for_text = parent
示例#8
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()
示例#9
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()
示例#10
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()
示例#11
0
def step_impl(context, what):
    driver = context.driver
    util = context.util

    parent = util.find_element((By.CSS_SELECTOR, ".title"))
    label = parent.find_element_by_css_selector(".__start_label._title_label")

    if label.is_displayed():
        ActionChains(driver) \
            .click(label) \
            .perform()
    else:
        ActionChains(driver) \
            .move_to_element_with_offset(parent, 1, 1) \
            .click() \
            .perform()

    # We need to find the text inside the title element
    text = util.get_text_excluding_children(parent)
    start_index = text.find(what)
    assert_true(start_index >= 0, "should have found the text")
    if start_index > 0:
        util.send_keys(parent,
                       # Move the caret to the start of the selection
                       # we want.
                       [Keys.ARROW_RIGHT] * (start_index +
                                             1 if label.is_displayed() else 0))

    start = wedutil.caret_selection_pos(driver)
    # On FF there's an off-by 1 issue in the CSS rendering which causes
    # a problem unless we perform this adjustment.
    start["left"] += 1

    util.send_keys(parent,
                   # Move to the end of the selection we want.
                   [Keys.ARROW_RIGHT] * len(what))

    end = wedutil.caret_selection_pos(driver)
    # On FF there's an off-by 1 issue in the CSS rendering which causes
    # a problem unless we perform this adjustment.
    end["left"] -= 1

    select_text(context, start, end)

    assert_equal(util.get_selection_text(), what,
                 "the selected text should be what we wanted to select")
    context.selection_parent = parent
    context.caret_screen_position = wedutil.caret_screen_pos(driver)
    context.element_to_test_for_text = parent
示例#12
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)))
示例#13
0
文件: caret.py 项目: 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)))