def test_drag_and_drop(session, test_actions_page, mouse_chain, dx, dy, drag_duration): drag_target = session.find.css("#dragTarget", all=False) initial_rect = drag_target.rect initial_center = get_center(initial_rect) # Conclude chain with extra move to allow time for last queued # coordinate-update of drag_target and to test that drag_target is "dropped". mouse_chain \ .pointer_move(0, 0, origin=drag_target) \ .pointer_down() \ .pointer_move(dx, dy, duration=drag_duration, origin="pointer") \ .pointer_up() \ .pointer_move(80, 50, duration=100, origin="pointer") \ .perform() # mouseup that ends the drag is at the expected destination e = get_events(session)[1] assert e["type"] == "mouseup" assert approx(e["pageX"], initial_center["x"] + dx) assert approx(e["pageY"], initial_center["y"] + dy) # check resulting location of the dragged element final_rect = drag_target.rect assert initial_rect["x"] + dx == final_rect["x"] assert initial_rect["y"] + dy == final_rect["y"]
def test_click_element_center(session, test_actions_page, mouse_chain): outer = session.find.css("#outer", all=False) center = get_center(outer.rect) mouse_chain.click(element=outer).perform() events = get_events(session) assert len(events) == 4 event_types = [e["type"] for e in events] assert ["mousemove", "mousedown", "mouseup", "click"] == event_types for e in events: if e["type"] != "mousemove": assert approx(e["pageX"], center["x"]) assert approx(e["pageY"], center["y"]) assert e["target"] == "outer"
def test_dblclick_with_pause_after_second_pointerdown(dblclick_session, mouse_chain): outer = dblclick_session.find.css("#outer", all=False) center = get_center(outer.rect) mouse_chain \ .pointer_move(int(center["x"]), int(center["y"])) \ .click() \ .pointer_down() \ .pause(_DBLCLICK_INTERVAL + 10) \ .pointer_up() \ .perform() events = get_events(dblclick_session) expected = [ { "type": "mousedown", "button": 0 }, { "type": "mouseup", "button": 0 }, { "type": "click", "button": 0 }, { "type": "mousedown", "button": 0 }, { "type": "mouseup", "button": 0 }, { "type": "click", "button": 0 }, { "type": "dblclick", "button": 0 }, ] assert len(events) == 8 filtered_events = [filter_dict(e, expected[0]) for e in events] assert expected == filtered_events[1:]
def test_no_dblclick(dblclick_session, mouse_chain): outer = dblclick_session.find.css("#outer", all=False) center = get_center(outer.rect) mouse_chain \ .pointer_move(int(center["x"]), int(center["y"])) \ .click() \ .pause(_DBLCLICK_INTERVAL + 10) \ .click() \ .perform() events = get_events(dblclick_session) expected = [ {"type": "mousedown", "button": 0}, {"type": "mouseup", "button": 0}, {"type": "click", "button": 0}, {"type": "mousedown", "button": 0}, {"type": "mouseup", "button": 0}, {"type": "click", "button": 0}, ] assert len(events) == 7 filtered_events = [filter_dict(e, expected[0]) for e in events] assert expected == filtered_events[1:]