Exemple #1
0
def step_impl(context):
    driver = context.driver
    util = context.util

    # Obtain the first placeholder after "[etymology]".
    ph = __get_first_ph_in_etymology(driver)

    wedutil.click_until_caret_in(util, ph)
    ActionChains(driver) \
        .send_keys("Foo") \
        .perform()
    wedutil.select_text_of_element_directly(util, r".btw\:etymology>.p")

    util.ctrl_equivalent_x("/")

    context.execute_steps("""
    When the user clicks the context menu option "Replace the selection \
with a bibliographical reference"
    """)

    util.find_element((By.CSS_SELECTOR,
                       ".wed-typeahead-popup .tt-input"))

    # We do this rather than send directly to the input element
    # because it should have been focussed automatically.

    ActionChains(driver) \
        .send_keys(Keys.ENTER) \
        .perform()
def step_impl(context):
    driver = context.driver
    util = context.util

    # Obtain the first placeholder after "[etymology]".
    ph = __get_first_ph_in_etymology(driver)

    wedutil.click_until_caret_in(util, ph)
    ActionChains(driver) \
        .send_keys("Foo") \
        .perform()
    wedutil.select_text_of_element_directly(util, r".btw\:etymology>.p")

    util.ctrl_equivalent_x("/")

    context.execute_steps(u"""
    When the user clicks the context menu option "Replace the selection \
with a bibliographical reference"
    """)

    util.find_element((By.CSS_SELECTOR,
                       ".wed-typeahead-popup .tt-input"))

    # We do this rather than send directly to the input element
    # because it should have been focussed automatically.

    ActionChains(driver) \
        .send_keys(Keys.ENTER) \
        .perform()
Exemple #3
0
def step_impl(context, parent):
    util = context.util

    parent = "." + parent.replace(":", r"\:")
    element = util.find_element((By.CSS_SELECTOR, parent + r">.btw\:none"))

    # Rendering can screw up our click... so check that it is where we
    # want it.
    wedutil.click_until_caret_in(util, element)
Exemple #4
0
def step_impl(context, parent):
    util = context.util

    parent = "." + parent.replace(":", r"\:")
    element = util.find_element((By.CSS_SELECTOR, parent + r">.btw\:none"))
    btw_util.scroll_into_view(context.driver, element)

    # Rendering can screw up our click... so check that it is where we
    # want it.
    wedutil.click_until_caret_in(util, element)
Exemple #5
0
def step_impl(context):
    util = context.util
    driver = context.driver

    el = driver.find_element_by_css_selector(
        r".__start_label._btw\:example_label, "
        r".__start_label._btw\:example-explained_label")

    wedutil.click_until_caret_in(util, el)
    context.execute_steps("""
    When the user brings up the context menu
    And the user clicks the context menu option "Delete this element"
    """)
def step_impl(context):
    util = context.util
    driver = context.driver

    el = driver.find_element_by_css_selector(
        r".__start_label._btw\:example_label, "
        r".__start_label._btw\:example-explained_label")

    wedutil.click_until_caret_in(util, el)
    context.execute_steps(u"""
    When the user brings up the context menu
    And the user clicks the context menu option "Delete this element"
    """)
Exemple #7
0
def step_impl(context, choice):
    driver = context.driver
    util = context.util

    class_name = None
    if choice == "a placeholder":
        parent, where = driver.execute_script("""
        var $ph = jQuery("._placeholder");
        var $parent = $ph.closest("._real");
        return [$parent[0], $ph[0]];
        """)
    elif choice == "text":
        where = util.find_element((By.CLASS_NAME, "title"))
        parent = where
    else:
        raise ValueError("unknown choice: " + choice)

    max_tries = 5
    while True:
        # IF YOU CHANGE THIS, CHANGE THE TRIGGER
        wedutil.click_until_caret_in(util, where)
        util.ctrl_equivalent_x("/")
        try:
            # We don't want to check too fast so we do use an explicit
            # wait by way of ``util``.
            util.find_element((By.CLASS_NAME, "wed-context-menu"))
            # If we get here, the menu exists.
            break
        except TimeoutException:
            # The menu did not come up. Probably something messed up
            # the caret between ``click_until_caret_in`` and
            # ``ctrl_equivalent_x``. Try again or decide that it just
            # won't happen.
            max_tries -= 1
            if max_tries == 0:
                raise Exception("tried multiple times to bring up "
                                "the contextual menu, but was "
                                "unsuccessful")

    # THIS TRIGGER WORKS ONLY BECAUSE OF .click(where) above.
    context.context_menu_trigger = Trigger(util, where)
    context.context_menu_for = parent
Exemple #8
0
def step_impl(context, choice):
    driver = context.driver
    util = context.util

    class_name = None
    if choice == "a placeholder":
        parent, where = driver.execute_script("""
        var $ph = jQuery("._placeholder");
        var $parent = $ph.closest("._real");
        return [$parent[0], $ph[0]];
        """)
    elif choice == "text":
        where = util.find_element((By.CLASS_NAME, "title"))
        parent = where
    else:
        raise ValueError("unknown choice: " + choice)

    max_tries = 5
    while True:
        # IF YOU CHANGE THIS, CHANGE THE TRIGGER
        wedutil.click_until_caret_in(util, where)
        util.ctrl_equivalent_x("/")
        try:
            # We don't want to check too fast so we do use an explicit
            # wait by way of ``util``.
            util.find_element((By.CLASS_NAME, "wed-context-menu"))
            # If we get here, the menu exists.
            break
        except TimeoutException:
            # The menu did not come up. Probably something messed up
            # the caret between ``click_until_caret_in`` and
            # ``ctrl_equivalent_x``. Try again or decide that it just
            # won't happen.
            max_tries -= 1
            if max_tries == 0:
                raise Exception("tried multiple times to bring up "
                                "the contextual menu, but was "
                                "unsuccessful")

    # THIS TRIGGER WORKS ONLY BECAUSE OF .click(where) above.
    context.context_menu_trigger = Trigger(util, where)
    context.context_menu_for = parent
Exemple #9
0
def step_impl(context, what):
    driver = context.driver
    util = context.util

    label_class = "._" + what.replace(":", ur"\:") + "_label"

    # Use util to wait until the elements are decorated...
    antonym_lbls = util.find_elements(
        (By.CSS_SELECTOR, r".__start_label" + label_class))

    while len(antonym_lbls):
        wedutil.click_until_caret_in(util, antonym_lbls[0])
        context.execute_steps(u"""
        When the user brings up the context menu
        And the user clicks the context menu option "Delete this element"
        """)

        # Use driver so that we don't get a timeout.
        antonym_lbls = driver.find_elements_by_css_selector(
            r".__start_label" + label_class)
Exemple #10
0
def step_impl(context, what):
    driver = context.driver
    util = context.util

    label_class = "._" + what.replace(":", r"\:") + "_label"

    # Use util to wait until the elements are decorated...
    antonym_lbls = util.find_elements(
        (By.CSS_SELECTOR, r".__start_label" + label_class))

    while len(antonym_lbls):
        btw_util.scroll_into_view(driver, antonym_lbls[0])
        wedutil.click_until_caret_in(util, antonym_lbls[0])
        context.execute_steps("""
        When the user brings up the context menu
        And the user clicks the context menu option "Delete this element"
        """)

        # Use driver so that we don't get a timeout.
        antonym_lbls = driver.find_elements_by_css_selector(
            r".__start_label" + label_class)
Exemple #11
0
def step_impl(context, which=None):
    driver = context.driver
    util = context.util

    order = None
    if which == " to the first example":
        order = 0
        which = "with"
    elif which == " to the second example":
        order = 1
        which = "with"
    elif which is None:
        which = "with"

    if order is None:
        # Obtain the first placeholder after "[etymology]".
        ph = __get_first_ph_in_etymology(driver)

        wedutil.click_until_caret_in(util, ph)
        util.ctrl_equivalent_x("/")
    else:
        # By doing it this way, we avoid being thrown off by possible
        # error markers that could show in front of it.
        driver.execute_script(ur"""
        var order = arguments[0];
        var cits = document.getElementsByClassName("btw:cit");
        var node = cits[order];
        node.scrollIntoView();
        var data_node = jQuery.data(node, "wed_mirror_node");
        if (data_node.childNodes.length) {
            data_node = data_node.firstChild;
        }
        wed_editor.caretManager.setCaret(data_node, 0);
        """, order)

        util.ctrl_equivalent_x("/")

    context.execute_steps(u"""
    When the user clicks the context menu option "Insert a new \
bibliographical reference"
    """)

    title = WHICH_TO_TITLE[which]
    typeahead = util.find_element((By.CSS_SELECTOR,
                                   ".wed-typeahead-popup .tt-input"))
    typeahead.send_keys(title)

    def cond(*_):
        ret = driver.execute_script("""
        var title = arguments[0];
        var $suggestion = jQuery(".wed-typeahead-popup " +
                                 ".tt-suggestion:contains('" + title + "')");
        return $suggestion[0];
        """, WHICH_TO_TITLE[which] if which != "with" else "Foo --- ")
        return ret

    suggestion = util.wait(cond)

    ActionChains(driver) \
        .click(suggestion) \
        .perform()
Exemple #12
0
def step_impl(context, which=None):
    driver = context.driver
    util = context.util

    order = None
    if which == " to the first example":
        order = 0
        which = "with"
    elif which == " to the second example":
        order = 1
        which = "with"
    elif which is None:
        which = "with"

    if order is None:
        # Obtain the first placeholder after "[etymology]".
        ph = __get_first_ph_in_etymology(driver)

        wedutil.click_until_caret_in(util, ph)
        util.ctrl_equivalent_x("/")
    else:
        # By doing it this way, we avoid being thrown off by possible
        # error markers that could show in front of it.
        driver.execute_script(r"""
        var order = arguments[0];
        var cits = document.getElementsByClassName("btw:cit");
        var node = cits[order];
        node.scrollIntoView();
        var data_node = wed_editor.toDataNode(node);
        if (data_node.childNodes.length) {
            data_node = data_node.firstChild;
        }
        wed_editor.caretManager.setCaret(data_node, 0);
        """, order)

        util.ctrl_equivalent_x("/")

    context.execute_steps("""
    When the user clicks the context menu option "Insert a new \
bibliographical reference"
    """)

    title = WHICH_TO_TITLE[which]
    typeahead = util.find_element((By.CSS_SELECTOR,
                                   ".wed-typeahead-popup .tt-input"))
    typeahead.send_keys(title)

    def cond(*_):
        ret = driver.execute_script("""
        var title = arguments[0];
        var $suggestion = jQuery(".wed-typeahead-popup " +
                                 ".tt-suggestion:contains('" + title + "')");
        return $suggestion[0];
        """, WHICH_TO_TITLE[which] if which != "with" else "Foo --- ")
        return ret

    suggestion = util.wait(cond)

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