| OLD | NEW |
| (Empty) | |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 from page_sets.system_health import platforms |
| 6 from page_sets.system_health import system_health_story |
| 7 |
| 8 from page_sets.login_helpers import google_login |
| 9 from page_sets.login_helpers import pandora_login |
| 10 |
| 11 from telemetry import benchmark |
| 12 from telemetry import decorators |
| 13 |
| 14 |
| 15 class _MediaStory(system_health_story.SystemHealthStory): |
| 16 """Abstract base class for media System Health user stories.""" |
| 17 |
| 18 ABSTRACT_STORY = True |
| 19 SUPPORTED_PLATFORMS = platforms.DESKTOP_ONLY |
| 20 PLAY_DURATION = 20 |
| 21 PLAY_SELECTOR = NotImplemented |
| 22 STOP_SELECTOR = NotImplemented |
| 23 TIME_SELECTOR = NotImplemented |
| 24 |
| 25 def RunPageInteractions(self, action_runner): |
| 26 self._NavigateToMedia(action_runner) |
| 27 # Play Media. |
| 28 if self.PLAY_SELECTOR: |
| 29 self._WaitForAndClickElementBySelector(action_runner, self.PLAY_SELECTOR) |
| 30 self._WaitForPlayTime(action_runner) |
| 31 # Stop media. |
| 32 self._WaitForAndClickElementBySelector(action_runner, self.STOP_SELECTOR) |
| 33 |
| 34 def _NavigateToMedia(self, action_runner): |
| 35 raise NotImplementedError |
| 36 |
| 37 def _WaitForAndClickElementBySelector(self, action_runner, selector): |
| 38 element_function = 'document.querySelector("%s")' % selector |
| 39 action_runner.WaitForElement(element_function=element_function) |
| 40 action_runner.ClickElement(element_function=element_function) |
| 41 |
| 42 def _WaitForPlayTime(self, action_runner): |
| 43 action_runner.Wait(self.PLAY_DURATION) |
| 44 while self._GetTimeInSeconds(action_runner) < self.PLAY_DURATION: |
| 45 action_runner.Wait( |
| 46 self.PLAY_DURATION - self._GetTimeInSeconds(action_runner)) |
| 47 |
| 48 def _GetTimeInSeconds(self, action_runner): |
| 49 time_func = ( |
| 50 'document.querySelector("%s").textContent' % self.TIME_SELECTOR) |
| 51 minutes, seconds = action_runner.EvaluateJavaScript(time_func).split(':') |
| 52 return int(minutes * 60 + seconds) |
| 53 |
| 54 |
| 55 ################################################################################ |
| 56 # Audio stories. |
| 57 ################################################################################ |
| 58 |
| 59 |
| 60 @benchmark.Disabled('win') # crbug.com/649392 |
| 61 class GooglePlayMusicDesktopStory(_MediaStory): |
| 62 NAME = 'play:media:google_play_music' |
| 63 URL = 'https://music.google.com' |
| 64 |
| 65 PLAY_SELECTOR = '.x-scope.paper-fab-0' |
| 66 STOP_SELECTOR = '.style-scope.sj-play-button' |
| 67 TIME_SELECTOR = '#time-container-current' |
| 68 SEARCH_SELECTOR = '.title.fade-out.tooltip' |
| 69 NAVIGATE_SELECTOR = '.description.tooltip.fade-out' |
| 70 |
| 71 def _Login(self, action_runner): |
| 72 google_login.LoginGoogleAccount(action_runner, 'googletest', |
| 73 self.credentials_path) |
| 74 |
| 75 def _NavigateToMedia(self, action_runner): |
| 76 # Clicks on Today's top hits. |
| 77 action_runner.Wait(1) # Add 1 second wait to make the browsing realistic. |
| 78 self._WaitForAndClickElementBySelector(action_runner, self.SEARCH_SELECTOR) |
| 79 # Clicks on playlist. |
| 80 action_runner.Wait(1) # Add 1 second wait to make the browsing realistic. |
| 81 self._WaitForAndClickElementBySelector(action_runner, |
| 82 self.NAVIGATE_SELECTOR) |
| 83 |
| 84 |
| 85 @benchmark.Disabled('win') # crbug.com/649392 |
| 86 class SoundCloudDesktopStory(_MediaStory): |
| 87 NAME = 'play:media:soundcloud' |
| 88 URL = 'https://soundcloud.com' |
| 89 |
| 90 PLAY_SELECTOR = '.sc-button-play.playButton.sc-button.sc-button-xlarge' |
| 91 STOP_SELECTOR = '.playControl.playControls__icon.sc-ir.playing' |
| 92 TIME_SELECTOR = '.playbackTimeline__timePassed>span[aria-hidden=true]' |
| 93 SEARCH_SELECTOR = '.headerSearch' |
| 94 SEARCH_QUERY = 'SSmooth Jazz' # First S for some reason gets ommited. |
| 95 |
| 96 def _NavigateToMedia(self, action_runner): |
| 97 self._WaitForAndClickElementBySelector(action_runner, self.SEARCH_SELECTOR) |
| 98 action_runner.Wait(1) # Add 1 second wait to make the browsing realistic. |
| 99 action_runner.EnterText(self.SEARCH_QUERY) |
| 100 action_runner.PressKey('Return') |
| 101 |
| 102 |
| 103 @decorators.Disabled('all') # crbug.com/649392 |
| 104 class PandoraDesktopStory(_MediaStory): |
| 105 NAME = 'play:media:pandora' |
| 106 URL = 'https://pandora.com' |
| 107 |
| 108 PLAY_SELECTOR = None |
| 109 STOP_SELECTOR = '.pauseButton' |
| 110 TIME_SELECTOR = '.elapsedTime' |
| 111 SEARCH_SELECTOR = '.searchInput' |
| 112 |
| 113 def _Login(self, action_runner): |
| 114 pandora_login.LoginAccount(action_runner, 'pandora', self.credentials_path) |
| 115 |
| 116 def _NavigateToMedia(self, action_runner): |
| 117 pass # Audio autoplays on Pandora, no need to search. |
| OLD | NEW |