Beispiel #1
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)
Beispiel #2
0
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)
Beispiel #3
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)
Beispiel #4
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)
Beispiel #5
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)
Beispiel #6
0
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)
Beispiel #7
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)
Beispiel #8
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)
Beispiel #9
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)
Beispiel #10
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)
Beispiel #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)
    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
Beispiel #12
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
Beispiel #13
0
def step_impl(context, choice):
    driver = context.driver

    context.caret_position_before_arrow = wedutil.caret_screen_pos(driver)

    key = _CHOICE_TO_ARROW[choice]
    ActionChains(driver)\
        .send_keys(key)\
        .perform()
Beispiel #14
0
def step_impl(context):
    driver = context.driver

    context.caret_screen_position_before_focus_loss = \
        wedutil.caret_screen_pos(driver)

    driver.execute_script("window.open('http://www.google.com')")
    driver.switch_to_window([x for x in driver.window_handles
                             if x != context.initial_window_handle][0])
Beispiel #15
0
def step_impl(context):
    driver = context.driver

    context.caret_screen_position_before_focus_loss = \
        wedutil.caret_screen_pos(driver)

    driver.execute_script("window.open('http://www.google.com')")
    driver.switch_to_window([x for x in driver.window_handles
                             if x != context.initial_window_handle][0])
Beispiel #16
0
def step_impl(context, choice):
    driver = context.driver

    context.caret_position_before_arrow = wedutil.caret_screen_pos(driver)

    key = Keys.ARROW_RIGHT if choice == "right" else Keys.ARROW_LEFT
    ActionChains(driver)\
        .send_keys(key)\
        .perform()
Beispiel #17
0
def step_impl(context, choice):
    driver = context.driver

    context.caret_position_before_arrow = wedutil.caret_screen_pos(driver)

    key = Keys.ARROW_RIGHT if choice == "right" else Keys.ARROW_LEFT
    ActionChains(driver)\
        .send_keys(key)\
        .perform()
Beispiel #18
0
def step_impl(context):
    driver = context.driver

    before = context.caret_position_before_label_visibility_change

    after = wedutil.caret_screen_pos(driver)

    # Some platforms use float dimensions so there may be rounding off
    # errors.
    assert_equal(selenic.util.locations_within(before, after, 1), '')
Beispiel #19
0
def step_impl(context, choice):
    driver = context.driver

    context.caret_position_before_arrow = wedutil.caret_screen_pos(
        driver)

    key = _CHOICE_TO_ARROW[choice]
    ActionChains(driver)\
        .send_keys(key)\
        .perform()
Beispiel #20
0
def step_impl(context):
    driver = context.driver
    util = context.util
    initial_pos = context.caret_position_before_arrow

    util.wait(lambda *_: initial_pos != wedutil.caret_screen_pos(driver))

    initial = context.clicked_element_parent_initial_text
    parent = context.clicked_element_parent
    final = util.get_text_excluding_children(parent)
    assert_equal(initial[:-1], final, "edited text")
Beispiel #21
0
def step_impl(context):
    driver = context.driver
    util = context.util
    initial_pos = context.caret_position_before_arrow

    util.wait(lambda *_: initial_pos != wedutil.caret_screen_pos(driver))

    initial = context.clicked_element_parent_initial_text
    parent = context.clicked_element_parent
    final = util.get_text_excluding_children(parent)
    assert_equal(initial[:-1], final, "edited text")
Beispiel #22
0
def step_impl(context, text):
    driver = context.driver
    util = context.util

    element = util.find_clickable_element((By.CLASS_NAME, "title"))
    ActionChains(driver) \
        .click(element) \
        .perform()
    wedutil.wait_for_caret_to_be_in(util, element)
    context.element_to_test_for_text = element
    assert_true(util.get_text_excluding_children(element).find(text) == -1)
    context.caret_screen_position = wedutil.caret_screen_pos(driver)
Beispiel #23
0
def step_impl(context, text):
    driver = context.driver
    util = context.util

    element = util.find_clickable_element((By.CLASS_NAME, "title"))
    ActionChains(driver) \
        .click(element) \
        .perform()
    wedutil.wait_for_caret_to_be_in(util, element)
    context.element_to_test_for_text = element
    assert_true(
        util.get_text_excluding_children(element).find(text) == -1)
    context.caret_screen_position = wedutil.caret_screen_pos(driver)
Beispiel #24
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)
Beispiel #25
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
Beispiel #26
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
Beispiel #27
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)
Beispiel #28
0
def step_impl(context):
    driver = context.driver
    util = context.util

    p = util.find_element((By.CSS_SELECTOR, ".body .p"))

    text = wedutil.select_contents_directly(util, p)

    context.expected_selection_serialization = driver.execute_script("""
    var data_node = wed_editor.toDataNode(arguments[0]);
    var range = document.createRange();
    range.selectNodeContents(data_node);
    var clone = range.cloneContents();
    var parser = new window.DOMParser();
    var doc = parser.parseFromString("<div></div>", "text/xml");
    while(clone.firstChild)
      doc.firstChild.appendChild(clone.firstChild);
    return doc.firstChild.innerHTML;
    """, p)

    context.expected_selection = text
    context.selection_parent = p
    context.caret_screen_position = wedutil.caret_screen_pos(driver)
Beispiel #29
0
def step_impl(context):
    driver = context.driver
    util = context.util

    p = util.find_element((By.CSS_SELECTOR, ".body .p"))

    text = wedutil.select_contents_directly(util, p)

    context.expected_selection_serialization = driver.execute_script("""
    var data_node = wed_editor.toDataNode(arguments[0]);
    var range = document.createRange();
    range.selectNodeContents(data_node);
    var clone = range.cloneContents();
    var parser = new window.DOMParser();
    var doc = parser.parseFromString("<div></div>", "text/xml");
    while(clone.firstChild)
      doc.firstChild.appendChild(clone.firstChild);
    return doc.firstChild.innerHTML;
    """, p)

    context.expected_selection = text
    context.selection_parent = p
    context.caret_screen_position = wedutil.caret_screen_pos(driver)
Beispiel #30
0
def step_impl(context):
    context.util.wait(lambda driver:
                      context.caret_screen_position_before_focus_loss ==
                      wedutil.caret_screen_pos(driver))
Beispiel #31
0
 def cond2(driver):
     pos = wedutil.caret_screen_pos(driver)
     return pos if pos_before != pos else False
Beispiel #32
0
 def cond2(driver):
     pos = wedutil.caret_screen_pos(driver)
     return pos if pos_before != pos else False
Beispiel #33
0
def step_impl(context):
    context.util.wait(
        lambda driver: context.caret_screen_position_before_focus_loss ==
        wedutil.caret_screen_pos(driver))