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_cue_data ⇒ Array of Hash
Return properties of active text cue of associated media.
-
#active_cue_text ⇒ String
Return cue text of active text track of associated media.
-
#active_track ⇒ Integer
Return index of active text track of associated media.
-
#active_track_cue_count ⇒ Integer
Return number of text cues 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_cues_data ⇒ Array of Hash
Return properties of all cues of active track of associated media.
-
#all_cues_text ⇒ Array of Hash
Return all text cues of active 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.
-
#cue_text(track) ⇒ String
Return text cue of specified text track of associated media.
-
#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_cue_count(track) ⇒ Integer
Return number of text cues of specified text track 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, #draggable?, #enabled?, #exists?, #find_element, #focused?, #get_attribute, #get_locator, #get_locator_type, #get_max, #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_cue_data ⇒ Array of Hash
Return properties of active text cue of associated media
386 387 388 389 390 391 392 393 394 395 396 397 |
# File 'lib/testcentricity_web/web_elements/media.rb', line 386 def active_cue_data active = active_track return nil if active.zero? obj, = find_element(visible = :all) object_not_found_exception(obj, @type) { text: page.execute_script('return arguments[0].textTracks[0].activeCues[0].text', obj), start: page.execute_script('return arguments[0].textTracks[0].activeCues[0].startTime', obj), end: page.execute_script('return arguments[0].textTracks[0].activeCues[0].endTime', obj) } end |
#active_cue_text ⇒ String
Return cue text of active text track of associated media
360 361 362 363 364 365 |
# File 'lib/testcentricity_web/web_elements/media.rb', line 360 def active_cue_text active = active_track return nil if active.zero? cue_text(active) end |
#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_cue_count ⇒ Integer
Return number of text cues of active text track of associated media
334 335 336 337 338 339 |
# File 'lib/testcentricity_web/web_elements/media.rb', line 334 def active_track_cue_count active = active_track return nil if active.zero? track_cue_count(active) 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_cues_data ⇒ Array of Hash
Return properties of all cues of active track of associated media
425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 |
# File 'lib/testcentricity_web/web_elements/media.rb', line 425 def all_cues_data active = active_track return nil if active.zero? obj, = find_element(visible = :all) object_not_found_exception(obj, @type) num_cues = page.execute_script('return arguments[0].textTracks[0].cues.length', obj) all_data = [] (1..num_cues).each do |cue| all_data.push( { cue - 1 => { text: page.execute_script("return arguments[0].textTracks[0].cues[#{cue - 1}].text", obj), start: page.execute_script("return arguments[0].textTracks[0].cues[#{cue - 1}].startTime", obj), end: page.execute_script("return arguments[0].textTracks[0].cues[#{cue - 1}].endTime", obj) } } ) end all_data end |
#all_cues_text ⇒ Array of Hash
Return all text cues of active track of associated media
405 406 407 408 409 410 411 412 413 414 415 416 417 |
# File 'lib/testcentricity_web/web_elements/media.rb', line 405 def all_cues_text active = active_track return nil if active.zero? obj, = find_element(visible = :all) object_not_found_exception(obj, @type) num_cues = page.execute_script('return arguments[0].textTracks[0].cues.length', obj) all_text = [] (1..num_cues).each do |cue| all_text.push( { cue - 1 => page.execute_script("return arguments[0].textTracks[0].cues[#{cue - 1}].text", obj) }) end all_text 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 |
#cue_text(track) ⇒ String
Return text cue of specified text track of associated media
374 375 376 377 378 |
# File 'lib/testcentricity_web/web_elements/media.rb', line 374 def cue_text(track) obj, = find_element(visible = :all) object_not_found_exception(obj, @type) page.execute_script("return arguments[0].textTracks[#{track - 1}].activeCues[0].text", obj) 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(1) end |
#current_time=(value) ⇒ Object
Set the media currentTime property
452 453 454 455 456 |
# File 'lib/testcentricity_web/web_elements/media.rb', line 452 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(1) 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
485 486 487 488 489 |
# File 'lib/testcentricity_web/web_elements/media.rb', line 485 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
474 475 476 477 478 |
# File 'lib/testcentricity_web/web_elements/media.rb', line 474 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
463 464 465 466 467 |
# File 'lib/testcentricity_web/web_elements/media.rb', line 463 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
508 509 510 511 512 |
# File 'lib/testcentricity_web/web_elements/media.rb', line 508 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
532 533 534 535 536 |
# File 'lib/testcentricity_web/web_elements/media.rb', line 532 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_cue_count(track) ⇒ Integer
Return number of text cues of specified text track of associated media
348 349 350 351 352 |
# File 'lib/testcentricity_web/web_elements/media.rb', line 348 def track_cue_count(track) obj, = find_element(visible = :all) object_not_found_exception(obj, @type) page.execute_script("return arguments[0].textTracks[#{track - 1}].cues.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
496 497 498 499 500 |
# File 'lib/testcentricity_web/web_elements/media.rb', line 496 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
520 521 522 523 524 |
# File 'lib/testcentricity_web/web_elements/media.rb', line 520 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? ? .default_max_wait_time : seconds wait = Selenium::WebDriver::Wait.new(timeout: timeout) wait.until do reset_mru_cache compare(value, ready_state) end rescue StandardError if post_exception raise "Ready state of media #{object_ref_message} failed to equal '#{value}' after #{timeout} seconds" unless get_value == value else ready_state == value end end |