Class: TestCentricity::Elements::Media
- Defined in:
- lib/testcentricity_web/web_elements/media.rb
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, #mru_driver, #mru_locator, #mru_object, #mru_parent, #name, #original_style, #parent, #type
Instance Method Summary collapse
-
#active_track ⇒ Integer
Return index of active text track of associated media.
-
#active_track_data ⇒ Hash
Return properties of active text track of associated media.
-
#active_track_source ⇒ String
Return src property of active text track of associated media.
-
#all_tracks_data ⇒ Array of Hash
Return properties of all text tracks of associated media.
-
#autoplay? ⇒ Boolean
Return media autoplay property.
-
#controls? ⇒ Boolean
Return media controls property.
-
#current_time ⇒ Float
Return media currentTime property.
-
#current_time=(value) ⇒ Object
Set the media currentTime property.
-
#default_muted? ⇒ Boolean
Return media defaultMuted property.
-
#default_playback_rate ⇒ Integer or Float
Return media defaultPlaybackRate property.
-
#duration ⇒ Float
Return media duration property.
-
#ended? ⇒ Boolean
Return media ended property.
-
#loop? ⇒ Boolean
Return media loop property.
-
#mute ⇒ Object
Mute the media's audio.
-
#muted? ⇒ Boolean
Return media muted property.
-
#pause ⇒ Object
Pause the media.
-
#paused? ⇒ Boolean
Return media paused property.
-
#play ⇒ Object
Play the media.
-
#playback_rate ⇒ Integer or Float
Return media playbackRate property.
-
#playback_rate=(value) ⇒ Object
Set the media playbackRate property.
-
#preload ⇒ Object
Return media preload property.
-
#ready_state ⇒ Integer
Return media readyState property.
-
#seeking? ⇒ Boolean
Return media seeking property.
-
#src ⇒ String
Return media src property.
-
#track_count ⇒ Integer
Return number of text tracks of associated media.
-
#track_data(track) ⇒ Hash
Return properties of specified text track of associated media.
-
#track_source(track) ⇒ String
Return srv property of specified text track of associated media.
-
#unmute ⇒ Object
Unmute the media's audio.
-
#volume ⇒ Float
Return media volume property.
-
#volume=(value) ⇒ Object
Set the media volume property.
-
#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.
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, #crossorigin, #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, #obscured?, #required?, #reset_mru_cache, #right_click, #role, #scroll_to, #send_keys, #set, #set_alt_locator, #set_locator_type, #style, #tabindex, #title, #unhighlight, #verify_value, #visible?, #wait_until_enabled, #wait_until_exists, #wait_until_gone, #wait_until_hidden, #wait_until_value_changes, #wait_until_value_is, #wait_until_visible, #wait_while_busy, #width, #x, #y
Constructor Details
This class inherits a constructor from TestCentricity::Elements::UIElement
Instance Method Details
#active_track ⇒ Integer
Return index of active text track of associated media
238 239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/testcentricity_web/web_elements/media.rb', line 238 def active_track num_tracks = track_count return 0 if num_tracks.zero? obj, = find_element(visible = :all) object_not_found_exception(obj, @type) (0..num_tracks).each do |track| track_info = page.execute_script("return arguments[0].textTracks[#{track}].mode", obj) return track + 1 if track_info == 'showing' end 0 end |
#active_track_data ⇒ Hash
Return properties of active text track of associated media
257 258 259 260 261 262 |
# File 'lib/testcentricity_web/web_elements/media.rb', line 257 def active_track_data active = active_track return nil if active.zero? track_data(active) end |
#active_track_source ⇒ String
Return src property of active text track of associated media
307 308 309 310 311 312 |
# File 'lib/testcentricity_web/web_elements/media.rb', line 307 def active_track_source active = active_track return nil if active.zero? track_source(active) end |
#all_tracks_data ⇒ Array of Hash
Return properties of all text tracks of associated media
270 271 272 273 274 275 276 277 278 279 |
# File 'lib/testcentricity_web/web_elements/media.rb', line 270 def all_tracks_data num_tracks = track_count return 0 if num_tracks.zero? all_data = [] (1..num_tracks).each do |track| all_data.push( { track => track_data(track) }) end all_data end |
#autoplay? ⇒ Boolean
Return media autoplay property
10 11 12 13 14 15 |
# File 'lib/testcentricity_web/web_elements/media.rb', line 10 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
36 37 38 39 40 41 |
# File 'lib/testcentricity_web/web_elements/media.rb', line 36 def controls? obj, = find_element(visible = :all) object_not_found_exception(obj, @type) state = obj.native.attribute('controls') state.boolean? ? state : state == 'true' end |
#current_time ⇒ Float
Return media currentTime property
126 127 128 129 130 |
# File 'lib/testcentricity_web/web_elements/media.rb', line 126 def current_time obj, = find_element(visible = :all) object_not_found_exception(obj, @type) obj.native.attribute('currentTime').to_f.round(2) end |
#current_time=(value) ⇒ Object
Set the media currentTime property
334 335 336 337 338 |
# File 'lib/testcentricity_web/web_elements/media.rb', line 334 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
75 76 77 78 79 80 |
# File 'lib/testcentricity_web/web_elements/media.rb', line 75 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 ⇒ Integer or Float
Return media defaultPlaybackRate property
138 139 140 141 142 |
# File 'lib/testcentricity_web/web_elements/media.rb', line 138 def default_playback_rate obj, = find_element(visible = :all) object_not_found_exception(obj, @type) obj.native.attribute('defaultPlaybackRate').to_f end |
#duration ⇒ Float
Return media duration property
150 151 152 153 154 |
# File 'lib/testcentricity_web/web_elements/media.rb', line 150 def duration obj, = find_element(visible = :all) object_not_found_exception(obj, @type) obj.native.attribute('duration').to_f.round(2) end |
#ended? ⇒ Boolean
Return media ended property
23 24 25 26 27 28 |
# File 'lib/testcentricity_web/web_elements/media.rb', line 23 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
49 50 51 52 53 54 |
# File 'lib/testcentricity_web/web_elements/media.rb', line 49 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 |
#mute ⇒ Object
Mute the media's audio
367 368 369 370 371 |
# File 'lib/testcentricity_web/web_elements/media.rb', line 367 def mute obj, = find_element(visible = :all) object_not_found_exception(obj, @type) page.execute_script('arguments[0].muted = true;', obj) end |
#muted? ⇒ Boolean
Return media muted property
62 63 64 65 66 67 |
# File 'lib/testcentricity_web/web_elements/media.rb', line 62 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 ⇒ Object
Pause the media
356 357 358 359 360 |
# File 'lib/testcentricity_web/web_elements/media.rb', line 356 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
88 89 90 91 92 93 |
# File 'lib/testcentricity_web/web_elements/media.rb', line 88 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 ⇒ Object
Play the media
345 346 347 348 349 |
# File 'lib/testcentricity_web/web_elements/media.rb', line 345 def play obj, = find_element(visible = :all) object_not_found_exception(obj, @type) page.execute_script('arguments[0].play()', obj) end |
#playback_rate ⇒ Integer or Float
Return media playbackRate property
162 163 164 165 166 |
# File 'lib/testcentricity_web/web_elements/media.rb', line 162 def playback_rate obj, = find_element(visible = :all) object_not_found_exception(obj, @type) obj.native.attribute('playbackRate').to_f end |
#playback_rate=(value) ⇒ Object
Set the media playbackRate property
390 391 392 393 394 |
# File 'lib/testcentricity_web/web_elements/media.rb', line 390 def playback_rate=(value) obj, = find_element(visible = :all) object_not_found_exception(obj, @type) page.execute_script('arguments[0].playbackRate = arguments[1]', obj, value) end |
#preload ⇒ Object
Return media preload property
414 415 416 417 418 |
# File 'lib/testcentricity_web/web_elements/media.rb', line 414 def preload obj, = find_element object_not_found_exception(obj, @type) obj.native.attribute('preload') end |
#ready_state ⇒ Integer
Return media readyState property
179 180 181 182 183 |
# File 'lib/testcentricity_web/web_elements/media.rb', line 179 def ready_state obj, = find_element(visible = :all) object_not_found_exception(obj, @type) page.execute_script('return arguments[0].readyState', obj) end |
#seeking? ⇒ Boolean
Return media seeking property
101 102 103 104 105 106 |
# File 'lib/testcentricity_web/web_elements/media.rb', line 101 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 ⇒ String
Return media src property
114 115 116 117 118 |
# File 'lib/testcentricity_web/web_elements/media.rb', line 114 def src obj, = find_element(visible = :all) object_not_found_exception(obj, @type) obj.native.attribute('src') end |
#track_count ⇒ Integer
Return number of text tracks of associated media
226 227 228 229 230 |
# File 'lib/testcentricity_web/web_elements/media.rb', line 226 def track_count obj, = find_element(visible = :all) object_not_found_exception(obj, @type) page.execute_script('return arguments[0].textTracks.length', obj) end |
#track_data(track) ⇒ Hash
Return properties of specified text track of associated media
288 289 290 291 292 293 294 295 296 297 298 299 |
# File 'lib/testcentricity_web/web_elements/media.rb', line 288 def track_data(track) obj, = find_element(visible = :all) object_not_found_exception(obj, @type) track_mode = page.execute_script("return arguments[0].textTracks[#{track - 1}].mode", obj) track_obj = obj.find(:css, "track:nth-of-type(#{track})", visible: :all, wait: 1) { kind: track_obj[:kind], label: track_obj[:label], language: track_obj[:srclang], mode: track_mode } end |
#track_source(track) ⇒ String
Return srv property of specified text track of associated media
321 322 323 324 325 326 |
# File 'lib/testcentricity_web/web_elements/media.rb', line 321 def track_source(track) obj, = find_element(visible = :all) object_not_found_exception(obj, @type) track_obj = obj.find(:css, "track:nth-of-type(#{track})", visible: :all, wait: 1) track_obj[:src] end |
#unmute ⇒ Object
Unmute the media's audio
378 379 380 381 382 |
# File 'lib/testcentricity_web/web_elements/media.rb', line 378 def unmute obj, = find_element(visible = :all) object_not_found_exception(obj, @type) page.execute_script('arguments[0].muted = false;', obj) end |
#volume ⇒ Float
Return media volume property
214 215 216 217 218 |
# File 'lib/testcentricity_web/web_elements/media.rb', line 214 def volume obj, = find_element(visible = :all) object_not_found_exception(obj, @type) obj.native.attribute('volume').to_f end |
#volume=(value) ⇒ Object
Set the media volume property
402 403 404 405 406 |
# File 'lib/testcentricity_web/web_elements/media.rb', line 402 def volume=(value) obj, = find_element(visible = :all) object_not_found_exception(obj, @type) page.execute_script('arguments[0].volume = arguments[1]', obj, value) 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.
193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/testcentricity_web/web_elements/media.rb', line 193 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 do reset_mru_cache ready_state == value end rescue StandardError if post_exception raise "Ready state of media #{} failed to equal '#{value}' after #{timeout} seconds" unless get_value == value else ready_state == value end end |