| 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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 class ChromeDriver(object): | 106 class ChromeDriver(object): |
| 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_request=None, |
| 117 page_load_strategy=None, unexpected_alert_behaviour=None): | 117 page_load_strategy=None, unexpected_alert_behaviour=None): |
| 118 self._executor = command_executor.CommandExecutor(server_url) | 118 self._executor = command_executor.CommandExecutor(server_url) |
| 119 | 119 |
| 120 options = {} | 120 options = {} |
| 121 | 121 |
| 122 if experimental_options: | 122 if experimental_options: |
| 123 assert isinstance(experimental_options, dict) | 123 assert isinstance(experimental_options, dict) |
| 124 options = experimental_options.copy() | 124 options = experimental_options.copy() |
| 125 | 125 |
| 126 if android_package: | 126 if android_package: |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 logging_prefs = {} | 173 logging_prefs = {} |
| 174 | 174 |
| 175 download_prefs = {} | 175 download_prefs = {} |
| 176 if download_dir: | 176 if download_dir: |
| 177 if 'prefs' not in options: | 177 if 'prefs' not in options: |
| 178 options['prefs'] = {} | 178 options['prefs'] = {} |
| 179 if 'download' not in options['prefs']: | 179 if 'download' not in options['prefs']: |
| 180 options['prefs']['download'] = {} | 180 options['prefs']['download'] = {} |
| 181 options['prefs']['download']['default_directory'] = download_dir | 181 options['prefs']['download']['default_directory'] = download_dir |
| 182 | 182 |
| 183 if send_w3c_capability: | |
| 184 options['w3c'] = send_w3c_capability | |
| 185 | |
| 186 params = { | 183 params = { |
| 187 'desiredCapabilities': { | |
| 188 'chromeOptions': options, | 184 'chromeOptions': options, |
| 189 'loggingPrefs': logging_prefs | 185 'loggingPrefs': logging_prefs |
| 190 } | |
| 191 } | 186 } |
| 192 | 187 |
| 193 if page_load_strategy: | 188 if page_load_strategy: |
| 194 assert type(page_load_strategy) is str | 189 assert type(page_load_strategy) is str |
| 195 params['desiredCapabilities']['pageLoadStrategy'] = page_load_strategy | 190 params['pageLoadStrategy'] = page_load_strategy |
| 196 | 191 |
| 197 if unexpected_alert_behaviour: | 192 if unexpected_alert_behaviour: |
| 198 assert type(unexpected_alert_behaviour) is str | 193 assert type(unexpected_alert_behaviour) is str |
| 199 params['desiredCapabilities']['unexpectedAlertBehaviour'] = ( | 194 params['unexpectedAlertBehaviour'] = unexpected_alert_behaviour |
| 200 unexpected_alert_behaviour) | |
| 201 | 195 |
| 202 if network_connection: | 196 if network_connection: |
| 203 params['desiredCapabilities']['networkConnectionEnabled'] = ( | 197 params['networkConnectionEnabled'] = network_connection |
| 204 network_connection) | |
| 205 | 198 |
| 206 if send_w3c_request: | 199 if send_w3c_request: |
| 207 params = {'capabilities': params} | 200 params = {'capabilities': {'alwaysMatch': params}} |
| 201 else: |
| 202 params = {'desiredCapabilities': params} |
| 208 | 203 |
| 209 response = self._ExecuteCommand(Command.NEW_SESSION, params) | 204 response = self._ExecuteCommand(Command.NEW_SESSION, params) |
| 210 if isinstance(response['status'], basestring): | 205 if isinstance(response['status'], basestring): |
| 211 self.w3c_compliant = True | 206 self.w3c_compliant = True |
| 212 elif isinstance(response['status'], int): | 207 elif isinstance(response['status'], int): |
| 213 self.w3c_compliant = False | 208 self.w3c_compliant = False |
| 214 else: | 209 else: |
| 215 raise UnknownError("unexpected response") | 210 raise UnknownError("unexpected response") |
| 216 | 211 |
| 217 self._session_id = response['sessionId'] | 212 self._session_id = response['sessionId'] |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 self.ExecuteCommand(Command.DELETE_SCREEN_ORIENTATION) | 506 self.ExecuteCommand(Command.DELETE_SCREEN_ORIENTATION) |
| 512 | 507 |
| 513 def SendKeys(self, *values): | 508 def SendKeys(self, *values): |
| 514 typing = [] | 509 typing = [] |
| 515 for value in values: | 510 for value in values: |
| 516 if isinstance(value, int): | 511 if isinstance(value, int): |
| 517 value = str(value) | 512 value = str(value) |
| 518 for i in range(len(value)): | 513 for i in range(len(value)): |
| 519 typing.append(value[i]) | 514 typing.append(value[i]) |
| 520 self.ExecuteCommand(Command.SEND_KEYS_TO_ACTIVE_ELEMENT, {'value': typing}) | 515 self.ExecuteCommand(Command.SEND_KEYS_TO_ACTIVE_ELEMENT, {'value': typing}) |
| OLD | NEW |