OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 from telemetry.page import page as page_module | 4 from telemetry.page import page as page_module |
5 from telemetry.page import page_set as page_set_module | 5 from telemetry.page import page_set as page_set_module |
6 | 6 |
7 class PolymerPage(page_module.Page): | 7 class PolymerPage(page_module.Page): |
8 | 8 |
9 def __init__(self, url, page_set, run_no_page_interactions): | 9 def __init__(self, url, page_set, run_no_page_interactions): |
10 """ Base class for all polymer pages. | 10 """ Base class for all polymer pages. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 url=('http://www.polymer-project.org/components/paper-calculator/' | 47 url=('http://www.polymer-project.org/components/paper-calculator/' |
48 'demo.html'), | 48 'demo.html'), |
49 page_set=page_set, run_no_page_interactions=run_no_page_interactions) | 49 page_set=page_set, run_no_page_interactions=run_no_page_interactions) |
50 | 50 |
51 def PerformPageInteractions(self, action_runner): | 51 def PerformPageInteractions(self, action_runner): |
52 self.TapButton(action_runner) | 52 self.TapButton(action_runner) |
53 self.SlidePanel(action_runner) | 53 self.SlidePanel(action_runner) |
54 | 54 |
55 def TapButton(self, action_runner): | 55 def TapButton(self, action_runner): |
56 interaction = action_runner.BeginInteraction( | 56 interaction = action_runner.BeginInteraction( |
57 'Action_TapAction', is_smooth=True) | 57 'Action_TapAction') |
58 action_runner.TapElement(element_function=''' | 58 action_runner.TapElement(element_function=''' |
59 document.querySelector( | 59 document.querySelector( |
60 'body /deep/ #outerPanels' | 60 'body /deep/ #outerPanels' |
61 ).querySelector( | 61 ).querySelector( |
62 '#standard' | 62 '#standard' |
63 ).shadowRoot.querySelector( | 63 ).shadowRoot.querySelector( |
64 'paper-calculator-key[label="5"]' | 64 'paper-calculator-key[label="5"]' |
65 )''') | 65 )''') |
66 action_runner.Wait(2) | 66 action_runner.Wait(2) |
67 interaction.End() | 67 interaction.End() |
68 | 68 |
69 def SlidePanel(self, action_runner): | 69 def SlidePanel(self, action_runner): |
70 # only bother with this interaction if the drawer is hidden | 70 # only bother with this interaction if the drawer is hidden |
71 opened = action_runner.EvaluateJavaScript(''' | 71 opened = action_runner.EvaluateJavaScript(''' |
72 (function() { | 72 (function() { |
73 var outer = document.querySelector("body /deep/ #outerPanels"); | 73 var outer = document.querySelector("body /deep/ #outerPanels"); |
74 return outer.opened || outer.wideMode; | 74 return outer.opened || outer.wideMode; |
75 }());''') | 75 }());''') |
76 if not opened: | 76 if not opened: |
77 interaction = action_runner.BeginInteraction( | 77 interaction = action_runner.BeginInteraction( |
78 'Action_SwipeAction', is_smooth=True) | 78 'Action_SwipeAction') |
79 action_runner.SwipeElement( | 79 action_runner.SwipeElement( |
80 left_start_ratio=0.1, top_start_ratio=0.2, | 80 left_start_ratio=0.1, top_start_ratio=0.2, |
81 direction='left', distance=300, speed_in_pixels_per_second=5000, | 81 direction='left', distance=300, speed_in_pixels_per_second=5000, |
82 element_function=''' | 82 element_function=''' |
83 document.querySelector( | 83 document.querySelector( |
84 'body /deep/ #outerPanels' | 84 'body /deep/ #outerPanels' |
85 ).querySelector( | 85 ).querySelector( |
86 '#advanced' | 86 '#advanced' |
87 ).shadowRoot.querySelector( | 87 ).shadowRoot.querySelector( |
88 '.handle-bar' | 88 '.handle-bar' |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 def PerformPageInteractions(self, action_runner): | 151 def PerformPageInteractions(self, action_runner): |
152 #TODO(wiltzius) Add interactions for input elements and shadow pages | 152 #TODO(wiltzius) Add interactions for input elements and shadow pages |
153 if self.scrolling_page: | 153 if self.scrolling_page: |
154 # Only bother scrolling the page if its been marked as worthwhile | 154 # Only bother scrolling the page if its been marked as worthwhile |
155 self.ScrollContentPane(action_runner) | 155 self.ScrollContentPane(action_runner) |
156 self.TouchEverything(action_runner) | 156 self.TouchEverything(action_runner) |
157 | 157 |
158 def ScrollContentPane(self, action_runner): | 158 def ScrollContentPane(self, action_runner): |
159 element_function = (self.iframe_js + '.querySelector(' | 159 element_function = (self.iframe_js + '.querySelector(' |
160 '"core-scroll-header-panel").$.mainContainer') | 160 '"core-scroll-header-panel").$.mainContainer') |
161 interaction = action_runner.BeginInteraction('Scroll_Page', is_smooth=True) | 161 interaction = action_runner.BeginInteraction('Scroll_Page') |
162 action_runner.ScrollElement(use_touch=True, | 162 action_runner.ScrollElement(use_touch=True, |
163 direction='down', | 163 direction='down', |
164 distance='900', | 164 distance='900', |
165 element_function=element_function) | 165 element_function=element_function) |
166 interaction.End() | 166 interaction.End() |
167 interaction = action_runner.BeginInteraction('Scroll_Page', is_smooth=True) | 167 interaction = action_runner.BeginInteraction('Scroll_Page') |
168 action_runner.ScrollElement(use_touch=True, | 168 action_runner.ScrollElement(use_touch=True, |
169 direction='up', | 169 direction='up', |
170 distance='900', | 170 distance='900', |
171 element_function=element_function) | 171 element_function=element_function) |
172 interaction.End() | 172 interaction.End() |
173 | 173 |
174 def TouchEverything(self, action_runner): | 174 def TouchEverything(self, action_runner): |
175 tappable_types = [ | 175 tappable_types = [ |
176 'paper-button', | 176 'paper-button', |
177 'paper-checkbox', | 177 'paper-checkbox', |
(...skipping 22 matching lines...) Expand all Loading... |
200 element_query = element_list_query + ("[%d]" % i) | 200 element_query = element_list_query + ("[%d]" % i) |
201 if action_runner.EvaluateJavaScript( | 201 if action_runner.EvaluateJavaScript( |
202 element_query + '.offsetParent != null'): | 202 element_query + '.offsetParent != null'): |
203 # Only try to tap on visible elements (offsetParent != null) | 203 # Only try to tap on visible elements (offsetParent != null) |
204 action_runner.ExecuteJavaScript(element_query + '.scrollIntoView()') | 204 action_runner.ExecuteJavaScript(element_query + '.scrollIntoView()') |
205 action_runner.Wait(1) # wait for page to settle after scrolling | 205 action_runner.Wait(1) # wait for page to settle after scrolling |
206 action_function(action_runner, element_query) | 206 action_function(action_runner, element_query) |
207 | 207 |
208 def TapWidget(self, action_runner, element_function): | 208 def TapWidget(self, action_runner, element_function): |
209 interaction = action_runner.BeginInteraction( | 209 interaction = action_runner.BeginInteraction( |
210 'Tap_Widget', is_smooth=True) | 210 'Tap_Widget') |
211 action_runner.TapElement(element_function=element_function) | 211 action_runner.TapElement(element_function=element_function) |
212 action_runner.Wait(1) # wait for e.g. animations on the widget | 212 action_runner.Wait(1) # wait for e.g. animations on the widget |
213 interaction.End() | 213 interaction.End() |
214 | 214 |
215 def SwipeWidget(self, action_runner, element_function): | 215 def SwipeWidget(self, action_runner, element_function): |
216 interaction = action_runner.BeginInteraction( | 216 interaction = action_runner.BeginInteraction( |
217 'Swipe_Widget', is_smooth=True) | 217 'Swipe_Widget') |
218 action_runner.SwipeElement(element_function=element_function, | 218 action_runner.SwipeElement(element_function=element_function, |
219 left_start_ratio=0.75, | 219 left_start_ratio=0.75, |
220 speed_in_pixels_per_second=300) | 220 speed_in_pixels_per_second=300) |
221 interaction.End() | 221 interaction.End() |
222 | 222 |
223 | 223 |
224 class PolymerPageSet(page_set_module.PageSet): | 224 class PolymerPageSet(page_set_module.PageSet): |
225 | 225 |
226 def __init__(self, run_no_page_interactions=False): | 226 def __init__(self, run_no_page_interactions=False): |
227 super(PolymerPageSet, self).__init__( | 227 super(PolymerPageSet, self).__init__( |
(...skipping 29 matching lines...) Expand all Loading... |
257 for p in SCROLLABLE_PAGES: | 257 for p in SCROLLABLE_PAGES: |
258 self.AddUserStory(PolymerSampler( | 258 self.AddUserStory(PolymerSampler( |
259 self, p, run_no_page_interactions=run_no_page_interactions, | 259 self, p, run_no_page_interactions=run_no_page_interactions, |
260 scrolling_page=True)) | 260 scrolling_page=True)) |
261 | 261 |
262 for page in self: | 262 for page in self: |
263 assert (page.__class__.RunPageInteractions == | 263 assert (page.__class__.RunPageInteractions == |
264 PolymerPage.RunPageInteractions), ( | 264 PolymerPage.RunPageInteractions), ( |
265 'Pages in this page set must not override PolymerPage\' ' | 265 'Pages in this page set must not override PolymerPage\' ' |
266 'RunPageInteractions method.') | 266 'RunPageInteractions method.') |
OLD | NEW |