def step_impl(context, direction): direction = direction.strip() driver = context.driver util = context.util if direction == "": keys = ( # From the label to before the first letter and then past the # first letter. [Keys.ARROW_RIGHT] * 2 + # This moves two caracters to the right with shift down. [Keys.SHIFT] + [Keys.ARROW_RIGHT] * 2 + [Keys.SHIFT]) elif direction == "backwards": keys = ( # From the label to before the first letter and then past the # first letter, and then two more to the right. [Keys.ARROW_RIGHT] * (2 + 2) + # This moves two caracters to the left with shift down. [Keys.SHIFT] + [Keys.ARROW_LEFT] * 2 + [Keys.SHIFT]) else: raise ValueError("unexpected direction: " + direction) element, _, parent_text = get_element_parent_and_parent_text( driver, ".__start_label._title_label") ActionChains(driver)\ .click(element)\ .perform() util.send_keys(element, keys) assert_true(util.is_something_selected(), "something must be selected") context.expected_selection = parent_text[1:3]
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)
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)
def step_impl(context): driver = context.driver util = context.util element, parent, _ = get_element_parent_and_parent_text( driver, ".__start_label._title_label") ActionChains(driver)\ .click(element)\ .perform() # On IE, sending the keys to the element itself does not work. send_to = element if driver.name != "internet explorer" else \ util.find_element((By.CSS_SELECTOR, ".wed-document")) util.send_keys(send_to, # From the label to before the first letter and then past # the first letter. [Keys.ARROW_RIGHT] * 3 + # This moves 9 caracters to the right with shift down. [Keys.SHIFT] + [Keys.ARROW_RIGHT] * 9 + [Keys.SHIFT]) assert_true(util.is_something_selected(), "something must be selected") context.selection_parent = parent
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
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
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)
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
def step_impl(context): driver = context.driver util = context.util element = util.find_element((By.CSS_SELECTOR, ".__start_label._title_label")) ActionChains(driver)\ .click(element)\ .perform() # On IE, sending the keys to the element itself does not work. send_to = element if driver.name != "internet explorer" else \ util.find_element((By.CSS_SELECTOR, ".wed-document")) util.send_keys(send_to, # From the label to before the first letter and then past # the first letter. [Keys.ARROW_RIGHT] * 3 + # This moves 9 caracters to the right with shift down. [Keys.SHIFT] + [Keys.ARROW_RIGHT] * 9 + [Keys.SHIFT]) assert_true(util.is_something_selected(), "something must be selected")