Skip to content

Commit 9dd763a

Browse files
committed
Initial implementation of Mouse and Keyboard abstractions
1 parent 36b6957 commit 9dd763a

File tree

8 files changed

+183
-39
lines changed

8 files changed

+183
-39
lines changed

src/interaction/se_actions.e

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,62 @@ note
77
class
88
SE_ACTIONS
99

10+
create
11+
make
12+
13+
feature {NONE} -- Initialization
14+
15+
make (a_web_driver: WEB_DRIVER)
16+
-- Create an object Actions using webdriver input devices (mouse and keyboard)
17+
do
18+
make_with_parameters (a_web_driver.mouse, a_web_driver.keyboard )
19+
ensure
20+
keyboard_set: attached keyboard
21+
mouse_set: attached mouse
22+
actions_set: actions.is_empty
23+
end
24+
25+
make_with_parameters (a_mouse: SE_MOUSE; a_keyboard: SE_KEYBOARD)
26+
-- Create an object Actions with `a_mouse' and `a_keyboard'
27+
do
28+
set_keyboard (a_keyboard)
29+
set_mouse (a_mouse)
30+
reset
31+
ensure
32+
keyboard_set: keyboard = a_keyboard
33+
mouse_set: mouse = a_mouse
34+
actions_set: actions.is_empty
35+
end
1036

1137
feature -- Access
1238

13-
-- keyboard: SE_KEYBOARD
14-
-- mouse: SE_MOUSE
39+
keyboard: SE_KEYBOARD
40+
mouse: SE_MOUSE
41+
actions: SE_COMPOSITE_ACTION
42+
43+
feature -- Change Element
44+
45+
reset
46+
-- Create a new instance of composite actions.
47+
do
48+
create actions.make
49+
end
50+
51+
52+
set_keyboard (a_keyboard: SE_KEYBOARD)
53+
-- Set `keyboard' with `a_keyboard'
54+
do
55+
keyboard := a_keyboard
56+
ensure
57+
keyboard_set: keyboard = a_keyboard
58+
end
59+
60+
set_mouse (a_mouse: SE_MOUSE)
61+
-- Set `mouse' with `a_mouse'
62+
do
63+
mouse := a_mouse
64+
ensure
65+
mouse_set: mouse = a_mouse
66+
end
67+
1568
end

src/interaction/se_base_action.e

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
note
2+
description: "Summary description for {SE_BASE_ACTION}."
3+
author: ""
4+
date: "$Date$"
5+
revision: "$Revision$"
6+
7+
deferred class
8+
SE_BASE_ACTION
9+
10+
feature {NONE} -- Initialization
11+
12+
13+
feature -- Access
14+
15+
location: detachable SE_COORDINATES
16+
17+
end

src/interaction/se_composite_action.e

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ create
1717
feature {NONE} -- Initialization
1818

1919
make
20+
-- Create an empty composite actions
2021
do
2122
create {ARRAYED_LIST[SE_ACTION]}actions.make (5)
2223
ensure
23-
actions_empty: actions.is_empty
24+
actions_empty: is_empty
2425
end
2526

2627
feature -- Execute
@@ -33,10 +34,19 @@ feature -- Execute
3334
feature -- Access
3435

3536
count: INTEGER
37+
-- Number of items
3638
do
3739
Result := actions.count
3840
end
3941

42+
feature -- Status report
43+
44+
is_empty: BOOLEAN
45+
-- Is the current list of actions empty?
46+
do
47+
Result := actions.is_empty
48+
end
49+
4050
feature -- Change Element
4151

4252
add_action (a_action: SE_ACTION)

src/interaction/se_coordinates.e

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,48 +16,49 @@ create
1616

1717
feature {NONE} -- Initialization
1818

19-
make ( a_web_driver : like driver)
19+
make (a_web_driver: like driver)
2020
-- Create an object se_mouse with his driver
2121
do
2222
driver := a_web_driver
2323
ensure
24-
web_driver_set : driver = a_web_driver
24+
web_driver_set: driver = a_web_driver
2525
end
2626

27-
2827
feature -- Access
2928

3029
on_screen: detachable SE_POINT
30+
-- Gets Coordinates on the element relative to the top-left corner of the monitor (screen).
3131
do
3232
to_implement ("Not supported yet.")
3333
end
3434

3535
in_view_port: detachable SE_POINT
36+
-- Gets coordinates on the element relative to the top-left corner of OS-window being used
37+
-- to display the content. Usually it is the browser window's viewport.
3638
do
37-
if attached driver.active_element as l_element and then
38-
attached driver.session as l_session then
39+
if attached driver.active_element as l_element and then attached driver.session as l_session then
3940
Result := driver.api.location_in_view (l_session.session_id, l_element.element)
4041
end
4142
end
4243

4344
on_page: detachable SE_POINT
45+
-- Gets coordinates on the element relative to the top-left corner of the page.
4446
do
45-
if attached driver.active_element as l_element and then
46-
attached driver.session as l_session then
47+
if attached driver.active_element as l_element and then attached driver.session as l_session then
4748
Result := driver.api.element_location (l_session.session_id, l_element.element)
4849
end
4950
end
5051

51-
auxiliary: detachable ANY
52+
auxiliary: detachable WEB_ELEMENT
5253
do
5354
if attached driver.active_element as l_element then
54-
Result := l_element.element
55+
Result := l_element
5556
end
5657
end
5758

58-
5959
feature -- {NONE} -- Implementations
60-
driver : WEB_DRIVER
61-
-- web_driver
60+
61+
driver: WEB_DRIVER
62+
-- web_driver
6263

6364
end

src/interaction/se_mouse.e

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,61 +22,74 @@ feature {NONE} -- Initialization
2222

2323
feature -- Mouse Actions
2424

25-
click (a_coordinates: SE_COORDINATES)
25+
click (a_coordinates: detachable SE_COORDINATES)
2626
do
27+
move_if_needed (a_coordinates)
28+
if attached driver.session as l_session then
29+
driver.api.click (l_session.session_id, create {SE_BUTTON}.make_left)
30+
end
2731
end
2832

29-
double_click (a_coordinates: SE_COORDINATES)
33+
double_click (a_coordinates: detachable SE_COORDINATES)
3034
do
31-
35+
move_if_needed (a_coordinates)
36+
if attached driver.session as l_session then
37+
driver.api.double_click (l_session.session_id)
38+
end
3239
end
3340

34-
mouse_down (a_coordinates: SE_COORDINATES)
41+
mouse_down (a_coordinates: detachable SE_COORDINATES)
3542
do
36-
43+
move_if_needed (a_coordinates)
44+
if attached driver.session as l_session then
45+
driver.api.button_down (l_session.session_id, create {SE_BUTTON}.make_left)
46+
end
3747
end
3848

3949

40-
mouse_up (a_coordinates: SE_COORDINATES)
50+
mouse_up (a_coordinates: detachable SE_COORDINATES)
4151
do
42-
52+
move_if_needed (a_coordinates)
53+
if attached driver.session as l_session then
54+
driver.api.button_up (l_session.session_id, create {SE_BUTTON}.make_left)
55+
end
4356
end
4457

4558
mouse_move (a_coordinates: SE_COORDINATES)
4659
do
47-
60+
if attached driver.session as l_session and then attached a_coordinates.auxiliary as l_element then
61+
driver.api.move_to_default (l_session.session_id,l_element)
62+
end
4863
end
4964

5065
mouse_move_by_params (a_coordinates: SE_COORDINATES; a_param1: INTEGER_64; a_param2: INTEGER_64)
5166
do
52-
67+
if attached driver.session as l_session and then attached a_coordinates.auxiliary as l_element then
68+
driver.api.move_to (l_session.session_id,l_element,a_param1, a_param2)
69+
end
5370
end
5471

55-
context_click (a_coordinates: SE_COORDINATES)
72+
context_click (a_coordinates: detachable SE_COORDINATES)
73+
-- Right click an element
5674
do
57-
75+
move_if_needed (a_coordinates)
76+
if attached driver.session as l_session then
77+
driver.api.click (l_session.session_id, create {SE_BUTTON}.make_right)
78+
end
5879
end
5980

6081

6182

6283
feature {NONE} -- Implementation
6384

64-
65-
params_from_coordinates (a_where: SE_COORDINATES): HASH_TABLE[ANY,STRING]
85+
move_if_needed (a_coordinates: detachable SE_COORDINATES)
6686
do
67-
create Result.make(1)
68-
if attached {STRING} a_where.auxiliary as l_id then
69-
Result.force (l_id,"element")
87+
if attached a_coordinates as l_coordinates then
88+
mouse_move (a_coordinates)
7089
end
7190
end
7291

73-
74-
7592
driver : WEB_DRIVER
7693
-- web_driver
7794

78-
json_template : String = "[
79-
{"value" :"$value",
80-
"isdown" : $boolean}
81-
]"
8295
end

src/protocol/se_json_wire_protocol.e

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1704,7 +1704,7 @@ feature -- Commands
17041704
end
17051705
end
17061706

1707-
move_to (a_session_id: STRING_32; web_element : WEB_ELEMENT; xoffset : NATURAL; yoffset:NATURAL)
1707+
move_to (a_session_id: STRING_32; web_element : WEB_ELEMENT; xoffset : INTEGER_64; yoffset:INTEGER_64)
17081708
-- POST /session/:sessionId/moveto
17091709
-- Move the mouse by an offset of the specificed element.
17101710
-- If no element is specified, the move is relative to the current mouse cursor.
@@ -1736,6 +1736,34 @@ feature -- Commands
17361736
end
17371737
end
17381738

1739+
move_to_default (a_session_id: STRING_32; web_element : WEB_ELEMENT)
1740+
-- POST /session/:sessionId/moveto
1741+
-- Move the mouse by an offset of the specificed element.
1742+
-- If no element is specified, the move is relative to the current mouse cursor.
1743+
-- If an element is provided but no offset, the mouse will be moved to the center of the element.
1744+
-- If the element is not visible, it will be scrolled into view.
1745+
-- URL Parameters:
1746+
-- :sessionId - ID of the session to route the command to.
1747+
-- JSON Parameters:
1748+
-- element - {string} Opaque ID assigned to the element to move to, as described in the WebElement JSON Object. If not specified or is null, the offset is relative to current position of the mouse.
1749+
-- xoffset - {number} X offset to move to, relative to the top-left corner of the element. If not specified, the mouse will move to the middle of the element.
1750+
-- yoffset - {number} Y offset to move to, relative to the top-left corner of the element. If not specified, the mouse will move to the middle of the element.
1751+
local
1752+
resp : SE_RESPONSE
1753+
l_json : STRING_32
1754+
1755+
do
1756+
l_json := "[
1757+
{ "element" : "$element"
1758+
}
1759+
]"
1760+
if commnad_executor.is_available then
1761+
l_json.replace_substring_all ("$element", web_element.element)
1762+
resp := commnad_executor.move_to (a_session_id, l_json)
1763+
check_response (resp)
1764+
end
1765+
end
1766+
17391767

17401768
modifier (a_session_id: STRING_32; data: STRING)
17411769
-- POST /session/:sessionId/modifier
@@ -1823,6 +1851,7 @@ feature -- Commands
18231851
check_response (resp)
18241852
end
18251853
end
1854+
18261855
double_click (a_session_id: STRING_32)
18271856
-- POST /session/:sessionId/doubleclick
18281857
-- Double-clicks at the current mouse coordinates (set by moveto).

src/se_button.e

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ note
66

77
class
88
SE_BUTTON
9+
910
inherit {NONE}
11+
1012
ENUM
1113

1214

@@ -21,16 +23,22 @@ feature -- Initialization
2123
make_left
2224
do
2325
set_left
26+
ensure
27+
left_set: is_left
2428
end
2529

2630
make_middle
2731
do
2832
set_middle
33+
ensure
34+
middle_set: is_middle
2935
end
3036

3137
make_right
3238
do
3339
set_right
40+
ensure
41+
right_set: is_right
3442
end
3543

3644

@@ -85,6 +93,7 @@ feature -- Query
8593

8694

8795
feature {NONE} -- Implementation
96+
8897
-- {LEFT = 0, MIDDLE = 1 , RIGHT = 2}
8998
left_value :INTEGER = 0
9099
middle_value : INTEGER = 1

src/web_driver.e

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,19 @@ feature {WEB_DRIVER, WEB_DRIVER_WAIT}
476476
end
477477
end
478478

479-
feature {SE_KEYBOARD, SE_COORDINATES} -- Implementation
479+
feature -- Input Devices
480+
481+
keyboard: SE_KEYBOARD
482+
do
483+
create Result.make (Current)
484+
end
485+
486+
mouse: SE_MOUSE
487+
do
488+
create Result.make (Current)
489+
end
490+
491+
feature {SE_KEYBOARD, SE_COORDINATES, SE_MOUSE} -- Implementation
480492

481493
session: detachable SE_SESSION
482494

0 commit comments

Comments
 (0)