Commit dc135e43 by Muhammad Ammar

Video Test Improvements

parent 501a1b59
...@@ -97,6 +97,28 @@ class VideoPage(PageObject): ...@@ -97,6 +97,28 @@ class VideoPage(PageObject):
video_selector = '{0}'.format(CSS_CLASS_NAMES['video_container']) video_selector = '{0}'.format(CSS_CLASS_NAMES['video_container'])
self._wait_for_element(video_selector, 'Video is initialized') self._wait_for_element(video_selector, 'Video is initialized')
def _wait_for_element_visibility(self, element_selector, promise_desc):
"""
Wait for an element to be visible.
Arguments:
element_selector (str): css selector of the element.
promise_desc (str): Description of the Promise, used in log messages.
"""
def _is_element_visible():
"""
Check if a web-element is visible.
Returns:
bool: Tells element visibility status.
"""
return self.q(css=element_selector).visible
EmptyPromise(_is_element_visible, promise_desc, timeout=200).fulfill()
@wait_for_js @wait_for_js
def wait_for_video_player_render(self): def wait_for_video_player_render(self):
""" """
...@@ -107,6 +129,10 @@ class VideoPage(PageObject): ...@@ -107,6 +129,10 @@ class VideoPage(PageObject):
self._wait_for_element(CSS_CLASS_NAMES['video_init'], 'Video Player Initialized') self._wait_for_element(CSS_CLASS_NAMES['video_init'], 'Video Player Initialized')
self._wait_for_element(CSS_CLASS_NAMES['video_time'], 'Video Player Initialized') self._wait_for_element(CSS_CLASS_NAMES['video_time'], 'Video Player Initialized')
video_player_buttons = ['volume', 'play', 'fullscreen', 'speed']
for button in video_player_buttons:
self._wait_for_element_visibility(VIDEO_BUTTONS[button], '{} button is visible'.format(button.title()))
def _is_finished_loading(): def _is_finished_loading():
""" """
Check if video loading completed. Check if video loading completed.
...@@ -381,9 +407,9 @@ class VideoPage(PageObject): ...@@ -381,9 +407,9 @@ class VideoPage(PageObject):
button_selector = self.get_element_selector(video_display_name, VIDEO_BUTTONS[button]) button_selector = self.get_element_selector(video_display_name, VIDEO_BUTTONS[button])
self.q(css=button_selector).first.click() self.q(css=button_selector).first.click()
if button == 'play': button_states = {'play': 'playing', 'pause': 'pause'}
# wait for video buffering if button in button_states:
self._wait_for_video_play(video_display_name) self.wait_for_state(button_states[button], video_display_name)
self.wait_for_ajax() self.wait_for_ajax()
...@@ -691,6 +717,9 @@ class VideoPage(PageObject): ...@@ -691,6 +717,9 @@ class VideoPage(PageObject):
current_seek_position = self.q(css=selector).text[0] current_seek_position = self.q(css=selector).text[0]
return current_seek_position.split('/')[0].strip() return current_seek_position.split('/')[0].strip()
def seconds(self, video_display_name=None):
return int(self.position(video_display_name).split(':')[1])
def state(self, video_display_name=None): def state(self, video_display_name=None):
""" """
Extract the current state (play, pause etc) of video. Extract the current state (play, pause etc) of video.
...@@ -773,6 +802,16 @@ class VideoPage(PageObject): ...@@ -773,6 +802,16 @@ class VideoPage(PageObject):
seek_selector=seek_selector, seek_time=seek_time) seek_selector=seek_selector, seek_time=seek_time)
self.browser.execute_script(js_code) self.browser.execute_script(js_code)
# after seek, player goes into `is-buffered` state. we need to get
# out of this state before doing any further operation/action.
def _is_buffering_completed():
"""
Check if buffering completed
"""
return self.state(video_display_name) != 'buffering'
self._wait_for(_is_buffering_completed, 'Buffering completed after Seek.')
def reload_page(self): def reload_page(self):
""" """
Reload/Refresh the current video page. Reload/Refresh the current video page.
......
...@@ -681,7 +681,7 @@ class YouTubeVideoTest(VideoBaseTest): ...@@ -681,7 +681,7 @@ class YouTubeVideoTest(VideoBaseTest):
self.video.click_player_button('play') self.video.click_player_button('play')
self.video.click_player_button('pause') self.video.click_player_button('pause')
self.assertGreaterEqual(int(self.video.position().split(':')[1]), 5) self.assertGreaterEqual(self.video.seconds(), 5)
@skip("Intermittently fails 03 June 2014") @skip("Intermittently fails 03 June 2014")
def test_video_position_stored_correctly_with_seek(self): def test_video_position_stored_correctly_with_seek(self):
...@@ -701,16 +701,17 @@ class YouTubeVideoTest(VideoBaseTest): ...@@ -701,16 +701,17 @@ class YouTubeVideoTest(VideoBaseTest):
self.navigate_to_video() self.navigate_to_video()
self.video.click_player_button('play') self.video.click_player_button('play')
self.video.click_player_button('pause')
self.video.seek('0:10') self.video.seek('0:10')
self.video.click_player_button('play')
self.video.click_player_button('pause') self.video.click_player_button('pause')
self.video.reload_page() self.video.reload_page()
self.assertGreaterEqual(int(self.video.position().split(':')[1]), 10) self.video.click_player_button('play')
self.video.click_player_button('pause')
self.assertGreaterEqual(self.video.seconds(), 10)
class YouTubeHtml5VideoTest(VideoBaseTest): class YouTubeHtml5VideoTest(VideoBaseTest):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment