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

Side by Side Diff: tools/chrome_proxy/webdriver/common.py

Issue 2555833003: Add functionality for Android. (Closed)
Patch Set: Prettier logic Created 4 years 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 | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2016 The Chromium Authors. All rights reserved. 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 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 4
5 import argparse 5 import argparse
6 import json 6 import json
7 import os 7 import os
8 import re 8 import re
9 import shlex 9 import shlex
10 import sys 10 import sys
(...skipping 14 matching lines...) Expand all
25 Returns: 25 Returns:
26 A new Namespace object with class properties for each argument added below. 26 A new Namespace object with class properties for each argument added below.
27 See pydoc for argparse. 27 See pydoc for argparse.
28 """ 28 """
29 parser = argparse.ArgumentParser() 29 parser = argparse.ArgumentParser()
30 parser.add_argument('--browser_args', nargs=1, type=str, help='Override ' 30 parser.add_argument('--browser_args', nargs=1, type=str, help='Override '
31 'browser flags in code with these flags') 31 'browser flags in code with these flags')
32 parser.add_argument('--via_header_value', metavar='via_header', nargs=1, 32 parser.add_argument('--via_header_value', metavar='via_header', nargs=1,
33 default='1.1 Chrome-Compression-Proxy', help='What the via should match to ' 33 default='1.1 Chrome-Compression-Proxy', help='What the via should match to '
34 'be considered valid') 34 'be considered valid')
35 parser.add_argument('--android', help='If given, attempts to run the test on '
36 'Android via adb. Ignores usage of --chrome_exec', action='store_true')
37 parser.add_argument('--android_package', nargs=1,
38 default='com.android.chrome', help='Set the android package for Chrome')
35 parser.add_argument('--chrome_exec', nargs=1, type=str, help='The path to ' 39 parser.add_argument('--chrome_exec', nargs=1, type=str, help='The path to '
36 'the Chrome or Chromium executable') 40 'the Chrome or Chromium executable')
37 parser.add_argument('chrome_driver', nargs=1, type=str, help='The path to ' 41 parser.add_argument('chrome_driver', nargs=1, type=str, help='The path to '
38 'the ChromeDriver executable. If not given, the default system chrome ' 42 'the ChromeDriver executable. If not given, the default system chrome '
39 'will be used.') 43 'will be used.')
40 # TODO(robertogden): Log sys.argv here. 44 # TODO(robertogden): Log sys.argv here.
41 return parser.parse_args(sys.argv[1:]) 45 return parser.parse_args(sys.argv[1:])
42 46
43 def HandleException(test_name=None): 47 def HandleException(test_name=None):
44 """Writes the exception being handled and a stack trace to stderr. 48 """Writes the exception being handled and a stack trace to stderr.
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 original_args[GetDictKey(arg)] = arg 107 original_args[GetDictKey(arg)] = arg
104 # Override flags given in code with any command line arguments. 108 # Override flags given in code with any command line arguments.
105 for override_arg in shlex.split(self._flags.browser_args[0]): 109 for override_arg in shlex.split(self._flags.browser_args[0]):
106 arg_key = GetDictKey(override_arg) 110 arg_key = GetDictKey(override_arg)
107 if arg_key in original_args: 111 if arg_key in original_args:
108 self._chrome_args.remove(original_args[arg_key]) 112 self._chrome_args.remove(original_args[arg_key])
109 self._chrome_args.add(override_arg) 113 self._chrome_args.add(override_arg)
110 114
111 def _StartDriver(self): 115 def _StartDriver(self):
112 """Parses the flags to pass to Chromium, then starts the ChromeDriver. 116 """Parses the flags to pass to Chromium, then starts the ChromeDriver.
117
118 If running Android, the Android package name is passed to ChromeDriver here.
113 """ 119 """
114 self._OverrideChromeArgs() 120 self._OverrideChromeArgs()
115 options = Options() 121 capabilities = {
116 for arg in self._chrome_args: 122 'loggingPrefs': {'performance': 'INFO'},
117 options.add_argument(arg) 123 'chromeOptions': {
118 capabilities = {'loggingPrefs': {'performance': 'INFO'}} 124 'args': list(self._chrome_args)
119 if self._flags.chrome_exec: 125 }
126 }
127 if self._flags.android:
128 capabilities['chromeOptions'].update({
129 'androidPackage': self._flags.android_package,
130 })
131 elif self._flags.chrome_exec:
120 capabilities['chrome.binary'] = self._flags.chrome_exec 132 capabilities['chrome.binary'] = self._flags.chrome_exec
121 driver = webdriver.Chrome(executable_path=self._flags.chrome_driver[0], 133 driver = webdriver.Chrome(executable_path=self._flags.chrome_driver[0],
122 chrome_options=options, desired_capabilities=capabilities) 134 desired_capabilities=capabilities)
123 driver.command_executor._commands.update({ 135 driver.command_executor._commands.update({
124 'getAvailableLogTypes': ('GET', '/session/$sessionId/log/types'), 136 'getAvailableLogTypes': ('GET', '/session/$sessionId/log/types'),
125 'getLog': ('POST', '/session/$sessionId/log')}) 137 'getLog': ('POST', '/session/$sessionId/log')})
126 self._driver = driver 138 self._driver = driver
127 139
128 def _StopDriver(self): 140 def _StopDriver(self):
129 """Nicely stops the ChromeDriver. 141 """Nicely stops the ChromeDriver.
130 """ 142 """
131 self._driver.quit() 143 self._driver.quit()
132 self._driver = None 144 self._driver = None
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 """ 368 """
357 sys.stderr.write("**************************************\n") 369 sys.stderr.write("**************************************\n")
358 sys.stderr.write("**************************************\n") 370 sys.stderr.write("**************************************\n")
359 sys.stderr.write("** **\n") 371 sys.stderr.write("** **\n")
360 sys.stderr.write("** TEST FAILURE **\n") 372 sys.stderr.write("** TEST FAILURE **\n")
361 sys.stderr.write("** **\n") 373 sys.stderr.write("** **\n")
362 sys.stderr.write("**************************************\n") 374 sys.stderr.write("**************************************\n")
363 sys.stderr.write("**************************************\n") 375 sys.stderr.write("**************************************\n")
364 sys.stderr.write(msg, '\n') 376 sys.stderr.write(msg, '\n')
365 sys.exit(1) 377 sys.exit(1)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698