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 system_health_story | |
6 | |
7 | |
8 class SearchGoogleStory(system_health_story.SystemHealthStory): | |
9 NAME = 'search:portal:google' | |
10 URL = 'https://www.google.co.uk/' | |
11 | |
12 _SEARCH_BOX_SELECTOR = 'input[aria-label="Search"]' | |
13 _RESULT_SELECTOR = '.r > a[href*="wikipedia"]' | |
14 | |
15 def _DidLoadDocument(self, action_runner): | |
16 # Click on the search box. | |
17 action_runner.Wait(1) | |
18 action_runner.WaitForElement(selector=self._SEARCH_BOX_SELECTOR) | |
19 action_runner.TapElement(selector=self._SEARCH_BOX_SELECTOR) | |
20 | |
21 # Submit search query. | |
22 action_runner.Wait(1) | |
23 action_runner.EnterText('what is science') | |
24 action_runner.Wait(0.5) | |
25 action_runner.PressKey('Return') | |
26 | |
27 # Scroll to the Wikipedia result. | |
28 action_runner.WaitForElement(selector=self._RESULT_SELECTOR) | |
29 action_runner.Wait(1) | |
30 # TODO(petrcermak): Turn this into a proper Telemetry API (ScrollToElement). | |
31 result_visible_expression = (''' | |
32 (function() { | |
33 var resultElem = document.querySelector(\'%s\'); | |
34 var boundingRect = resultElem.getBoundingClientRect(); | |
35 return boundingRect.bottom >= window.innerHeight | |
36 })()''' % self._RESULT_SELECTOR) | |
37 while action_runner.EvaluateJavaScript(result_visible_expression): | |
38 action_runner.RepeatableBrowserDrivenScroll(y_scroll_distance_ratio=0.75, | |
39 prevent_fling=False) | |
40 action_runner.Wait(0.2) | |
41 | |
42 # Click on the Wikipedia result. | |
43 action_runner.Wait(1) | |
44 action_runner.TapElement(selector=self._RESULT_SELECTOR) | |
45 action_runner.tab.WaitForDocumentReadyStateToBeComplete() | |
OLD | NEW |