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 sys | 5 import sys |
6 import platform | 6 import platform |
7 | 7 |
8 import command_executor | 8 import command_executor |
9 from command_executor import Command | 9 from command_executor import Command |
10 from webelement import WebElement | 10 from webelement import WebElement |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 """Starts and controls a single Chrome instance on this machine.""" | 106 """Starts and controls a single Chrome instance on this machine.""" |
107 | 107 |
108 def __init__(self, server_url, chrome_binary=None, android_package=None, | 108 def __init__(self, server_url, chrome_binary=None, android_package=None, |
109 android_activity=None, android_process=None, | 109 android_activity=None, android_process=None, |
110 android_use_running_app=None, chrome_switches=None, | 110 android_use_running_app=None, chrome_switches=None, |
111 chrome_extensions=None, chrome_log_path=None, | 111 chrome_extensions=None, chrome_log_path=None, |
112 debugger_address=None, logging_prefs=None, | 112 debugger_address=None, logging_prefs=None, |
113 mobile_emulation=None, experimental_options=None, | 113 mobile_emulation=None, experimental_options=None, |
114 download_dir=None, network_connection=None, | 114 download_dir=None, network_connection=None, |
115 send_w3c_capability=None, send_w3c_request=None, | 115 send_w3c_capability=None, send_w3c_request=None, |
116 page_load_strategy=None, unexpected_alert_behaviour=None): | 116 page_load_strategy=None, unexpected_alert_behaviour=None, |
| 117 devtools_events_to_log=None): |
117 self._executor = command_executor.CommandExecutor(server_url) | 118 self._executor = command_executor.CommandExecutor(server_url) |
118 | 119 |
119 options = {} | 120 options = {} |
120 | 121 |
121 if experimental_options: | 122 if experimental_options: |
122 assert isinstance(experimental_options, dict) | 123 assert isinstance(experimental_options, dict) |
123 options = experimental_options.copy() | 124 options = experimental_options.copy() |
124 | 125 |
125 if android_package: | 126 if android_package: |
126 options['androidPackage'] = android_package | 127 options['androidPackage'] = android_package |
(...skipping 28 matching lines...) Expand all Loading... |
155 if chrome_log_path: | 156 if chrome_log_path: |
156 assert type(chrome_log_path) is str | 157 assert type(chrome_log_path) is str |
157 options['logPath'] = chrome_log_path | 158 options['logPath'] = chrome_log_path |
158 | 159 |
159 if debugger_address: | 160 if debugger_address: |
160 assert type(debugger_address) is str | 161 assert type(debugger_address) is str |
161 options['debuggerAddress'] = debugger_address | 162 options['debuggerAddress'] = debugger_address |
162 | 163 |
163 if logging_prefs: | 164 if logging_prefs: |
164 assert type(logging_prefs) is dict | 165 assert type(logging_prefs) is dict |
165 log_types = ['client', 'driver', 'browser', 'server', 'performance'] | 166 log_types = ['client', 'driver', 'browser', 'server', 'performance', |
| 167 'devtools'] |
166 log_levels = ['ALL', 'DEBUG', 'INFO', 'WARNING', 'SEVERE', 'OFF'] | 168 log_levels = ['ALL', 'DEBUG', 'INFO', 'WARNING', 'SEVERE', 'OFF'] |
167 for log_type, log_level in logging_prefs.iteritems(): | 169 for log_type, log_level in logging_prefs.iteritems(): |
168 assert log_type in log_types | 170 assert log_type in log_types |
169 assert log_level in log_levels | 171 assert log_level in log_levels |
170 else: | 172 else: |
171 logging_prefs = {} | 173 logging_prefs = {} |
172 | 174 |
| 175 if devtools_events_to_log: |
| 176 assert type(devtools_events_to_log) is list |
| 177 options['devToolsEventsToLog'] = devtools_events_to_log |
| 178 |
173 download_prefs = {} | 179 download_prefs = {} |
174 if download_dir: | 180 if download_dir: |
175 if 'prefs' not in options: | 181 if 'prefs' not in options: |
176 options['prefs'] = {} | 182 options['prefs'] = {} |
177 if 'download' not in options['prefs']: | 183 if 'download' not in options['prefs']: |
178 options['prefs']['download'] = {} | 184 options['prefs']['download'] = {} |
179 options['prefs']['download']['default_directory'] = download_dir | 185 options['prefs']['download']['default_directory'] = download_dir |
180 | 186 |
181 if send_w3c_capability: | 187 if send_w3c_capability: |
182 options['w3c'] = send_w3c_capability | 188 options['w3c'] = send_w3c_capability |
(...skipping 305 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 |