コード例 #1
0
ファイル: caret.py プロジェクト: bennettbuchanan/wed
def step_impl(context, what):
    driver = context.driver
    util = context.util

    if what == "an element":
        what = "the first title element"

    if what == "the first title element":
        selector = ".__start_label._title_label"
    elif what == 'the first paragraph in "body"':
        selector = ".body .__start_label._p_label"
    else:
        raise ValueError("unknown value for what: " + what)

    element, parent, parent_text = get_element_parent_and_parent_text(
        driver, selector)

    ActionChains(driver)\
        .click(element) \
        .perform()

    util.send_keys(element,
                   # From the label to before the first letter.
                   [Keys.ARROW_RIGHT] +
                   # This select the whole text of the element.
                   [Keys.SHIFT] + [Keys.ARROW_RIGHT] * len(parent_text) +
                   [Keys.SHIFT])

    assert_true(util.is_something_selected(), "something must be selected")
    text = util.get_selection_text()
    assert_equal(text, parent_text, "expected selection")

    context.expected_selection = text
    context.selection_parent = parent
    context.caret_screen_position = wedutil.caret_screen_pos(driver)
コード例 #2
0
ファイル: caret.py プロジェクト: nenadg/wed
def step_impl(context, what):
    driver = context.driver
    util = context.util

    if what == "an element":
        what = "the first title element"

    if what == "the first title element":
        selector = ".__start_label._title_label"
    elif what == 'the first paragraph in "body"':
        selector = ".body .__start_label._p_label"
    else:
        raise ValueError("unknown value for what: " + what)

    element, parent, parent_text = get_element_parent_and_parent_text(
        driver, selector)

    ActionChains(driver)\
        .click(element) \
        .perform()

    util.send_keys(
        element,
        # From the label to before the first letter.
        [Keys.ARROW_RIGHT] +
        # This select the whole text of the element.
        [Keys.SHIFT] + [Keys.ARROW_RIGHT] * len(parent_text) + [Keys.SHIFT])

    assert_true(util.is_something_selected(), "something must be selected")
    text = util.get_selection_text()
    assert_equal(text, parent_text, "expected selection")

    context.expected_selection = text
    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

    if what == "an element":
        what = "the first title element"

    expected_text = None
    if what == "the first title element":
        selector = ".__start_label._title_label"
    elif what == 'the first paragraph in "body"':
        selector = ".body .__start_label._p_label"
    elif what == "an attribute":
        selector = ".body .__start_label._p_label"
    elif what == 'a readonly element with the text "abc"':
        selector = ".body ._readonly .__end_label"
        expected_text = "abc"
    else:
        raise ValueError("unknown value for what: " + what)

    element, parent, length = \
        get_element_parent_and_selection_length(driver, selector)

    ActionChains(driver)\
        .click(element) \
        .perform()

    if selector.find("__end_label") != -1:
        util.send_keys(element,
                       # From the label to after the text
                       [Keys.ARROW_LEFT] +
                       # This select the whole text of the element.
                       [Keys.SHIFT] + [Keys.ARROW_LEFT] * length +
                       [Keys.SHIFT])
    else:
        util.send_keys(element,
                       # From the label to before the first letter.
                       [Keys.ARROW_RIGHT] +
                       # This select the whole text of the element.
                       [Keys.SHIFT] + [Keys.ARROW_RIGHT] * length +
                       [Keys.SHIFT])

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

    if expected_text is not None:
        assert_equal(text, expected_text)

    context.expected_selection = text
    context.selection_parent = parent
    context.caret_screen_position = wedutil.caret_screen_pos(driver)
コード例 #7
0
ファイル: caret.py プロジェクト: bennettbuchanan/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):
    driver = context.driver
    util = context.util

    driver.execute_script("""
    const p = wed_editor.guiRoot.querySelectorAll(".body .p")[7];
    const caretManager = wed_editor.caretManager;
    const attr = p.getElementsByClassName("_attribute_value")[0];
    const text = attr.firstChild;
    const guiStart = caretManager.makeCaret(text, 0);
    const guiEnd = caretManager.makeCaret(text, text.length);
    const dataStart = caretManager.toDataLocation(guiStart);
    const dataEnd = caretManager.toDataLocation(guiEnd);
    caretManager.setRange(guiStart, guiEnd);
    """)

    context.expected_selection = util.get_selection_text()
    context.selection_parent = None
    context.caret_screen_position = wedutil.caret_screen_pos(driver)
コード例 #9
0
ファイル: caret.py プロジェクト: bennettbuchanan/wed
def step_impl(context):
    util = context.util

    assert_equal(util.get_selection_text(), context.expected_selection)
コード例 #10
0
ファイル: caret.py プロジェクト: bennettbuchanan/wed
def step_impl(context):
    util = context.util

    util.wait(lambda *_: util.get_selection_text() ==
              context.expected_selection)
コード例 #11
0
ファイル: caret.py プロジェクト: bennettbuchanan/wed
def step_impl(context):
    util = context.util

    text = util.get_selection_text()
    assert_equal(text, "abcd", "expected selection")
コード例 #12
0
ファイル: caret.py プロジェクト: nenadg/wed
def step_impl(context):
    util = context.util

    assert_equal(util.get_selection_text(), context.expected_selection)
コード例 #13
0
ファイル: caret.py プロジェクト: nenadg/wed
def step_impl(context):
    util = context.util

    util.wait(
        lambda *_: util.get_selection_text() == context.expected_selection)
コード例 #14
0
ファイル: caret.py プロジェクト: nenadg/wed
def step_impl(context):
    util = context.util

    text = util.get_selection_text()
    assert_equal(text, "abcd", "expected selection")