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

Side by Side Diff: experimental/telemetry_mini/android_go_stories.py

Issue 3000083002: [telemetry_mini] Add UserStory class (Closed)
Patch Set: Created 3 years, 4 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 | « no previous file | experimental/telemetry_mini/telemetry_mini.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2017 The Chromium Authors. All rights reserved. 2 # Copyright 2017 The Chromium Authors. All rights reserved.
3 # 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
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import argparse 6 import argparse
7 import logging 7 import logging
8 import os 8 import os
9 import sys 9 import sys
10 import time 10 import time
(...skipping 22 matching lines...) Expand all
33 33
34 KEYCODE_BACK = 4 34 KEYCODE_BACK = 4
35 35
36 BROWSERS = { 36 BROWSERS = {
37 'android-chrome': telemetry_mini.ChromeApp, 37 'android-chrome': telemetry_mini.ChromeApp,
38 'android-chromium': telemetry_mini.ChromiumApp, 38 'android-chromium': telemetry_mini.ChromiumApp,
39 'android-system-chrome': telemetry_mini.SystemChromeApp, 39 'android-system-chrome': telemetry_mini.SystemChromeApp,
40 } 40 }
41 41
42 42
43 class TwitterApp(telemetry_mini.AndroidApp):
44 PACKAGE_NAME = 'com.twitter.android'
45
46
47 class ProcessWatcher(object): 43 class ProcessWatcher(object):
48 def __init__(self, device): 44 def __init__(self, device):
49 self.device = device 45 self.device = device
50 self._process_pid = {} 46 self._process_pid = {}
51 47
52 def StartWatching(self, process_name): 48 def StartWatching(self, process_name):
53 """Register a process or android app to keep track of its PID.""" 49 """Register a process or android app to keep track of its PID."""
54 if isinstance(process_name, telemetry_mini.AndroidApp): 50 if isinstance(process_name, telemetry_mini.AndroidApp):
55 process_name = process_name.PACKAGE_NAME 51 process_name = process_name.PACKAGE_NAME
56 52
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 # Finally check that only the selected browser is actually available. 108 # Finally check that only the selected browser is actually available.
113 available_browsers = device.ListPackages('chrome', only_enabled=True) 109 available_browsers = device.ListPackages('chrome', only_enabled=True)
114 assert browser.PACKAGE_NAME in available_browsers, ( 110 assert browser.PACKAGE_NAME in available_browsers, (
115 'Unable to make %s available' % browser.PACKAGE_NAME) 111 'Unable to make %s available' % browser.PACKAGE_NAME)
116 available_browsers.remove(browser.PACKAGE_NAME) 112 available_browsers.remove(browser.PACKAGE_NAME)
117 assert not available_browsers, ( 113 assert not available_browsers, (
118 'Other browsers may intefere with the test: %s' % available_browsers) 114 'Other browsers may intefere with the test: %s' % available_browsers)
119 return browser 115 return browser
120 116
121 117
122 def RunStory(browser): 118 class TwitterApp(telemetry_mini.AndroidApp):
123 tracefile = 'trace.json' 119 PACKAGE_NAME = 'com.twitter.android'
124 device = browser.device
125 twitter = TwitterApp(device)
126 watcher = ProcessWatcher(device)
127 120
128 with browser.Session(BROWSER_FLAGS, TRACE_CONFIG):
129 twitter.ForceStop()
130 try:
131 # Intent will launch Twitter app on Flipkart profile.
132 device.RunShellCommand(
133 'am', 'start', '-a', 'android.intent.action.VIEW',
134 '-d', 'https://twitter.com/flipkart')
135 watcher.StartWatching(twitter)
136 121
137 # Tapping on Flikpart link on Twitter app will launch Chrome. 122 class TwitterFlipkartStory(telemetry_mini.UserStory):
138 device.TapUiNode(FLIPKART_TWITTER_LINK) 123 def __init__(self, *args, **kwargs):
139 watcher.StartWatching(browser) 124 super(TwitterFlipkartStory, self).__init__(*args, **kwargs)
125 self.watcher = ProcessWatcher(self.device)
126 self.twitter = TwitterApp(self.device)
140 127
141 time.sleep(4) 128 def GetExtraStoryApps(self):
142 # Scroll content up a bit. 129 return (self.twitter,)
143 device.RunShellCommand(
144 'input', 'swipe', '240', '568', '240', '284', '400')
145 time.sleep(1)
146 130
147 browser.CollectTrace(tracefile) 131 def RunStorySteps(self):
148 watcher.AssertAllAlive() 132 # Intent will launch Twitter app on Flipkart profile.
133 self.device.RunShellCommand(
134 'am', 'start', '-a', 'android.intent.action.VIEW',
135 '-d', 'https://twitter.com/flipkart')
136 self.watcher.StartWatching(self.twitter)
149 137
150 # Go "Back" and return to Twitter app. 138 # Tapping on Flikpart link on Twitter app will launch Chrome.
151 device.RunShellCommand('input', 'keyevent', str(KEYCODE_BACK)) 139 self.device.TapUiNode(FLIPKART_TWITTER_LINK)
152 time.sleep(1) 140 self.watcher.StartWatching(self.browser)
153 finally: 141
154 twitter.ForceStop() 142 time.sleep(10) # TODO: Replace with wait until page loaded.
143 # Scroll content up a bit.
144 self.device.RunShellCommand(
145 'input', 'swipe', '240', '568', '240', '284', '400')
146 time.sleep(1)
147
148 # Go "Back" and return to Twitter app.
149 self.device.RunShellCommand('input', 'keyevent', str(KEYCODE_BACK))
150 time.sleep(1)
151
152 self.watcher.AssertAllAlive()
155 153
156 154
157 def main(): 155 def main():
158 browser_names = sorted(BROWSERS) 156 browser_names = sorted(BROWSERS)
159 default_browser = 'android-chrome' 157 default_browser = 'android-chrome'
160 parser = argparse.ArgumentParser() 158 parser = argparse.ArgumentParser()
161 parser.add_argument('--serial', 159 parser.add_argument('--serial',
162 help='device serial on which to run user stories' 160 help='device serial on which to run user stories'
163 ' (defaults to first device found)') 161 ' (defaults to first device found)')
164 parser.add_argument('--adb-bin', default='adb', metavar='PATH', 162 parser.add_argument('--adb-bin', default='adb', metavar='PATH',
(...skipping 29 matching lines...) Expand all
194 logging.warning('Connected to first device found: %s', device.serial) 192 logging.warning('Connected to first device found: %s', device.serial)
195 else: 193 else:
196 device = telemetry_mini.AdbMini(args.serial) 194 device = telemetry_mini.AdbMini(args.serial)
197 195
198 # Some operations may require a rooted device. 196 # Some operations may require a rooted device.
199 device.RunCommand('root') 197 device.RunCommand('root')
200 device.RunCommand('wait-for-device') 198 device.RunCommand('wait-for-device')
201 199
202 browser = EnsureSingleBrowser(device, args.browser, args.force_install) 200 browser = EnsureSingleBrowser(device, args.browser, args.force_install)
203 browser.SetDevToolsLocalPort(args.port) 201 browser.SetDevToolsLocalPort(args.port)
204 RunStory(browser) 202
203 story = TwitterFlipkartStory(browser)
204 story.Run(BROWSER_FLAGS, TRACE_CONFIG, 'trace.json')
205
205 206
206 if __name__ == '__main__': 207 if __name__ == '__main__':
207 sys.exit(main()) 208 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | experimental/telemetry_mini/telemetry_mini.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698