Chromium Code Reviews| 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:search:google' | |
|
nednguyen
2016/07/20 20:44:25
search:portal:google?
petrcermak
2016/07/22 16:16:25
Done.
| |
| 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.Wait(1) | |
| 29 action_runner.tab.WaitForDocumentReadyStateToBeComplete() | |
| 30 action_runner.WaitForElement(selector=self._RESULT_SELECTOR) | |
| 31 # TODO(petrcermak): Turn this into a proper Telemetry API (ScrollToElement). | |
|
nednguyen
2016/07/20 16:02:02
Yeah, I encounter this situation a lot too ~_~
| |
| 32 result_visible_expression = (''' | |
| 33 (function() { | |
| 34 var resultElem = document.querySelector(\'%s\'); | |
| 35 var boundingRect = resultElem.getBoundingClientRect(); | |
| 36 return boundingRect.bottom >= window.innerHeight | |
| 37 })()''' % self._RESULT_SELECTOR) | |
| 38 while action_runner.EvaluateJavaScript(result_visible_expression): | |
| 39 action_runner.RepeatableBrowserDrivenScroll(y_scroll_distance_ratio=0.75, | |
| 40 prevent_fling=False) | |
| 41 action_runner.Wait(0.2) | |
| 42 | |
| 43 # Click on the Wikipedia result. | |
| 44 action_runner.Wait(1) | |
| 45 action_runner.TapElement(selector=self._RESULT_SELECTOR) | |
| 46 action_runner.tab.WaitForDocumentReadyStateToBeComplete() | |
| OLD | NEW |