Skip to content

Commit 852c35c

Browse files
committed
Added basic actions, still work in progress
1 parent 9dd763a commit 852c35c

10 files changed

+363
-22
lines changed

src/interaction/se_actions.e

Lines changed: 72 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
note
2-
description: "Summary description for {SE_ACTIONS}."
2+
description: "Object that allows to build a complex chain of events"
33
author: ""
44
date: "$Date$"
55
revision: "$Revision$"
@@ -13,9 +13,9 @@ create
1313
feature {NONE} -- Initialization
1414

1515
make (a_web_driver: WEB_DRIVER)
16-
-- Create an object Actions using webdriver input devices (mouse and keyboard)
16+
-- Create an object Actions using webdriver.
1717
do
18-
make_with_parameters (a_web_driver.mouse, a_web_driver.keyboard )
18+
make_with_parameters (a_web_driver.mouse, a_web_driver.keyboard)
1919
ensure
2020
keyboard_set: attached keyboard
2121
mouse_set: attached mouse
@@ -37,7 +37,9 @@ feature {NONE} -- Initialization
3737
feature -- Access
3838

3939
keyboard: SE_KEYBOARD
40+
4041
mouse: SE_MOUSE
42+
4143
actions: SE_COMPOSITE_ACTION
4244

4345
feature -- Change Element
@@ -48,7 +50,6 @@ feature -- Change Element
4850
create actions.make
4951
end
5052

51-
5253
set_keyboard (a_keyboard: SE_KEYBOARD)
5354
-- Set `keyboard' with `a_keyboard'
5455
do
@@ -65,4 +66,71 @@ feature -- Change Element
6566
mouse_set: mouse = a_mouse
6667
end
6768

69+
feature -- Actions
70+
71+
click (a_element: WEB_ELEMENT): SE_ACTIONS
72+
-- Clicks in the middle of the given element `a_element'
73+
-- Equivalent to call move_to_element (a_element).click()
74+
do
75+
actions.add_action (create {SE_CLICK_ACTION}.make_with_location (mouse, create {SE_COORDINATES}.make (a_element)))
76+
Result := Current
77+
end
78+
79+
click_current: SE_ACTIONS
80+
-- Clicks at the current mouse location
81+
do
82+
actions.add_action (create {SE_CLICK_ACTION}.make (mouse))
83+
Result := Current
84+
end
85+
86+
87+
88+
key_down (a_key: SE_KEY_STROKE): SE_ACTIONS
89+
-- Execute a modifier key press. Does not release the modifier key - subsequent interactions may assume it's kept pressed.
90+
-- Note that the modifier key is <b>never</b> released implicitly - either key_UP(a_Key)or send_keys(Keys.NULL)
91+
do
92+
actions.add_action (create {SE_KEY_DOWN_ACTION}.make(keyboard, mouse, a_key))
93+
Result := Current
94+
end
95+
96+
97+
98+
key_down_element (a_element: WEB_ELEMENT; a_key: SE_KEY_STROKE): SE_ACTIONS
99+
-- Execute a modifer key press after focusing on an element
100+
-- Equivalent to: SE_ACTIONS.click(element).send_keys (a_key)
101+
do
102+
actions.add_action (create {SE_KEY_DOWN_ACTION}.make_with_location (keyboard, mouse, a_key,create {SE_COORDINATES}.make (a_element) ))
103+
Result := Current
104+
end
105+
106+
107+
key_up (a_key: SE_KEY_STROKE): SE_ACTIONS
108+
-- Execute a modifier key release. Releasing a non-depressed modifier key will yield undefined
109+
-- behaviour.
110+
do
111+
actions.add_action (create {SE_KEY_UP_ACTION}.make(keyboard, mouse, a_key))
112+
Result := Current
113+
end
114+
115+
116+
117+
key_up_element (a_element: WEB_ELEMENT; a_key: SE_KEY_STROKE): SE_ACTIONS
118+
-- Executes a modifier key release after focusing on an element.
119+
-- Equivalent to: SE_ACTIONS.click(a_element).send_keys (a_key)
120+
do
121+
actions.add_action (create {SE_KEY_UP_ACTION}.make_with_location (keyboard, mouse, a_key,create {SE_COORDINATES}.make (a_element) ))
122+
Result := Current
123+
end
124+
125+
feature -- Builder
126+
127+
build: SE_ACTION
128+
-- Build a composite action containinig all actions, ready to be executed (and
129+
-- resets the internal builder state, so subsequent calls to build will contain fresh
130+
-- sequences).
131+
do
132+
Result := actions.twin
133+
reset
134+
end
135+
68136
end

src/interaction/se_base_action.e

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,17 @@ note
77
deferred class
88
SE_BASE_ACTION
99

10-
feature {NONE} -- Initialization
10+
feature -- Change Element
1111

12+
set_location (a_location: SE_COORDINATES)
13+
do
14+
location := a_location
15+
ensure
16+
location_set: location /= Void implies location = a_location
17+
end
1218

1319
feature -- Access
1420

1521
location: detachable SE_COORDINATES
16-
22+
--Coordintates of the current action, if any.
1723
end

src/interaction/se_click_action.e

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
note
2+
description: "Summary description for {SE_CLICK_ACTION}."
3+
author: ""
4+
date: "$Date$"
5+
revision: "$Revision$"
6+
7+
class
8+
SE_CLICK_ACTION
9+
10+
inherit
11+
12+
SE_MOUSE_ACTION
13+
14+
SE_ACTION
15+
16+
create
17+
make,
18+
make_with_location
19+
20+
feature -- Execute
21+
22+
execute
23+
-- Execute the current action
24+
-- click an element
25+
do
26+
move_to_location
27+
mouse.click (location)
28+
end
29+
30+
end

src/interaction/se_coordinates.e

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ create
1616

1717
feature {NONE} -- Initialization
1818

19-
make (a_web_driver: like driver)
20-
-- Create an object se_mouse with his driver
19+
make (a_web_element: like element)
20+
-- Create an object coordinet from an element
2121
do
22-
driver := a_web_driver
22+
element := a_web_element
2323
ensure
24-
web_driver_set: driver = a_web_driver
24+
element_set: element = a_web_element
2525
end
2626

2727
feature -- Access
@@ -36,29 +36,23 @@ feature -- Access
3636
-- Gets coordinates on the element relative to the top-left corner of OS-window being used
3737
-- to display the content. Usually it is the browser window's viewport.
3838
do
39-
if attached driver.active_element as l_element and then attached driver.session as l_session then
40-
Result := driver.api.location_in_view (l_session.session_id, l_element.element)
41-
end
39+
Result := element.api.location_in_view (element.session_id, element.element)
4240
end
4341

4442
on_page: detachable SE_POINT
4543
-- Gets coordinates on the element relative to the top-left corner of the page.
4644
do
47-
if attached driver.active_element as l_element and then attached driver.session as l_session then
48-
Result := driver.api.element_location (l_session.session_id, l_element.element)
49-
end
45+
Result := element.api.element_location (element.session_id, element.element)
5046
end
5147

5248
auxiliary: detachable WEB_ELEMENT
5349
do
54-
if attached driver.active_element as l_element then
55-
Result := l_element
56-
end
50+
Result := element
5751
end
5852

5953
feature -- {NONE} -- Implementations
6054

61-
driver: WEB_DRIVER
62-
-- web_driver
55+
element: WEB_ELEMENT
56+
-- web_element
6357

6458
end

src/interaction/se_key_down_action.e

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
note
2+
description: "Summary description for {SE_KEY_DOWN_ACTION}."
3+
author: ""
4+
date: "$Date$"
5+
revision: "$Revision$"
6+
7+
class
8+
SE_KEY_DOWN_ACTION
9+
10+
inherit
11+
12+
SE_SINGLE_KEY_ACTION
13+
14+
SE_ACTION
15+
16+
create
17+
make,
18+
make_with_location
19+
20+
feature -- Execute
21+
22+
execute
23+
-- Key press only
24+
do
25+
focus_on_element
26+
keyboard.press_key (keys)
27+
end
28+
end

src/interaction/se_key_up_action.e

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
note
2+
description: "Summary description for {SE_KEY_UP_ACTION}."
3+
author: ""
4+
date: "$Date$"
5+
revision: "$Revision$"
6+
7+
class
8+
SE_KEY_UP_ACTION
9+
10+
inherit
11+
12+
SE_SINGLE_KEY_ACTION
13+
14+
SE_ACTION
15+
16+
create
17+
make,
18+
make_with_location
19+
20+
feature -- Execute
21+
22+
execute
23+
-- Release key
24+
do
25+
focus_on_element
26+
keyboard.release_key (keys)
27+
end
28+
end
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
note
2+
description: "Summary description for {SE_KEYS_RELATED_ACTION}."
3+
author: ""
4+
date: "$Date$"
5+
revision: "$Revision$"
6+
7+
deferred class
8+
SE_KEYS_RELATED_ACTION
9+
10+
inherit
11+
12+
SE_BASE_ACTION
13+
14+
feature -- Access
15+
16+
keyboard: SE_KEYBOARD
17+
18+
mouse: SE_MOUSE
19+
20+
feature -- Change Element
21+
22+
set_keyboard (a_keyboard: SE_KEYBOARD)
23+
-- Set `keyboard' with `a_keyboard'
24+
do
25+
keyboard := a_keyboard
26+
ensure
27+
keyboard_set: keyboard = a_keyboard
28+
end
29+
30+
set_mouse (a_mouse: SE_MOUSE)
31+
-- Set `mouse' with `a_mouse'
32+
do
33+
mouse := a_mouse
34+
ensure
35+
mouse_set: mouse = a_mouse
36+
end
37+
38+
39+
feature {NONE} -- Implementation
40+
41+
focus_on_element
42+
do
43+
if attached location as l_location then
44+
mouse.click (l_location)
45+
end
46+
end
47+
end

src/interaction/se_mouse_action.e

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
note
2+
description: "Summary description for {SE_MOUSE_ACTION}."
3+
author: ""
4+
date: "$Date$"
5+
revision: "$Revision$"
6+
7+
class
8+
SE_MOUSE_ACTION
9+
10+
inherit
11+
12+
SE_BASE_ACTION
13+
14+
create
15+
make,
16+
make_with_location
17+
18+
feature {NONE} --Initialization
19+
20+
make (a_mouse: SE_MOUSE)
21+
-- Create a mouse action with `a_mouse'
22+
do
23+
set_mouse (a_mouse)
24+
ensure
25+
mouse_set: mouse = a_mouse
26+
end
27+
28+
make_with_location (a_mouse: SE_MOUSE; a_coordinate: SE_COORDINATES)
29+
-- Create a mouse action with `a_mouse' and `a_coordinates'
30+
do
31+
set_mouse (a_mouse)
32+
set_location (a_coordinate)
33+
ensure
34+
mouse_set: mouse = a_mouse
35+
location_set: location /= Void implies location = a_coordinate
36+
end
37+
38+
feature -- Access
39+
40+
mouse: SE_MOUSE
41+
42+
feature -- Change Element
43+
44+
set_mouse (a_mouse: SE_MOUSE)
45+
-- Set `mouse' with `a_mouse'
46+
do
47+
mouse := a_mouse
48+
ensure
49+
mouse_set: mouse = a_mouse
50+
end
51+
52+
feature {NONE} -- Implementation
53+
54+
move_to_location
55+
-- Only call mouse_move if actaul location was provided
56+
-- in other case the action will happend in the last know
57+
-- location of the mouse cursor
58+
do
59+
if attached location as l_location then
60+
mouse.mouse_move (l_location)
61+
end
62+
end
63+
64+
end

0 commit comments

Comments
 (0)