Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # encoding: utf-8 | |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 2 # 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 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 4 | 5 |
| 6 from page_sets.system_health import platforms | |
| 7 from page_sets.system_health import story_tags | |
| 5 from page_sets.system_health import system_health_story | 8 from page_sets.system_health import system_health_story |
| 6 | 9 |
| 10 from devil.android.sdk import keyevent # pylint: disable=import-error | |
| 7 | 11 |
| 12 from telemetry import decorators | |
| 13 from telemetry.util import js_template | |
| 14 | |
| 15 # TODO(ssid): Rename the search stories to browse stories crbug.com/708300. | |
| 8 class SearchGoogleStory(system_health_story.SystemHealthStory): | 16 class SearchGoogleStory(system_health_story.SystemHealthStory): |
| 9 NAME = 'search:portal:google' | 17 NAME = 'search:portal:google' |
| 10 URL = 'https://www.google.co.uk/' | 18 URL = 'https://www.google.co.uk/' |
| 19 TAGS = [story_tags.EMERGING_MARKET] | |
| 11 | 20 |
| 12 _SEARCH_BOX_SELECTOR = 'input[aria-label="Search"]' | 21 _SEARCH_BOX_SELECTOR = 'input[aria-label="Search"]' |
| 13 _RESULT_SELECTOR = '.r > a[href*="wikipedia"]' | 22 _RESULT_SELECTOR = '.r > a[href*="wikipedia"]' |
| 14 | 23 |
| 15 def _DidLoadDocument(self, action_runner): | 24 def _DidLoadDocument(self, action_runner): |
| 16 # Click on the search box. | 25 # Click on the search box. |
| 17 action_runner.Wait(1) | 26 action_runner.Wait(1) |
| 18 action_runner.WaitForElement(selector=self._SEARCH_BOX_SELECTOR) | 27 action_runner.WaitForElement(selector=self._SEARCH_BOX_SELECTOR) |
| 19 action_runner.TapElement(selector=self._SEARCH_BOX_SELECTOR) | 28 action_runner.TapElement(selector=self._SEARCH_BOX_SELECTOR) |
| 20 | 29 |
| 21 # Submit search query. | 30 # Submit search query. |
| 22 action_runner.Wait(1) | 31 action_runner.Wait(1) |
| 23 action_runner.EnterText('what is science') | 32 action_runner.EnterText('what is science') |
| 24 action_runner.Wait(0.5) | 33 action_runner.Wait(0.5) |
| 25 action_runner.PressKey('Return') | 34 action_runner.PressKey('Return') |
| 26 | 35 |
| 27 # Scroll to the Wikipedia result. | 36 # Scroll to the Wikipedia result. |
| 28 action_runner.WaitForElement(selector=self._RESULT_SELECTOR) | 37 action_runner.WaitForElement(selector=self._RESULT_SELECTOR) |
| 29 action_runner.Wait(1) | 38 action_runner.Wait(1) |
| 30 action_runner.ScrollPageToElement(selector=self._RESULT_SELECTOR) | 39 action_runner.ScrollPageToElement(selector=self._RESULT_SELECTOR) |
| 31 | 40 |
| 32 # Click on the Wikipedia result. | 41 # Click on the Wikipedia result. |
| 33 action_runner.Wait(1) | 42 action_runner.Wait(1) |
| 34 action_runner.TapElement(selector=self._RESULT_SELECTOR) | 43 action_runner.TapElement(selector=self._RESULT_SELECTOR) |
| 35 action_runner.tab.WaitForDocumentReadyStateToBeComplete() | 44 action_runner.tab.WaitForDocumentReadyStateToBeComplete() |
| 45 | |
| 46 | |
| 47 class SearchOmniboxStory(system_health_story.SystemHealthStory): | |
| 48 NAME = 'search:google:omnibox' | |
|
perezju
2017/04/10 10:13:57
this one should be called already: browse:chrome:o
ssid
2017/04/11 03:55:58
Done.
| |
| 49 URL = 'https://www.google.co.in' | |
| 50 SUPPORTED_PLATFORMS = platforms.MOBILE_ONLY | |
| 51 TAGS = [story_tags.EMERGING_MARKET] | |
| 52 | |
| 53 def _DidLoadDocument(self, action_runner): | |
| 54 app_ui = action_runner.tab.browser.app_ui | |
| 55 platform = action_runner.tab.browser.platform | |
| 56 app_ui.WaitForUiNode(resource_id='url_bar') | |
| 57 url_bar = app_ui.GetUiNode(resource_id='url_bar') | |
| 58 url_bar.Tap() | |
| 59 action_runner.Wait(1) # user wait before typing | |
| 60 platform.android_action_runner.InputText('drake') | |
| 61 action_runner.Wait(0.5) # user wait after typing | |
| 62 platform.android_action_runner.InputKeyEvent(keyevent.KEYCODE_ENTER) | |
| 63 | |
| 64 action_runner.WaitForNavigate(15) | |
| 65 action_runner.ScrollPage(use_touch=True, distance=500) | |
| 66 | |
| 67 | |
| 68 class MobileNewTabPageStory(system_health_story.SystemHealthStory): | |
| 69 """Story that loads new tab page and opens menu.""" | |
| 70 | |
| 71 NAME = 'search:chrome:newtab' | |
|
perezju
2017/04/10 10:13:57
should be called already: browse:chrome:newtab
ssid
2017/04/11 03:55:58
Done.
| |
| 72 URL = 'chrome://newtab' | |
| 73 _SEARCH_TEXTS = ['does google know everything', | |
| 74 'most famous paintings', | |
| 75 'current weather', | |
| 76 'best movies 2016', | |
| 77 'how to tie a tie'] | |
| 78 | |
| 79 SUPPORTED_PLATFORMS = platforms.MOBILE_ONLY | |
| 80 TAGS = [story_tags.EMERGING_MARKET] | |
| 81 | |
| 82 def _DidLoadDocument(self, action_runner): | |
| 83 app_ui = action_runner.tab.browser.app_ui | |
| 84 platform = action_runner.tab.browser.platform | |
| 85 renderer_view = self._GetUiNode('compositor_view_holder', app_ui) | |
| 86 scroll_start = 0.5 * ( | |
| 87 renderer_view.bounds.center + renderer_view.bounds.bottom_right) | |
| 88 platform.android_action_runner.SmoothScrollBy( | |
| 89 scroll_start.x, scroll_start.y, 'down', 300) | |
| 90 for keyword in self._SEARCH_TEXTS: | |
| 91 self._GetUiNode('search_box', app_ui).Tap() | |
| 92 platform.android_action_runner.InputText(keyword) | |
| 93 platform.android_action_runner.InputKeyEvent(keyevent.KEYCODE_ENTER) | |
| 94 action_runner.WaitForNavigate() | |
| 95 action_runner.Wait(1.5) # Read results | |
| 96 action_runner.ScrollPage(use_touch=True) | |
| 97 action_runner.NavigateBack() | |
| 98 action_runner.WaitForNavigate() | |
| 99 | |
| 100 self._GetUiNode('menu_button', app_ui).Tap() | |
| 101 app_ui.WaitForUiNode(resource_id='menu_item_text') | |
| 102 | |
| 103 def _GetUiNode(self, resource, app_ui): | |
| 104 app_ui.WaitForUiNode(resource_id=resource) | |
| 105 return app_ui.GetUiNode(resource_id=resource) | |
| 106 | |
| 107 | |
| 108 @decorators.Disabled('win') # crbug.com/673775 | |
| 109 class GoogleDesktopStory(system_health_story.SystemHealthStory): | |
| 110 """ | |
| 111 A typical google search story: | |
| 112 _ Start at https://www.google.com/search?q=flower | |
| 113 _ Click on the wikipedia link & navigate to | |
| 114 https://en.wikipedia.org/wiki/Flower | |
| 115 _ Scroll down the wikipedia page about flower. | |
| 116 _ Back to the search main page. | |
| 117 _ Refine the search query to 'flower delivery'. | |
| 118 _ Scroll down the page. | |
| 119 _ Click the next page result of 'flower delivery'. | |
| 120 _ Scroll the search page. | |
| 121 | |
| 122 """ | |
| 123 NAME = 'browse:search:google' | |
| 124 URL = 'https://www.google.com/search?q=flower' | |
| 125 _SEARCH_BOX_SELECTOR = 'input[aria-label="Search"]' | |
| 126 _SEARCH_PAGE_2_SELECTOR = 'a[aria-label=\'Page 2\']' | |
| 127 SUPPORTED_PLATFORMS = platforms.DESKTOP_ONLY | |
| 128 | |
| 129 def _DidLoadDocument(self, action_runner): | |
| 130 # Click on flower Wikipedia link. | |
| 131 action_runner.Wait(2) | |
| 132 action_runner.ClickElement(text='Flower - Wikipedia') | |
| 133 action_runner.WaitForNavigate() | |
| 134 | |
| 135 # Scroll the flower Wikipedia page, then navigate back. | |
| 136 action_runner.Wait(2) | |
| 137 action_runner.ScrollPage() | |
| 138 action_runner.Wait(2) | |
| 139 action_runner.NavigateBack() | |
| 140 | |
| 141 # Click on the search box. | |
| 142 action_runner.WaitForElement(selector=self._SEARCH_BOX_SELECTOR) | |
| 143 action_runner.ClickElement(selector=self._SEARCH_BOX_SELECTOR) | |
| 144 action_runner.Wait(2) | |
| 145 | |
| 146 # Submit search query. | |
| 147 action_runner.EnterText(' delivery') | |
| 148 action_runner.Wait(0.5) | |
| 149 action_runner.PressKey('Return') | |
| 150 | |
| 151 # Scroll down & click next search result page. | |
| 152 action_runner.Wait(2) | |
| 153 action_runner.ScrollPageToElement(selector=self._SEARCH_PAGE_2_SELECTOR) | |
| 154 action_runner.Wait(2) | |
| 155 action_runner.ClickElement(selector=self._SEARCH_PAGE_2_SELECTOR) | |
| 156 action_runner.Wait(2) | |
| 157 action_runner.ScrollPage() | |
| 158 | |
| 159 | |
| 160 class GoogleIndiaDesktopStory(system_health_story.SystemHealthStory): | |
| 161 """ | |
| 162 A typical google search story in India: | |
| 163 1. Start at https://www.google.co.in/search?q=%E0%A4%AB%E0%A5%82%E0%A4%B2` | |
| 164 2. Scroll down the page. | |
| 165 3. Refine the query & click search box, which navigates to | |
| 166 https://www.google.co.in/search?q=%E0%A4%AB%E0%A5%82%E0%A4%B2&rct=j#q=%E0%A4 %AB%E0%A5%82%E0%A4%B2+%E0%A4%B5%E0%A4%BF%E0%A4%A4%E0%A4%B0%E0%A4%A3 | |
| 167 4. Scroll down the page. | |
| 168 5. Click the next page result | |
| 169 6. Scroll the search result page. | |
| 170 | |
| 171 """ | |
| 172 NAME = 'browse:search:google_india' | |
| 173 URL = 'https://www.google.co.in/search?q=%E0%A4%AB%E0%A5%82%E0%A4%B2' | |
| 174 _SEARCH_BOX_SELECTOR = 'input[aria-label="Search"]' | |
| 175 _SEARCH_BUTTON_SELECTOR = 'button[aria-label="Google Search"]' | |
| 176 _SEARCH_PAGE_2_SELECTOR = 'a[aria-label=\'Page 2\']' | |
| 177 SUPPORTED_PLATFORMS = platforms.DESKTOP_ONLY | |
| 178 TAGS = [story_tags.INTERNATIONAL] | |
| 179 | |
| 180 def _DidLoadDocument(self, action_runner): | |
| 181 action_runner.Wait(2) | |
| 182 action_runner.ScrollPage() | |
| 183 action_runner.Wait(2) | |
| 184 | |
| 185 action_runner.ScrollPage(direction='up') | |
| 186 | |
| 187 # Refine search query in the search box. | |
| 188 # TODO(nednguyen): replace this with input text gesture to make it more | |
| 189 # realistic. | |
| 190 action_runner.ExecuteJavaScript( | |
| 191 js_template.Render( | |
| 192 'document.querySelector({{ selector }}).value += "वितरण";', | |
| 193 selector=self._SEARCH_BOX_SELECTOR)) | |
| 194 action_runner.Wait(2) | |
| 195 action_runner.ClickElement(selector=self._SEARCH_BUTTON_SELECTOR) | |
| 196 | |
| 197 # Scroll down & click next search result page. | |
| 198 action_runner.Wait(2) | |
| 199 action_runner.ScrollPageToElement(selector=self._SEARCH_PAGE_2_SELECTOR) | |
| 200 action_runner.Wait(2) | |
| 201 action_runner.ClickElement(selector=self._SEARCH_PAGE_2_SELECTOR) | |
| 202 action_runner.Wait(2) | |
| 203 action_runner.ScrollPage() | |
| OLD | NEW |