def testLoadWithAllSelector(self): """Both elements are loaded with selector='all'.""" action = LoadMediaAction(selector='all', timeout_in_seconds=5) action.WillRunAction(self._tab) action.RunAction(self._tab) self.assertTrue(self.eventFired('#video_1', 'canplaythrough')) self.assertTrue(self.eventFired('#audio_1', 'canplaythrough'))
def testLoadWithSelector(self): """Only the element matching the selector is loaded.""" action = LoadMediaAction(selector='#audio_1', timeout_in_seconds=5) action.WillRunAction(self._tab) action.RunAction(self._tab) self.assertFalse(self.eventFired('#video_1', 'canplaythrough')) self.assertTrue(self.eventFired('#audio_1', 'canplaythrough'))
def testLoadWithNoSelector(self): """With no selector the first media element is loaded.""" action = LoadMediaAction(timeout_in_seconds=5) action.WillRunAction(self._tab) action.RunAction(self._tab) self.assertTrue(self.eventFired('#video_1', 'canplaythrough')) self.assertFalse(self.eventFired('#audio_1', 'canplaythrough'))
def testAwaitedEventIsConfigurable(self): """It's possible to wait for different events.""" action = LoadMediaAction(selector='#video_1', timeout_in_seconds=0.1, event_to_await='loadedmetadata') action.WillRunAction(self._tab) action.RunAction(self._tab) self.assertTrue(self.eventFired('#video_1', 'loadedmetadata'))
def testLoadRaisesAnExceptionOnTimeout(self): """The load action times out if the event does not fire.""" action = LoadMediaAction(selector='#video_1', timeout_in_seconds=0.1, event_to_await='a_nonexistent_event') action.WillRunAction(self._tab) self.assertRaises(py_utils.TimeoutException, action.RunAction, self._tab)
def LoadMedia(self, selector=None, event_timeout_in_seconds=0, event_to_await='canplaythrough'): """Invokes load() on media elements and awaits an event. Args: selector: A CSS selector describing the element. If none is specified, play the first media element on the page. If the selector matches more than 1 media element, all of them will be played. event_timeout_in_seconds: Maximum waiting time for the event to be fired. 0 means do not wait. event_to_await: Which event to await. For example: 'canplaythrough' or 'loadedmetadata'. Raises: TimeoutException: If the maximum waiting time is exceeded. """ self._RunAction(LoadMediaAction( selector=selector, timeout_in_seconds=event_timeout_in_seconds, event_to_await=event_to_await))