class TestCentricity::Media

Public Instance Methods

autoplay?() click to toggle source

Return media autoplay property

@return [Boolean] @example

media_player.autoplay?
# 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?() click to toggle source

Return media controls property

@return [Boolean] @example

media_player.controls?
# 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
crossorigin() click to toggle source

Return media crossorigin property

@return crossorigin value @example

with_creds = media_player.crossorigin == 'use-credentials'
# 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_time() click to toggle source

Return media currentTime property

@return [Float] current playback position in seconds @example

current_player_time = media_player.current_time
# 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) click to toggle source

Set the media currentTime property

@param value [Float] time in seconds @example

media_player.current_time = 1.5
# 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?() click to toggle source

Return media defaultMuted property

@return [Boolean] @example

media_player.default_muted?
# 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_rate() click to toggle source

Return media defaultPlaybackRate property

@return [Integer or Float] default playback speed @example

default_speed = media_player.default_playback_rate
# 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
duration() click to toggle source

Return media duration property

@return [Float] duration of media @example

how_long = media_player.duration
# 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?() click to toggle source

Return media ended property

@return [Boolean] @example

media_player.ended?
# 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?() click to toggle source

Return media loop property

@return [Boolean] @example

media_player.loop?
# 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?() click to toggle source

Return media muted property

@return [Boolean] @example

media_player.muted?
# 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
pause() click to toggle source

Pause the media

@example

media_player.pause
# 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?() click to toggle source

Return media paused property

@return [Boolean] @example

media_player.paused?
# 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
play() click to toggle source

Play the media

@example

media_player.play
# 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_rate() click to toggle source

Return media playbackRate property

@return [Integer or Float] current playback speed @example

playback_speed = media_player.playback_rate
# 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
preload() click to toggle source

Return media preload property

@return preload value @example

preload = media_player.preload
# 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_state() click to toggle source

Return media readyState property

@return [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

@example

media_status = media_player.ready_state
# 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?() click to toggle source

Return media seeking property

@return [Boolean] @example

media_player.seeking?
# 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
src() click to toggle source

Return media src property

@return [String] value of src property @example

src_value = media_player.src
# 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
volume() click to toggle source

Return media volume property

@return [Float] media volume setting @example

volume_level = media_player.volume
# 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) click to toggle source

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.

@param value [Integer] value expected @param seconds [Integer or Float] wait time in seconds @example

media_player.wait_until_ready_state_is(4, 5)
# 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