Class: TestCentricity::Media

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

Direct Known Subclasses

Audio, Video

Constant Summary

Constants inherited from UIElement

UIElement::CSS_SELECTORS, UIElement::XPATH_SELECTORS

Instance Attribute Summary

Attributes inherited from UIElement

#alt_locator, #base_object, #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, #content_editable?, #count, #disabled?, #displayed?, #double_click, #drag_and_drop, #drag_by, #enabled?, #exists?, #find_element, #focused?, #get_attribute, #get_locator, #get_locator_type, #get_name, #get_native_attribute, #get_object_type, #get_value, #height, #hidden?, #highlight, #hover, #hover_at, #initialize, #inspect, #obscured?, #right_click, #role, #scroll_to, #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

This class inherits a constructor from TestCentricity::UIElement

Instance Method Details

#autoplay?Boolean

Return media autoplay property

Examples:

media_player.autoplay?

Returns:

  • (Boolean)


9
10
11
12
13
14
# File 'lib/testcentricity_web/web_elements/media.rb', line 9

def autoplay?
  obj, = find_element(visible = :all)
  object_not_found_exception(obj, @type)
  state = obj.native.attribute('autoplay')
  state.boolean? ? state : state == 'true'
end

#controls?Boolean

Return media controls property

Examples:

media_player.controls?

Returns:

  • (Boolean)


35
36
37
38
39
40
# File 'lib/testcentricity_web/web_elements/media.rb', line 35

def controls?
  obj, = find_element(visible = :all)
  object_not_found_exception(obj, @type)
  state = obj.native.attribute('controls')
  state.boolean? ? state : state == 'true'
end

#crossoriginObject

Return media crossorigin property

Examples:

with_creds = media_player.crossorigin == 'use-credentials'

Returns:

  • crossorigin value



256
257
258
259
260
# File 'lib/testcentricity_web/web_elements/media.rb', line 256

def crossorigin
  obj, = find_element
  object_not_found_exception(obj, @type)
  obj.native.attribute('crossorigin')
end

#current_timeFloat

Return media currentTime property

Examples:

current_player_time = media_player.current_time

Returns:

  • (Float)

    current playback position in seconds



125
126
127
128
129
# File 'lib/testcentricity_web/web_elements/media.rb', line 125

def current_time
  obj, = find_element(visible = :all)
  object_not_found_exception(obj, @type)
  obj.native.attribute('currentTime').to_f
end

#current_time=(value) ⇒ Object

Set the media currentTime property

Examples:

media_player.current_time = 1.5

Parameters:

  • value (Float)

    time in seconds



222
223
224
225
226
# File 'lib/testcentricity_web/web_elements/media.rb', line 222

def current_time=(value)
  obj, = find_element(visible = :all)
  object_not_found_exception(obj, @type)
  page.execute_script('arguments[0].currentTime = arguments[1]', obj, value)
end

#default_muted?Boolean

Return media defaultMuted property

Examples:

media_player.default_muted?

Returns:

  • (Boolean)


74
75
76
77
78
79
# File 'lib/testcentricity_web/web_elements/media.rb', line 74

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

#default_playback_rateInteger or Float

Return media defaultPlaybackRate property

Examples:

default_speed = media_player.default_playback_rate

Returns:

  • (Integer or Float)

    default playback speed



137
138
139
140
141
# File 'lib/testcentricity_web/web_elements/media.rb', line 137

def default_playback_rate
  obj, = find_element(visible = :all)
  object_not_found_exception(obj, @type)
  obj.native.attribute('defaultPlaybackRate')
end

#durationFloat

Return media duration property

Examples:

how_long = media_player.duration

Returns:

  • (Float)

    duration of media



149
150
151
152
153
# File 'lib/testcentricity_web/web_elements/media.rb', line 149

def duration
  obj, = find_element(visible = :all)
  object_not_found_exception(obj, @type)
  obj.native.attribute('duration').to_f
end

#ended?Boolean

Return media ended property

Examples:

media_player.ended?

Returns:

  • (Boolean)


22
23
24
25
26
27
# File 'lib/testcentricity_web/web_elements/media.rb', line 22

def ended?
  obj, = find_element(visible = :all)
  object_not_found_exception(obj, @type)
  state = obj.native.attribute('ended')
  state.boolean? ? state : state == 'true'
end

#loop?Boolean

Return media loop property

Examples:

media_player.loop?

Returns:

  • (Boolean)


48
49
50
51
52
53
# File 'lib/testcentricity_web/web_elements/media.rb', line 48

def loop?
  obj, = find_element(visible = :all)
  object_not_found_exception(obj, @type)
  loop_state = obj.native.attribute('loop')
  loop_state.boolean? ? loop_state : loop_state == 'true'
end

#muted?Boolean

Return media muted property

Examples:

media_player.muted?

Returns:

  • (Boolean)


61
62
63
64
65
66
# File 'lib/testcentricity_web/web_elements/media.rb', line 61

def muted?
  obj, = find_element(visible = :all)
  object_not_found_exception(obj, @type)
  mute_state = obj.native.attribute('muted')
  mute_state.boolean? ? mute_state : mute_state == 'true'
end

#pauseObject

Pause the media

Examples:

media_player.pause


244
245
246
247
248
# File 'lib/testcentricity_web/web_elements/media.rb', line 244

def pause
  obj, = find_element(visible = :all)
  object_not_found_exception(obj, @type)
  page.execute_script('arguments[0].pause()', obj)
end

#paused?Boolean

Return media paused property

Examples:

media_player.paused?

Returns:

  • (Boolean)


87
88
89
90
91
92
# File 'lib/testcentricity_web/web_elements/media.rb', line 87

def paused?
  obj, = find_element(visible = :all)
  object_not_found_exception(obj, @type)
  paused_state = obj.native.attribute('paused')
  paused_state.boolean? ? paused_state : paused_state == 'true'
end

#playObject

Play the media

Examples:

media_player.play


233
234
235
236
237
# File 'lib/testcentricity_web/web_elements/media.rb', line 233

def play
  obj, = find_element(visible = :all)
  object_not_found_exception(obj, @type)
  page.execute_script('arguments[0].play()', obj)
end

#playback_rateInteger or Float

Return media playbackRate property

Examples:

playback_speed = media_player.playback_rate

Returns:

  • (Integer or Float)

    current playback speed



161
162
163
164
165
# File 'lib/testcentricity_web/web_elements/media.rb', line 161

def playback_rate
  obj, = find_element(visible = :all)
  object_not_found_exception(obj, @type)
  obj.native.attribute('playbackRate')
end

#preloadObject

Return media preload property

Examples:

preload = media_player.preload

Returns:

  • preload value



268
269
270
271
272
# File 'lib/testcentricity_web/web_elements/media.rb', line 268

def preload
  obj, = find_element
  object_not_found_exception(obj, @type)
  obj.native.attribute('preload')
end

#ready_stateInteger

Return media readyState property

Examples:

media_status = media_player.ready_state

Returns:

  • (Integer)

    media 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



178
179
180
181
182
# File 'lib/testcentricity_web/web_elements/media.rb', line 178

def ready_state
  obj, = find_element(visible = :all)
  object_not_found_exception(obj, @type)
  obj.native.attribute('readyState').to_i
end

#seeking?Boolean

Return media seeking property

Examples:

media_player.seeking?

Returns:

  • (Boolean)


100
101
102
103
104
105
# File 'lib/testcentricity_web/web_elements/media.rb', line 100

def seeking?
  obj, = find_element(visible = :all)
  object_not_found_exception(obj, @type)
  state = obj.native.attribute('seeking')
  state.boolean? ? state : state == 'true'
end

#srcString

Return media src property

Examples:

src_value = media_player.src

Returns:

  • (String)

    value of src property



113
114
115
116
117
# File 'lib/testcentricity_web/web_elements/media.rb', line 113

def src
  obj, = find_element(visible = :all)
  object_not_found_exception(obj, @type)
  obj.native.attribute('src')
end

#volumeFloat

Return media volume property

Examples:

volume_level = media_player.volume

Returns:

  • (Float)

    media volume setting



210
211
212
213
214
# File 'lib/testcentricity_web/web_elements/media.rb', line 210

def volume
  obj, = find_element(visible = :all)
  object_not_found_exception(obj, @type)
  obj.native.attribute('volume').to_f
end

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

Wait until the media 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:

media_player.wait_until_ready_state_is(4, 5)

Parameters:

  • value (Integer)

    value expected

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

    wait time in seconds



192
193
194
195
196
197
198
199
200
201
202
# File 'lib/testcentricity_web/web_elements/media.rb', line 192

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 Audio #{object_ref_message} failed to equal '#{value}' after #{timeout} seconds" unless get_value == value
  else
    ready_state == value
  end
end