| OLD | NEW |
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 platform | 5 import platform |
| 6 import sys | 6 import sys |
| 7 import util | 7 import util |
| 8 | 8 |
| 9 import command_executor | 9 import command_executor |
| 10 from command_executor import Command | 10 from command_executor import Command |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 """Starts and controls a single Chrome instance on this machine.""" | 107 """Starts and controls a single Chrome instance on this machine.""" |
| 108 | 108 |
| 109 def __init__(self, server_url, chrome_binary=None, android_package=None, | 109 def __init__(self, server_url, chrome_binary=None, android_package=None, |
| 110 android_activity=None, android_process=None, | 110 android_activity=None, android_process=None, |
| 111 android_use_running_app=None, chrome_switches=None, | 111 android_use_running_app=None, chrome_switches=None, |
| 112 chrome_extensions=None, chrome_log_path=None, | 112 chrome_extensions=None, chrome_log_path=None, |
| 113 debugger_address=None, logging_prefs=None, | 113 debugger_address=None, logging_prefs=None, |
| 114 mobile_emulation=None, experimental_options=None, | 114 mobile_emulation=None, experimental_options=None, |
| 115 download_dir=None, network_connection=None, | 115 download_dir=None, network_connection=None, |
| 116 send_w3c_capability=None, send_w3c_request=None, | 116 send_w3c_capability=None, send_w3c_request=None, |
| 117 page_load_strategy=None, unexpected_alert_behaviour=None): | 117 page_load_strategy=None, unexpected_alert_behaviour=None, |
| 118 devtools_events_to_log=None): |
| 118 self._executor = command_executor.CommandExecutor(server_url) | 119 self._executor = command_executor.CommandExecutor(server_url) |
| 119 | 120 |
| 120 options = {} | 121 options = {} |
| 121 | 122 |
| 122 if experimental_options: | 123 if experimental_options: |
| 123 assert isinstance(experimental_options, dict) | 124 assert isinstance(experimental_options, dict) |
| 124 options = experimental_options.copy() | 125 options = experimental_options.copy() |
| 125 | 126 |
| 126 if android_package: | 127 if android_package: |
| 127 options['androidPackage'] = android_package | 128 options['androidPackage'] = android_package |
| (...skipping 29 matching lines...) Expand all Loading... |
| 157 if chrome_log_path: | 158 if chrome_log_path: |
| 158 assert type(chrome_log_path) is str | 159 assert type(chrome_log_path) is str |
| 159 options['logPath'] = chrome_log_path | 160 options['logPath'] = chrome_log_path |
| 160 | 161 |
| 161 if debugger_address: | 162 if debugger_address: |
| 162 assert type(debugger_address) is str | 163 assert type(debugger_address) is str |
| 163 options['debuggerAddress'] = debugger_address | 164 options['debuggerAddress'] = debugger_address |
| 164 | 165 |
| 165 if logging_prefs: | 166 if logging_prefs: |
| 166 assert type(logging_prefs) is dict | 167 assert type(logging_prefs) is dict |
| 167 log_types = ['client', 'driver', 'browser', 'server', 'performance'] | 168 log_types = ['client', 'driver', 'browser', 'server', 'performance', |
| 169 'devtools'] |
| 168 log_levels = ['ALL', 'DEBUG', 'INFO', 'WARNING', 'SEVERE', 'OFF'] | 170 log_levels = ['ALL', 'DEBUG', 'INFO', 'WARNING', 'SEVERE', 'OFF'] |
| 169 for log_type, log_level in logging_prefs.iteritems(): | 171 for log_type, log_level in logging_prefs.iteritems(): |
| 170 assert log_type in log_types | 172 assert log_type in log_types |
| 171 assert log_level in log_levels | 173 assert log_level in log_levels |
| 172 else: | 174 else: |
| 173 logging_prefs = {} | 175 logging_prefs = {} |
| 174 | 176 |
| 177 if devtools_events_to_log: |
| 178 assert type(devtools_events_to_log) is list |
| 179 options['devToolsEventsToLog'] = devtools_events_to_log |
| 180 |
| 175 download_prefs = {} | 181 download_prefs = {} |
| 176 if download_dir: | 182 if download_dir: |
| 177 if 'prefs' not in options: | 183 if 'prefs' not in options: |
| 178 options['prefs'] = {} | 184 options['prefs'] = {} |
| 179 if 'download' not in options['prefs']: | 185 if 'download' not in options['prefs']: |
| 180 options['prefs']['download'] = {} | 186 options['prefs']['download'] = {} |
| 181 options['prefs']['download']['default_directory'] = download_dir | 187 options['prefs']['download']['default_directory'] = download_dir |
| 182 | 188 |
| 183 if send_w3c_capability: | 189 if send_w3c_capability: |
| 184 options['w3c'] = send_w3c_capability | 190 options['w3c'] = send_w3c_capability |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 def GetNetworkConnection(self): | 494 def GetNetworkConnection(self): |
| 489 return self.ExecuteCommand(Command.GET_NETWORK_CONNECTION) | 495 return self.ExecuteCommand(Command.GET_NETWORK_CONNECTION) |
| 490 | 496 |
| 491 def DeleteNetworkConditions(self): | 497 def DeleteNetworkConditions(self): |
| 492 self.ExecuteCommand(Command.DELETE_NETWORK_CONDITIONS) | 498 self.ExecuteCommand(Command.DELETE_NETWORK_CONDITIONS) |
| 493 | 499 |
| 494 def SetNetworkConnection(self, connection_type): | 500 def SetNetworkConnection(self, connection_type): |
| 495 params = {'parameters': {'type': connection_type}} | 501 params = {'parameters': {'type': connection_type}} |
| 496 return self.ExecuteCommand(Command.SET_NETWORK_CONNECTION, params) | 502 return self.ExecuteCommand(Command.SET_NETWORK_CONNECTION, params) |
| 497 | 503 |
| 504 def SendCommand(self, cmd, cmd_params): |
| 505 params = {'parameters': {'cmd': cmd, 'params': cmd_params}}; |
| 506 return self.ExecuteCommand(Command.SEND_COMMAND, params) |
| 507 |
| 508 def SendCommandAndGetResult(self, cmd, cmd_params): |
| 509 params = {'cmd': cmd, 'params': cmd_params}; |
| 510 return self.ExecuteCommand(Command.SEND_COMMAND_AND_GET_RESULT, params) |
| 511 |
| 498 def GetScreenOrientation(self): | 512 def GetScreenOrientation(self): |
| 499 screen_orientation = self.ExecuteCommand(Command.GET_SCREEN_ORIENTATION) | 513 screen_orientation = self.ExecuteCommand(Command.GET_SCREEN_ORIENTATION) |
| 500 return { | 514 return { |
| 501 'orientation': screen_orientation['orientation'] | 515 'orientation': screen_orientation['orientation'] |
| 502 } | 516 } |
| 503 | 517 |
| 504 def SetScreenOrientation(self, orientation_type): | 518 def SetScreenOrientation(self, orientation_type): |
| 505 params = {'parameters': {'orientation': orientation_type}} | 519 params = {'parameters': {'orientation': orientation_type}} |
| 506 self.ExecuteCommand(Command.SET_SCREEN_ORIENTATION, params) | 520 self.ExecuteCommand(Command.SET_SCREEN_ORIENTATION, params) |
| 507 | 521 |
| 508 def DeleteScreenOrientationLock(self): | 522 def DeleteScreenOrientationLock(self): |
| 509 self.ExecuteCommand(Command.DELETE_SCREEN_ORIENTATION) | 523 self.ExecuteCommand(Command.DELETE_SCREEN_ORIENTATION) |
| 510 | 524 |
| 511 def SendKeys(self, *values): | 525 def SendKeys(self, *values): |
| 512 typing = [] | 526 typing = [] |
| 513 for value in values: | 527 for value in values: |
| 514 if isinstance(value, int): | 528 if isinstance(value, int): |
| 515 value = str(value) | 529 value = str(value) |
| 516 for i in range(len(value)): | 530 for i in range(len(value)): |
| 517 typing.append(value[i]) | 531 typing.append(value[i]) |
| 518 self.ExecuteCommand(Command.SEND_KEYS_TO_ACTIVE_ELEMENT, {'value': typing}) | 532 self.ExecuteCommand(Command.SEND_KEYS_TO_ACTIVE_ELEMENT, {'value': typing}) |
| OLD | NEW |