Class: TestCentricity::Video

Inherits:
UIElement show all
Defined in:
lib/testcentricity_web/web_elements/video.rb

Constant Summary

Constants inherited from UIElement

UIElement::CSS_SELECTORS, UIElement::XPATH_SELECTORS

Instance Attribute Summary

Attributes inherited from UIElement

#alt_locator, #context, #locator, #locator_type, #name, #original_style, #parent, #type

Instance Method Summary collapse

Methods inherited from UIElement

#aria_autocomplete, #aria_busy?, #aria_checked?, #aria_colcount, #aria_controls, #aria_describedby, #aria_disabled?, #aria_expanded?, #aria_haspopup?, #aria_hidden?, #aria_invalid?, #aria_keyshortcuts, #aria_label, #aria_labelledby, #aria_live, #aria_modal?, #aria_multiline?, #aria_multiselectable?, #aria_orientation, #aria_pressed?, #aria_readonly?, #aria_required?, #aria_roledescription, #aria_rowcount, #aria_selected?, #aria_sort, #aria_valuemax, #aria_valuemin, #aria_valuenow, #aria_valuetext, #clear_alt_locator, #click, #click_at, #count, #disabled?, #displayed?, #double_click, #drag_and_drop, #drag_by, #enabled?, #exists?, #get_attribute, #get_locator, #get_locator_type, #get_name, #get_native_attribute, #get_object_type, #get_siebel_object_type, #get_value, #height, #hidden?, #highlight, #hover, #hover_at, #inspect, #invoke_siebel_dialog, #obscured?, #right_click, #role, #send_keys, #set, #set_alt_locator, #set_locator_type, #style, #tabindex, #title, #unhighlight, #verify_value, #visible?, #wait_until_exists, #wait_until_gone, #wait_until_hidden, #wait_until_value_changes, #wait_until_value_is, #wait_until_visible, #width, #x, #y

Constructor Details

#initialize(name, parent, locator, context) ⇒ Video

Returns a new instance of Video.



3
4
5
6
# File 'lib/testcentricity_web/web_elements/video.rb', line 3

def initialize(name, parent, locator, context)
  super
  @type = :video
end

Instance Method Details

#autoplay?Boolean

Return video autoplay property

Examples:

video_player.autoplay?

Returns:

  • (Boolean)


14
15
16
17
18
19
# File 'lib/testcentricity_web/web_elements/video.rb', line 14

def autoplay?
  obj, = find_element
  object_not_found_exception(obj, nil)
  state = obj.native.attribute('autoplay')
  state.boolean? ? state : state == 'true'
end

#controls?Boolean

Return video controls property

Examples:

video_player.controls?

Returns:

  • (Boolean)


40
41
42
43
44
45
# File 'lib/testcentricity_web/web_elements/video.rb', line 40

def controls?
  obj, = find_element
  object_not_found_exception(obj, nil)
  state = obj.native.attribute('controls')
  state.boolean? ? state : state == 'true'
end

#current_timeFloat

Return video currentTime property

Examples:

current_player_time = video_player.current_time

Returns:

  • (Float)

    current playback position in seconds



130
131
132
133
134
# File 'lib/testcentricity_web/web_elements/video.rb', line 130

def current_time
  obj, = find_element
  object_not_found_exception(obj, nil)
  obj.native.attribute('currentTime').to_f
end

#current_time=(value) ⇒ Object

Set the video currentTime property

Examples:

video_player.current_time = 1.5

Parameters:

  • value (Float)

    time in seconds



251
252
253
254
255
# File 'lib/testcentricity_web/web_elements/video.rb', line 251

def current_time=(value)
  obj, = find_element
  object_not_found_exception(obj, nil)
  page.execute_script('arguments[0].currentTime = arguments[1]', obj, value)
end

#default_muted?Boolean

Return video defaultMuted property

Examples:

video_player.default_muted?

Returns:

  • (Boolean)


79
80
81
82
83
84
# File 'lib/testcentricity_web/web_elements/video.rb', line 79

def default_muted?
  obj, = find_element
  object_not_found_exception(obj, nil)
  mute_state = obj.native.attribute('defaultMuted')
  mute_state.boolean? ? mute_state : mute_state == 'true'
end

#default_playback_rateInteger or Float

Return video defaultPlaybackRate property

Examples:

default_speed = video_player.default_playback_rate

Returns:

  • (Integer or Float)

    default playback speed



142
143
144
145
146
# File 'lib/testcentricity_web/web_elements/video.rb', line 142

def default_playback_rate
  obj, = find_element
  object_not_found_exception(obj, nil)
  obj.native.attribute('defaultPlaybackRate')
end

#durationFloat

Return video duration property

Examples:

how_long = video_player.duration

Returns:

  • (Float)

    duration of video



154
155
156
157
158
# File 'lib/testcentricity_web/web_elements/video.rb', line 154

def duration
  obj, = find_element
  object_not_found_exception(obj, nil)
  obj.native.attribute('duration').to_f
end

#ended?Boolean

Return video ended property

Examples:

video_player.ended?

Returns:

  • (Boolean)


27
28
29
30
31
32
# File 'lib/testcentricity_web/web_elements/video.rb', line 27

def ended?
  obj, = find_element
  object_not_found_exception(obj, nil)
  state = obj.native.attribute('ended')
  state.boolean? ? state : state == 'true'
end

#loop?Boolean

Return video loop property

Examples:

video_player.loop?

Returns:

  • (Boolean)


53
54
55
56
57
58
# File 'lib/testcentricity_web/web_elements/video.rb', line 53

def loop?
  obj, = find_element
  object_not_found_exception(obj, nil)
  loop_state = obj.native.attribute('loop')
  loop_state.boolean? ? loop_state : loop_state == 'true'
end

#muted?Boolean

Return video muted property

Examples:

video_player.muted?

Returns:

  • (Boolean)


66
67
68
69
70
71
# File 'lib/testcentricity_web/web_elements/video.rb', line 66

def muted?
  obj, = find_element
  object_not_found_exception(obj, nil)
  mute_state = obj.native.attribute('muted')
  mute_state.boolean? ? mute_state : mute_state == 'true'
end

#pauseObject

Pause the video

Examples:

video_player.pause


273
274
275
276
277
# File 'lib/testcentricity_web/web_elements/video.rb', line 273

def pause
  obj, = find_element
  object_not_found_exception(obj, nil)
  page.execute_script('arguments[0].pause()', obj)
end

#paused?Boolean

Return video paused property

Examples:

video_player.paused?

Returns:

  • (Boolean)


92
93
94
95
96
97
# File 'lib/testcentricity_web/web_elements/video.rb', line 92

def paused?
  obj, = find_element
  object_not_found_exception(obj, nil)
  paused_state = obj.native.attribute('paused')
  paused_state.boolean? ? paused_state : paused_state == 'true'
end

#playObject

Play the video

Examples:

video_player.play


262
263
264
265
266
# File 'lib/testcentricity_web/web_elements/video.rb', line 262

def play
  obj, = find_element
  object_not_found_exception(obj, nil)
  page.execute_script('arguments[0].play()', obj)
end

#playback_rateInteger or Float

Return video playbackRate property

Examples:

playback_speed = video_player.playback_rate

Returns:

  • (Integer or Float)

    current playback speed



166
167
168
169
170
# File 'lib/testcentricity_web/web_elements/video.rb', line 166

def playback_rate
  obj, = find_element
  object_not_found_exception(obj, nil)
  obj.native.attribute('playbackRate')
end

#ready_stateInteger

Return video readyState property

Examples:

vid_status = video_player.ready_state

Returns:

  • (Integer)

    video ready state 0 = HAVE_NOTHING - no information whether or not the audio/video is ready 1 = HAVE_METADATA - metadata for the audio/video is ready 2 = HAVE_CURRENT_DATA - data for the current playback position is available, but not enough data to play next frame/millisecond 3 = HAVE_FUTURE_DATA - data for the current and at least the next frame is available 4 = HAVE_ENOUGH_DATA - enough data available to start playing



183
184
185
186
187
# File 'lib/testcentricity_web/web_elements/video.rb', line 183

def ready_state
  obj, = find_element
  object_not_found_exception(obj, nil)
  obj.native.attribute('readyState').to_i
end

#seeking?Boolean

Return video seeking property

Examples:

video_player.seeking?

Returns:

  • (Boolean)


105
106
107
108
109
110
# File 'lib/testcentricity_web/web_elements/video.rb', line 105

def seeking?
  obj, = find_element
  object_not_found_exception(obj, nil)
  state = obj.native.attribute('seeking')
  state.boolean? ? state : state == 'true'
end

#srcString

Return video src property

Examples:

src_value = video_player.src

Returns:

  • (String)

    value of src property



118
119
120
121
122
# File 'lib/testcentricity_web/web_elements/video.rb', line 118

def src
  obj, = find_element
  object_not_found_exception(obj, nil)
  obj.native.attribute('src')
end

#video_heightInteger

Return video Height property

Examples:

height = video_player.video_height

Returns:

  • (Integer)

    video height



227
228
229
230
231
# File 'lib/testcentricity_web/web_elements/video.rb', line 227

def video_height
  obj, = find_element
  object_not_found_exception(obj, nil)
  obj.native.attribute('videoHeight')
end

#video_widthInteger

Return video Width property

Examples:

width = video_player.video_width

Returns:

  • (Integer)

    video width



239
240
241
242
243
# File 'lib/testcentricity_web/web_elements/video.rb', line 239

def video_width
  obj, = find_element
  object_not_found_exception(obj, nil)
  obj.native.attribute('videoWidth')
end

#volumeInteger or Float

Return video volume property

Examples:

volume_level = video_player.volume

Returns:

  • (Integer or Float)

    video volume setting



215
216
217
218
219
# File 'lib/testcentricity_web/web_elements/video.rb', line 215

def volume
  obj, = find_element
  object_not_found_exception(obj, nil)
  obj.native.attribute('volume')
end

#wait_until_ready_state_is(value, seconds = nil, post_exception = true) ⇒ Object

Wait until the video object's readyState value equals the specified value, or until the specified wait time has expired. If the wait time is nil, then the wait time will be Capybara.default_max_wait_time.

Examples:

video_player.wait_until_ready_state_is(4, 5)

Parameters:

  • value (Integer)

    value expected

  • seconds (Integer or Float) (defaults to: nil)

    wait time in seconds



197
198
199
200
201
202
203
204
205
206
207
# File 'lib/testcentricity_web/web_elements/video.rb', line 197

def wait_until_ready_state_is(value, seconds = nil, post_exception = true)
  timeout = seconds.nil? ? Capybara.default_max_wait_time : seconds
  wait = Selenium::WebDriver::Wait.new(timeout: timeout)
  wait.until { ready_state == value }
rescue StandardError
  if post_exception
    raise "Ready state of Video #{object_ref_message} failed to equal '#{value}' after #{timeout} seconds" unless get_value == value
  else
    ready_state == value
  end
end