Module: Lebowski::Foundation::Mixins::UserActions

Includes:
KeyCheck, PositionedElement, StallSupport
Included in:
DOMElement, Views::View
Defined in:
lib/lebowski/foundation/mixins/user_actions.rb

Overview

Mixin containing a set of commonly performed user actions. Mix this into any class that is able to perform these set of actions.

Constant Summary

Constant Summary

Constants included from StallSupport

StallSupport::DEFAULT_KEY_STALLS, StallSupport::DEFAULT_STALL

Instance Method Summary (collapse)

Methods included from StallSupport

adjust_all_stalls, adjust_default_key_stall, adjust_default_stall, reset, #stall

Methods included from KeyCheck

#key_down?, #key_up?

Methods included from PositionedElement

#height, #position, #position_relative_to, #scroll_to_visible, #width

Instance Method Details

- (Object) basic_click

Used to perform a single basic click on this view in the remote application



125
126
127
128
129
# File 'lib/lebowski/foundation/mixins/user_actions.rb', line 125

def basic_click()
  scroll_to_visible
  @driver.sc_basic_click action_target, *action_locator_args
  stall :click
end

- (Object) click

Used to perform a single click on this view in the remote application



107
108
109
110
111
# File 'lib/lebowski/foundation/mixins/user_actions.rb', line 107

def click()
  mouse_down
  mouse_up
  stall :click
end

- (Object) click_at(x, y)



46
47
48
49
50
# File 'lib/lebowski/foundation/mixins/user_actions.rb', line 46

def click_at(x, y)
  mouse_down_at x, y
  mouse_up_at x, y
  stall :click
end

- (Object) double_click

Used to perform a double click on this view in the remote application



100
101
102
# File 'lib/lebowski/foundation/mixins/user_actions.rb', line 100

def double_click()
  double_click_at :center, :center
end

- (Object) double_click_at(x, y)



52
53
54
55
56
# File 'lib/lebowski/foundation/mixins/user_actions.rb', line 52

def double_click_at(x, y)
  scroll_to_visible
  @driver.sc_double_click_at action_target, x, y, *action_locator_args
  stall :double_click
end

- (Object) drag(x, y, *params)



214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
# File 'lib/lebowski/foundation/mixins/user_actions.rb', line 214

def drag(x, y, *params)
  if (not x.kind_of? Integer) or (not y.kind_of? Integer)
    raise ArgumentError.new "Must supply valid x-y coordinates: x = #{x}, y = #{y}" 
  end
  
  relative_to = nil
  mouse_offset_x = 0
  mouse_offset_y = 0
  
  if params.length > 0 and params[0].kind_of?(Hash)
    relative_to = params[0][:relative_to]
    mouse_offset_x = get_mouse_offset(params[0][:mouse_offset_x], :x)
    mouse_offset_y = get_mouse_offset(params[0][:mouse_offset_y], :y)
  end
  
  # First be sure to disable autoscrolling in the application. This needs
  # to be done so that autoscrolling will not interfere with our drag
  # and drop user action
  @driver.sc_disable_all_autoscrolling
  
  mouse_down_at mouse_offset_x, mouse_offset_y
  mouse_move_at mouse_offset_x, mouse_offset_y
            
  # Make sure the element we are dragging relative to is visible
  relative_to.scroll_to_visible if relative_to.kind_of? PositionedElement
  
  rel_pos = relative_position(x, y, relative_to)
  mouse_move_at rel_pos.x, rel_pos.y
  
  rel_pos = relative_position(x, y, relative_to)
  mouse_up_at rel_pos.x, rel_pos.y
  
  # Enable autoscrolling and mouse move events since we have completed the 
  # drag and drop operation
  @driver.sc_enable_all_autoscrolling
  @driver.sc_enable_mouse_move_event
  
  stall :drag 
end

- (Object) drag_after(item)



281
282
283
284
285
# File 'lib/lebowski/foundation/mixins/user_actions.rb', line 281

def drag_after(item)
  assert_item_has_collection_item_view_support(item, 'item')
  return if not item.can_drag_after?
  item.apply_drag_after self
end

- (Object) drag_before(item)



275
276
277
278
279
# File 'lib/lebowski/foundation/mixins/user_actions.rb', line 275

def drag_before(item)
  assert_item_has_collection_item_view_support(item, 'item')
  return if not item.can_drag_before?
  item.apply_drag_before self
end

- (Object) drag_on_to(source)



271
272
273
# File 'lib/lebowski/foundation/mixins/user_actions.rb', line 271

def drag_on_to(source)
  drag_to source, 1, 1
end

- (Object) drag_to(source, offset_x = nil, offset_y = nil, *params)



254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/lebowski/foundation/mixins/user_actions.rb', line 254

def drag_to(source, offset_x=nil, offset_y=nil, *params)
  if not (source.kind_of? PositionedElement or source == :window)
    raise ArgumentError.new "source must be an positioned element: #{source.class}"
  end
  
  offset_x = offset_x.nil? ? 0 : offset_x
  offset_y = offset_y.nil? ? 0 : offset_y
  
  params2 = { :relative_to => source }
  if params.length > 0 and params[0].kind_of? Hash
    params2[:mouse_offset_x] = params[0][:mouse_offset_x]
    params2[:mouse_offset_y] = params[0][:mouse_offset_y]
  end
  
  drag offset_x, offset_y, params2
end

- (Object) drag_to_end_of(view)



293
294
295
296
297
# File 'lib/lebowski/foundation/mixins/user_actions.rb', line 293

def drag_to_end_of(view)
  assert_is_collection_view(view, 'view');
  return if not view.can_drag_to_end_of?
  view.apply_drag_to_end_of self
end

- (Object) drag_to_start_of(view)



287
288
289
290
291
# File 'lib/lebowski/foundation/mixins/user_actions.rb', line 287

def drag_to_start_of(view)
  assert_is_collection_view(view, 'view');
  return if not view.can_drag_to_start_of?
  view.apply_drag_to_start_of self
end

- (Object) focus



210
211
212
# File 'lib/lebowski/foundation/mixins/user_actions.rb', line 210

def focus()
  @driver.sc_focus action_target, *action_locator_args
end

- (Object) key_down(key)

Used to perform a key down on this view in the remote application

You can either type a printable character or a function key. If you want to type a printable character then the 'key' parameter just has to be a string, such as 'a'. If you want to type a function key such as F1, then the 'key' parameter must be the corresponding symbol.

Example:

view.key_down 'a'       # key down for printable character 'a'
view.key_down :delete   # key down for function key delete
view.key_down :meta_key # key down for the meta key


160
161
162
163
164
# File 'lib/lebowski/foundation/mixins/user_actions.rb', line 160

def key_down(key)
  focus
  @driver.sc_key_down action_target, key, *action_locator_args
  stall :key_down
end

- (Object) key_up(key)

Used to perform a key up on this view in the remote application

You can either type a printable character or a function key. If you want to type a printable character then the 'key' parameter just has to be a string, such as 'a'. If you want to type a function key such as F1, then the 'key' parameter must be the corresponding symbol.

Example:

view.key_up 'a'       # key up for printable character 'a'
view.key_up :delete   # key up for function key delete
view.key_up :meta_key # key up for the meta key


179
180
181
182
183
# File 'lib/lebowski/foundation/mixins/user_actions.rb', line 179

def key_up(key)
  focus
  @driver.sc_key_up action_target, key, *action_locator_args
  stall :key_up
end

- (Object) mouse_down

Used to perform a mouse down on this view in the remote application



72
73
74
# File 'lib/lebowski/foundation/mixins/user_actions.rb', line 72

def mouse_down()
  mouse_down_at :center, :center
end

- (Object) mouse_down_at(x, y)



29
30
31
32
33
# File 'lib/lebowski/foundation/mixins/user_actions.rb', line 29

def mouse_down_at(x, y)
  scroll_to_visible
  @driver.sc_mouse_down_at action_target, x, y, *action_locator_args
  stall :mouse_down
end

- (Object) mouse_move



64
65
66
67
# File 'lib/lebowski/foundation/mixins/user_actions.rb', line 64

def mouse_move()
  @driver.sc_mouse_move action_target, *action_locator_args
  stall :mouse_move
end

- (Object) mouse_move_at(x, y)



19
20
21
22
# File 'lib/lebowski/foundation/mixins/user_actions.rb', line 19

def mouse_move_at(x, y)
  @driver.sc_mouse_move_at action_target, x, y, *action_locator_args
  stall :mouse_move          
end

- (Object) mouse_up

Used to perform a mouse up on this view in the remote application



79
80
81
# File 'lib/lebowski/foundation/mixins/user_actions.rb', line 79

def mouse_up()
  mouse_up_at :center, :center
end

- (Object) mouse_up_at(x, y)



24
25
26
27
# File 'lib/lebowski/foundation/mixins/user_actions.rb', line 24

def mouse_up_at(x, y)
  @driver.sc_mouse_up_at action_target, x, y, *action_locator_args
  stall :mouse_up
end

- (Object) mouse_wheel_delta_x(delta)

Used to perform a mouse wheel action on the x-axis



134
135
136
137
# File 'lib/lebowski/foundation/mixins/user_actions.rb', line 134

def mouse_wheel_delta_x(delta)
  @driver.sc_mouse_wheel_delta_x action_target, delta, *action_locator_args
  stall :mouse_wheel
end

- (Object) mouse_wheel_delta_y(delta)

Used to perform a mouse wheel action on the y-axis



142
143
144
145
# File 'lib/lebowski/foundation/mixins/user_actions.rb', line 142

def mouse_wheel_delta_y(delta)
  @driver.sc_mouse_wheel_delta_y action_target, delta, *action_locator_args
  stall :mouse_wheel
end

- (Object) right_click

Used to perform a single right click on this view in the remote application



116
117
118
119
120
# File 'lib/lebowski/foundation/mixins/user_actions.rb', line 116

def right_click()
  right_mouse_down
  right_mouse_up
  stall :right_click
end

- (Object) right_click_at(x, y)



58
59
60
61
62
# File 'lib/lebowski/foundation/mixins/user_actions.rb', line 58

def right_click_at(x, y)
  right_mouse_down_at x, y
  right_mouse_up_at x, y
  stall :right_click
end

- (Object) right_mouse_down

Used to perform a mouse down with right button on this view in the remote application



86
87
88
# File 'lib/lebowski/foundation/mixins/user_actions.rb', line 86

def right_mouse_down()
  right_mouse_down_at :center, :center
end

- (Object) right_mouse_down_at(x, y)



35
36
37
38
39
# File 'lib/lebowski/foundation/mixins/user_actions.rb', line 35

def right_mouse_down_at(x, y)
  scroll_to_visible
  @driver.sc_right_mouse_down_at action_target, x, y, *action_locator_args
  stall :right_mouse_down
end

- (Object) right_mouse_up

Used to perform a mouse up with right button on this view in the remote application



93
94
95
# File 'lib/lebowski/foundation/mixins/user_actions.rb', line 93

def right_mouse_up()
  right_mouse_up_at :center, :center
end

- (Object) right_mouse_up_at(x, y)



41
42
43
44
# File 'lib/lebowski/foundation/mixins/user_actions.rb', line 41

def right_mouse_up_at(x, y)
  @driver.sc_right_mouse_up_at action_target, x, y, *action_locator_args
  stall :right_mouse_up
end

- (Object) type(text)



204
205
206
207
208
# File 'lib/lebowski/foundation/mixins/user_actions.rb', line 204

def type(text)
  focus
  @driver.sc_type action_target, text, *action_locator_args
  stall :type_key
end

- (Object) type_key(key)

Used to type a key on this view in the remote application. This will cause a key down followed by a key up

You can either type a printable character or a function key. If you want to type a printable character then the 'key' parameter just has to be a string, such as 'a'. If you want to type a function key such as F1, then the 'key' parameter must be the corresponding symbol.

Example:

view.type_key 'a'      # type printable character 'a'
view.type_key :delete  # type function key delete


198
199
200
201
202
# File 'lib/lebowski/foundation/mixins/user_actions.rb', line 198

def type_key(key)
  focus
  @driver.sc_type_key action_target, key, *action_locator_args
  stall :type_key
end