예제 #1
0
파일: caret.py 프로젝트: nenadg/wed
def step_impl(context, direction):
    driver = context.driver
    util = context.util

    direction = direction.strip()

    element, parent, parent_text = get_element_parent_and_parent_text(
        driver, ".__start_label._title_label")
    element.click()
    wedutil.wait_for_caret_to_be_in(util, parent)

    # From the label to before the first letter and then past the
    # first letter.
    ActionChains(driver)\
        .send_keys(*[Keys.ARROW_RIGHT] * 2)\
        .perform()

    # We need to get the location of the caret.
    start = wedutil.caret_selection_pos(driver)
    # This moves two characters to the right
    ActionChains(driver)\
        .send_keys(*[Keys.ARROW_RIGHT] * 2)\
        .perform()
    end = wedutil.caret_selection_pos(driver)

    if direction == "":
        select_text(context, start, end)
    elif direction == "backwards":
        select_text(context, end, start)
    else:
        raise ValueError("unexpected direction: " + direction)

    context.expected_selection = parent_text[1:3]
    context.selection_parent = parent
    context.caret_screen_position = wedutil.caret_screen_pos(driver)
예제 #2
0
def step_impl(context, direction):
    driver = context.driver
    util = context.util

    direction = direction.strip()

    element, parent, parent_text = get_element_parent_and_parent_text(
        driver, ".__start_label._title_label")
    element.click()
    wedutil.wait_for_caret_to_be_in(util, parent)

    # From the label to before the first letter and then past the
    # first letter.
    ActionChains(driver)\
        .send_keys(*[Keys.ARROW_RIGHT] * 2)\
        .perform()

    # We need to get the location of the caret.
    start = wedutil.caret_selection_pos(driver)
    # This moves two characters to the right
    ActionChains(driver)\
        .send_keys(*[Keys.ARROW_RIGHT] * 2)\
        .perform()
    end = wedutil.caret_selection_pos(driver)

    if direction == "":
        select_text(context, start, end)
    elif direction == "backwards":
        select_text(context, end, start)
    else:
        raise ValueError("unexpected direction: " + direction)

    context.expected_selection = parent_text[1:3]
    context.selection_parent = parent
    context.caret_screen_position = wedutil.caret_screen_pos(driver)
예제 #3
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
예제 #4
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
예제 #5
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
예제 #6
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
예제 #7
0
파일: caret.py 프로젝트: nenadg/wed
def step_impl(context):
    driver = context.driver
    util = context.util

    element, parent, parent_text = get_element_parent_and_parent_text(
        driver, ".__start_label._title_label")

    # This is where our selection will end
    end = util.element_screen_center(element)
    end["left"] += 2  # Move it off-center for this test

    element.click()
    wedutil.wait_for_caret_to_be_in(util, parent)

    # From the label to before the first letter and then past the
    # first letter.
    ActionChains(driver)\
        .send_keys(*[Keys.ARROW_RIGHT] * 2)\
        .perform()

    # We need to get the location of the caret.
    start = wedutil.caret_selection_pos(driver)

    select_text(context, start, end)

    assert_true(util.is_something_selected(), "something must be selected")

    context.expected_selection = parent_text[0:1]
    context.selection_parent = parent
    context.caret_screen_position = wedutil.caret_screen_pos(driver)
예제 #8
0
def step_impl(context):
    driver = context.driver

    last_click = context.last_click
    caret_pos = wedutil.caret_selection_pos(driver)

    assert_equal(selenic.util.locations_within(caret_pos, last_click, 3), "")
예제 #9
0
def step_impl(context):
    util = context.util
    driver = context.driver
    button = util.find_element(
        (By.CSS_SELECTOR, ".body .__start_label._p_label"))
    ActionChains(driver)\
        .click(button)\
        .send_keys([Keys.ARROW_RIGHT] * 6) \
        .perform()

    context.caret_path = driver.execute_script("""
    var caret = wed_editor.getDataCaret();
    return [wed_editor.data_updater.nodeToPath(caret.node), caret.offset];
    """)

    pos = wedutil.caret_selection_pos(driver)
    # First click away so that the caret is no longer where we left it
    # and the subsequent click moves it again.
    el_pos = util.element_screen_position(button)
    ActionChains(driver) \
        .click(button) \
        .move_to_element_with_offset(button,
                                     pos["left"] - el_pos["left"] + 1,
                                     pos["top"] - el_pos["top"]) \
        .click() \
        .perform()
예제 #10
0
파일: caret.py 프로젝트: nenadg/wed
def step_impl(context):
    driver = context.driver

    last_click = context.last_click
    caret_pos = wedutil.caret_selection_pos(driver)

    assert_equal(selenic.util.locations_within(caret_pos, last_click, 3), "")
예제 #11
0
def step_impl(context):
    driver = context.driver
    util = context.util

    element, parent, parent_text = get_element_parent_and_parent_text(
        driver, ".__start_label._title_label")

    # This is where our selection will end
    end = util.element_screen_center(element)
    end["left"] += 2  # Move it off-center for this test

    element.click()
    wedutil.wait_for_caret_to_be_in(util, parent)

    # From the label to before the first letter and then past the
    # first letter.
    ActionChains(driver)\
        .send_keys(*[Keys.ARROW_RIGHT] * 2)\
        .perform()

    # We need to get the location of the caret.
    start = wedutil.caret_selection_pos(driver)

    select_text(context, start, end)

    assert_true(util.is_something_selected(), "something must be selected")

    context.expected_selection = parent_text[0:1]
    context.selection_parent = parent
    context.caret_screen_position = wedutil.caret_screen_pos(driver)
예제 #12
0
파일: caret.py 프로젝트: nenadg/wed
def step_impl(context):
    util = context.util
    driver = context.driver
    button = util.find_element(
        (By.CSS_SELECTOR, ".body .__start_label._p_label"))
    ActionChains(driver)\
        .click(button)\
        .send_keys([Keys.ARROW_RIGHT] * 6) \
        .perform()

    context.caret_path = driver.execute_script("""
    var caret = wed_editor.getDataCaret();
    return [wed_editor.data_updater.nodeToPath(caret.node), caret.offset];
    """)

    pos = wedutil.caret_selection_pos(driver)
    # First click away so that the caret is no longer where we left it
    # and the subsequent click moves it again.
    el_pos = util.element_screen_position(button)
    ActionChains(driver) \
        .click(button) \
        .move_to_element_with_offset(button,
                                     pos["left"] - el_pos["left"] + 1,
                                     pos["top"] - el_pos["top"]) \
        .click() \
        .perform()
예제 #13
0
def step_impl(context):
    driver = context.driver
    p = context.multiline_paragraph
    end_label = p.find_element_by_css_selector(".__end_label._p_label")
    end_label.click()
    ActionChains(driver) \
        .send_keys([Keys.ARROW_LEFT]) \
        .perform()
    pos = wedutil.caret_selection_pos(driver)
    ActionChains(driver) \
        .send_keys([Keys.ARROW_LEFT]) \
        .perform()
    pos2 = wedutil.caret_selection_pos(driver)
    ActionChains(driver) \
        .move_to_element_with_offset(context.origin_object,
                                     round(pos["left"] + pos2["left"] / 2),
                                     pos["top"]) \
        .click() \
        .perform()
예제 #14
0
파일: caret.py 프로젝트: nenadg/wed
def step_impl(context):
    driver = context.driver
    p = context.multiline_paragraph
    end_label = p.find_element_by_css_selector(".__end_label._p_label")
    end_label.click()
    ActionChains(driver) \
        .send_keys([Keys.ARROW_LEFT]) \
        .perform()
    pos = wedutil.caret_selection_pos(driver)
    ActionChains(driver) \
        .send_keys([Keys.ARROW_LEFT]) \
        .perform()
    pos2 = wedutil.caret_selection_pos(driver)
    ActionChains(driver) \
        .move_to_element_with_offset(context.origin_object,
                                     round(pos["left"] + pos2["left"] / 2),
                                     pos["top"]) \
        .click() \
        .perform()
예제 #15
0
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("/")
예제 #16
0
파일: caret.py 프로젝트: keisetsu/wed
def step_impl(context, direction):
    driver = context.driver
    util = context.util

    direction = direction.strip()

    element = util.find_element((By.CSS_SELECTOR,
                                 "._start_button._title_label"))
    parent = element.find_element_by_xpath("..")
    element.click()
    wedutil.wait_for_caret_to_be_in(util, parent)

    # From the label to before the first letter and then past the
    # first letter.
    ActionChains(driver)\
        .send_keys(*[Keys.ARROW_RIGHT] * 3)\
        .perform()

    # We need to get the location of the caret.
    start = wedutil.caret_selection_pos(driver)
    # This moves two characters to the right
    ActionChains(driver)\
        .send_keys(*[Keys.ARROW_RIGHT] * 2)\
        .perform()
    end = wedutil.caret_selection_pos(driver)

    if direction == "":
        wedutil.select_text(driver, start, end)
    elif direction == "backwards":
        wedutil.select_text(driver, end, start)
    else:
        raise ValueError("unexpected direction: " + direction)

    text = util.get_text_excluding_children(parent)
    context.expected_selection = text[1:3]
    context.selection_parent = parent
    context.caret_position = wedutil.caret_pos(driver)
예제 #17
0
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("/")