Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(894)

Side by Side Diff: tools/perf/page_sets/system_health/media_stories.py

Issue 2334233002: [System Health] Create first System Health media user stories. (Closed)
Patch Set: [System Health] Create first System Health media user stories. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/perf/page_sets/login_helpers/pandora_login.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
12 class _MediaStory(system_health_story.SystemHealthStory):
13 """Abstract base class for media System Health user stories."""
14
15 ABSTRACT_STORY = True
16 SUPPORTED_PLATFORMS = platforms.DESKTOP_ONLY
17 PLAY_DURATION = 20
18
19 def RunPageInteractions(self, action_runner):
20 self._NavigateToMedia(action_runner)
21 # Play Media.
22 if self.PLAY_ELEMENT:
23 self._WaitForAndClickElement(action_runner, self.PLAY_ELEMENT)
24 self._WaitForPlayTime(action_runner)
25 # Stop media.
26 self._WaitForAndClickElement(action_runner, self.STOP_ELEMENT)
27
28 def _NavigateToMedia(self, action_runner):
29 raise NotImplementedError
30
31 def _WaitForAndClickElement(self, action_runner, element_function):
32 action_runner.WaitForElement(element_function=element_function)
33 action_runner.ClickElement(element_function=element_function)
34
35 def _WaitForPlayTime(self, action_runner):
36 action_runner.Wait(self.PLAY_DURATION)
37 while self._GetTimeInSeconds(action_runner) < self.PLAY_DURATION:
38 action_runner.Wait(
39 self.PLAY_DURATION - self._GetTimeInSeconds(action_runner))
40
41 def _GetTimeInSeconds(self, action_runner):
42 minutes, seconds = action_runner.EvaluateJavaScript(
43 self.TIME_ELEMENT).split(':')
petrcermak 2016/09/22 09:50:56 you should define `TIME_ELEMENT = NotImplemented`
rnephew (Reviews Here) 2016/09/22 16:40:51 Done.
44 return int(minutes * 60 + seconds)
45
46
47 ################################################################################
48 # Audio stories.
49 ################################################################################
50
51
52 class GooglePlayMusicDesktopStory(_MediaStory):
53 NAME = 'play:media:google_play_music'
54 URL = 'https://music.google.com'
55
56 SEARCH_ELEMENT = 'document.querySelector(".title.fade-out.tooltip")'
petrcermak 2016/09/22 09:50:56 nit: please modify the order of the class constant
rnephew (Reviews Here) 2016/09/22 16:40:51 Done.
57 PLAY_ELEMENT = (
58 'document.getElementsByClassName("x-scope paper-fab-0")[0]')
petrcermak 2016/09/22 09:50:56 You use "document.getElementByClassName(SELECTOR)[
rnephew (Reviews Here) 2016/09/22 16:40:51 Done.
59 STOP_ELEMENT = (
60 'document.getElementsByClassName("style-scope sj-play-button")[0]')
61 NAVIGATE_IDENTIFIER = (
petrcermak 2016/09/22 09:50:56 why is this called "IDENTIFIER" and not "ELEMENT"
rnephew (Reviews Here) 2016/09/22 16:40:51 Missed when switching everything. Fixed.
62 'document.getElementsByClassName("description tooltip fade-out")[0]')
63 TIME_ELEMENT = 'document.getElementById("time-container-current").innerHTML'
petrcermak 2016/09/22 09:50:56 why don't you use `textContent` instead of `innerH
petrcermak 2016/09/22 09:50:56 All other ELEMENTs refer to the element, but this
rnephew (Reviews Here) 2016/09/22 16:40:51 Didn't know about it, switched to it.
rnephew (Reviews Here) 2016/09/22 16:40:51 Done.
64
65
66 def _Login(self, action_runner):
67 google_login.LoginGoogleAccount(action_runner, 'googletest',
68 self.credentials_path)
69
70 def _NavigateToMedia(self, action_runner):
71 # Clicks on Today's top hits.
72 self._WaitForAndClickElement(action_runner, self.SEARCH_ELEMENT)
73 # Clicks on playlist.
74 self._WaitForAndClickElement(action_runner, self.NAVIGATE_IDENTIFIER)
75
76 def _GetTimeInSeconds(self, action_runner):
petrcermak 2016/09/22 09:50:56 No need to redefine the method again.
rnephew (Reviews Here) 2016/09/22 16:40:52 Done.
77 minutes, seconds = action_runner.EvaluateJavaScript(
78 self.TIME_ELEMENT).split(':')
79 return int(minutes * 60 + seconds)
80
81
82 class SoundCloudDesktopStory(_MediaStory):
83 NAME = 'play:media:soundcloud'
84 URL = 'https://soundcloud.com'
85
86 SEARCH_ELEMENT = 'document.getElementsByClassName("headerSearch")[0]'
87 SEARCH_QUERY = 'SSmooth Jazz' # First S for some reason gets ommited.
88 PLAY_ELEMENT = ('document.getElementsByClassName("sc-button-play'
89 ' playButton sc-button sc-button-xlarge")[0]')
90 STOP_ELEMENT = ('document.getElementsByClassName("playControl '
91 'playControls__icon sc-ir playing")[0]')
92 TIME_ELEMENT = ('document.getElementsByClassName('
93 '"playbackTimeline__timePassed")[0].innerHTML')
94
95 def _NavigateToMedia(self, action_runner):
96 self._WaitForAndClickElement(action_runner, self.SEARCH_ELEMENT)
97 action_runner.Wait(1) # Add 1 second wait to make the browsing realistic.
98 action_runner.EnterText(self.SEARCH_QUERY)
99 action_runner.PressKey('Return')
100
101 def _GetTimeInSeconds(self, action_runner):
102 # Format of returned value is:
petrcermak 2016/09/22 09:50:56 Instead of doing this in python, change your TIME_
rnephew (Reviews Here) 2016/09/22 16:40:52 Done.
103 # <span class="sc-visuallyhidden">Current time: 19 seconds</span>
104 # <span aria-hidden="true">0:19</span>
105 minutes, seconds = action_runner.EvaluateJavaScript(
106 self.TIME_ELEMENT).split(">")[3].split('<')[0].split(':')
107 return int(minutes * 60 + seconds)
108
109
110 class PandoraDesktopStory(_MediaStory):
111 NAME = 'play:media:pandora'
112 URL = 'https://pandora.com'
113
114 SEARCH_ELEMENT = 'document.getElementsByClassName("searchInput")[0]'
115 SEARCH_QUERY = None
petrcermak 2016/09/22 09:50:56 no need to define SEARCH_QUERY
rnephew (Reviews Here) 2016/09/22 16:40:51 Done.
116 PLAY_ELEMENT = None
117 STOP_ELEMENT = 'document.getElementsByClassName("pauseButton")[0]'
118 TIME_ELEMENT = 'document.getElementsByClassName("elapsedTime")[0].innerHTML'
119
120 def _Login(self, action_runner):
121 pandora_login.LoginAccount(action_runner, 'pandora', self.credentials_path)
122
123 def _NavigateToMedia(self, action_runner):
124 pass # Audio autoplays on Pandora, no need to search.
OLDNEW
« no previous file with comments | « tools/perf/page_sets/login_helpers/pandora_login.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698