Bug 1370863 - Stop using Marionette.log API in external media tests; r=automatedtester,SingingTree draft
authorAndreas Tolfsen <ato@sny.no>
Fri, 09 Jun 2017 14:29:49 +0100
changeset 598399 3ae2bb18bda02a9dcdea2caf3eb04a66f5ea72f3
parent 598398 02b1ab7cd3ddecd7fc490433d6c37beb145e7cfd
child 598400 17d6516916790ce69b86961ca809a8b7116dfa61
push id65195
push userbmo:ato@sny.no
push dateWed, 21 Jun 2017 18:07:04 +0000
reviewersautomatedtester, SingingTree
bugs1370863
milestone56.0a1
Bug 1370863 - Stop using Marionette.log API in external media tests; r=automatedtester,SingingTree This removes the dependency on the Marionette server-side logging API from the external media tests. Instead, we rely on client-side logging alternatives. MozReview-Commit-ID: 8kMhMflYh4q
dom/media/test/external/external_media_harness/testcase.py
dom/media/test/external/external_media_tests/media_utils/video_puppeteer.py
dom/media/test/external/external_media_tests/media_utils/youtube_puppeteer.py
dom/media/test/external/external_media_tests/playback/youtube/test_basic_playback.py
--- a/dom/media/test/external/external_media_harness/testcase.py
+++ b/dom/media/test/external/external_media_harness/testcase.py
@@ -47,27 +47,26 @@ class MediaTestCase(PuppeteerMixin, Mari
                             '.png'])
         path = os.path.join(screenshot_dir, filename)
         if not os.path.exists(screenshot_dir):
             os.makedirs(screenshot_dir)
         with self.marionette.using_context(Marionette.CONTEXT_CONTENT):
             img_data = self.marionette.screenshot()
         with open(path, 'wb') as f:
             f.write(img_data.decode('base64'))
-        self.marionette.log('Screenshot saved in {}'
-                            .format(os.path.abspath(path)))
+        self.logger.info('Screenshot saved in {}'.format(os.path.abspath(path)))
 
     def log_video_debug_lines(self, video):
         """
         Log the debugging information that Firefox provides for video elements.
         """
         with self.marionette.using_context(Marionette.CONTEXT_CHROME):
             debug_lines = video.get_debug_lines()
             if debug_lines:
-                self.marionette.log('\n'.join(debug_lines))
+                self.logger.info('\n'.join(debug_lines))
 
     def run_playback(self, video):
         """
         Play the video all of the way through, or for the requested duration,
         whichever comes first. Raises if the video stalls for too long.
 
         :param video: VideoPuppeteer instance to play.
         """
--- a/dom/media/test/external/external_media_tests/media_utils/video_puppeteer.py
+++ b/dom/media/test/external/external_media_tests/media_utils/video_puppeteer.py
@@ -108,32 +108,28 @@ class VideoPuppeteer(object):
         self.expected_duration = 0
         self._first_seen_time = 0
         self._first_seen_wall_time = 0
         self._fetch_state_script_string = None
         self._last_seen_video_state = None
         wait = Wait(self.marionette, timeout=self.timeout)
         with self.marionette.using_context(Marionette.CONTEXT_CONTENT):
             self.marionette.navigate(self.test_url)
-            self.marionette.execute_script("""
-                log('URL: {0}');""".format(self.test_url))
+            print('URL: {}'.format(self.test_url))
             verbose_until(wait, self,
                           expected.element_present(By.TAG_NAME, 'video'))
             videos_found = self.marionette.find_elements(By.CSS_SELECTOR,
                                                          video_selector)
             if len(videos_found) > 1:
-                self.marionette.log(type(self).__name__ + ': multiple video '
-                                                          'elements found. '
-                                                          'Using first.')
+                print('{}: multiple video elements found. Using first.'.format(type(self).__name__))
             if len(videos_found) <= 0:
-                self.marionette.log(type(self).__name__ + ': no video '
-                                                          'elements found.')
+                print('{}: no video elements found.'.format(type(self).__name__))
                 return
             self.video = videos_found[0]
-            self.marionette.execute_script("log('video element obtained');")
+            print('video element obtained')
             if autostart:
                 self.start()
 
     def start(self):
         # To get an accurate expected_duration, playback must have started
         self._refresh_state()
         wait = Wait(self, timeout=self.timeout)
         verbose_until(wait, self, VideoPuppeteer.playback_started,
--- a/dom/media/test/external/external_media_tests/media_utils/youtube_puppeteer.py
+++ b/dom/media/test/external/external_media_tests/media_utils/youtube_puppeteer.py
@@ -88,18 +88,17 @@ class YouTubePuppeteer(VideoPuppeteer):
                              **kwargs)
         wait = Wait(self.marionette, timeout=30)
         with self.marionette.using_context(Marionette.CONTEXT_CONTENT):
             verbose_until(wait, self,
                           expected.element_present(By.CLASS_NAME,
                                                    'html5-video-player'))
             self.player = self.marionette.find_element(By.CLASS_NAME,
                                                        'html5-video-player')
-            self.marionette.execute_script("log('.html5-video-player "
-                                           "element obtained');")
+            print '.html5-video-player element obtained'
         # When an ad is playing, self.player_duration indicates the duration
         # of the spliced-in ad stream, not the duration of the main video, so
         # we attempt to skip the ad first.
         for attempt in range(5):
             sleep(1)
             self.process_ad()
             if (self._last_seen_player_state.player_ad_inactive and
                     self._last_seen_video_state.duration and not
@@ -135,18 +134,17 @@ class YouTubePuppeteer(VideoPuppeteer):
 
     def _get_player_debug_dict(self):
         text = self._execute_yt_script('return arguments[1].'
                                        'wrappedJSObject.getDebugText();')
         if text:
             try:
                 return loads(text)
             except ValueError:
-                self.marionette.log('Error loading json: DebugText',
-                                    level='DEBUG')
+                print 'Error loading JSON: DebugText'
 
     def _execute_yt_script(self, script):
         """
         Execute JS script in content context with access to video element and
         YouTube .html5-video-player element.
 
         :param script: script to be executed.
 
@@ -166,25 +164,23 @@ class YouTubePuppeteer(VideoPuppeteer):
         Wait for this ad to finish. Refreshes state.
         """
         self._refresh_state()
         if self._last_seen_player_state.player_ad_inactive:
             return
         ad_timeout = (self._search_ad_duration() or 30) + 5
         wait = Wait(self, timeout=ad_timeout, interval=1)
         try:
-            self.marionette.log('process_ad: waiting {} s for ad'
-                                .format(ad_timeout))
+            print('process_ad: waiting {}s for ad'.format(ad_timeout))
             verbose_until(wait,
                           self,
                           YouTubePuppeteer._check_if_ad_ended,
                           "Check if ad ended")
         except TimeoutException:
-            self.marionette.log('Waiting for ad to end timed out',
-                                level='WARNING')
+            print('Waiting for ad to end timed out')
 
     def _search_ad_duration(self):
         """
         Try and determine ad duration. Refreshes state.
 
         :return: ad duration in seconds, if currently displayed in player
         """
         self._refresh_state()
@@ -203,19 +199,17 @@ class YouTubePuppeteer(VideoPuppeteer):
                 countdown = self.marionette.find_element(By.CSS_SELECTOR,
                                                          selector)
                 ad_time = self._time_pattern.search(countdown.text)
                 if ad_time:
                     ad_minutes = int(ad_time.group('minute'))
                     ad_seconds = int(ad_time.group('second'))
                     return 60 * ad_minutes + ad_seconds
         except (TimeoutException, NoSuchElementException):
-            self.marionette.log('Could not obtain '
-                                'element: {}'.format(selector),
-                                level='WARNING')
+            print('Could not obtain element {}'.format(selector))
         return None
 
     def _player_stalled(self):
         """
         Checks if the player has stalled. Refreshes state.
 
         :return: True if playback is not making progress for 4-9 seconds. This
          excludes ad breaks. Note that the player might just be busy with
@@ -456,17 +450,17 @@ class YouTubePuppeteer(VideoPuppeteer):
             # wait longer between checks
             rest = duration / 50
 
         while remaining_time > final_piece:
             if self._player_stalled():
                 if self._last_seen_player_state.player_buffering:
                     # fall back on timeout in 'wait' call that comes after this
                     # in test function
-                    self.marionette.log('Buffering and no playback progress.')
+                    print('Buffering and no playback progress')
                     break
                 else:
                     message = '\n'.join(['Playback stalled', str(self)])
                     raise VideoException(message)
             if self._last_seen_player_state.player_breaks_count > 0:
                 self.process_ad()
             if remaining_time > 1.5 * rest:
                 sleep(rest)
--- a/dom/media/test/external/external_media_tests/playback/youtube/test_basic_playback.py
+++ b/dom/media/test/external/external_media_tests/playback/youtube/test_basic_playback.py
@@ -41,25 +41,23 @@ class TestBasicYouTubePlayback(MediaTest
                         final_piece=final_piece)
                 except VideoException as e:
                     raise self.failureException(e)
                 duration = abs(youtube.expected_duration) + 1
                 if duration > 1:
                     self.logger.info('Almost done: {} - {} seconds left.'
                                      .format(url, time_left))
                     if time_left > final_piece:
-                        self.marionette.log('time_left greater than '
-                                            'final_piece - {}'
-                                            .format(time_left),
-                                            level='WARNING')
+                        self.logger.warn('time_left greater than '
+                                         'final_piece - {}'
+                                         .format(time_left))
                         self.save_screenshot()
                 else:
-                    self.marionette.log('Duration close to 0 - {}'
-                                        .format(youtube),
-                                        level='WARNING')
+                    self.logger.warn('Duration close to 0 - {}'
+                                     .format(youtube))
                     self.save_screenshot()
                 try:
                     verbose_until(Wait(youtube,
                                        timeout=max(100, time_left) * 1.3,
                                        interval=1),
                                   youtube,
                                   YouTubePuppeteer.playback_done)
                 except TimeoutException as e: