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

Side by Side Diff: chrome/test/chromedriver/client/chromedriver.py

Issue 2230053002: [chromedriver] Added option to make element references W3C compliant. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed presubmit errors. Created 4 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 | « chrome/test/chromedriver/chrome_launcher.cc ('k') | chrome/test/chromedriver/commands.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 11
12 ELEMENT_KEY_W3C = "element-6066-11e4-a52e-4f735466cecf"
13 ELEMENT_KEY = "ELEMENT"
12 14
13 class ChromeDriverException(Exception): 15 class ChromeDriverException(Exception):
14 pass 16 pass
15 class NoSuchElement(ChromeDriverException): 17 class NoSuchElement(ChromeDriverException):
16 pass 18 pass
17 class NoSuchFrame(ChromeDriverException): 19 class NoSuchFrame(ChromeDriverException):
18 pass 20 pass
19 class UnknownCommand(ChromeDriverException): 21 class UnknownCommand(ChromeDriverException):
20 pass 22 pass
21 class StaleElementReference(ChromeDriverException): 23 class StaleElementReference(ChromeDriverException):
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 if isinstance(response['status'], basestring): 203 if isinstance(response['status'], basestring):
202 self.w3c_compliant = True 204 self.w3c_compliant = True
203 elif isinstance(response['status'], int): 205 elif isinstance(response['status'], int):
204 self.w3c_compliant = False 206 self.w3c_compliant = False
205 else: 207 else:
206 raise UnknownError("unexpected response") 208 raise UnknownError("unexpected response")
207 209
208 self._session_id = response['sessionId'] 210 self._session_id = response['sessionId']
209 self.capabilities = self._UnwrapValue(response['value']) 211 self.capabilities = self._UnwrapValue(response['value'])
210 212
213
211 def _WrapValue(self, value): 214 def _WrapValue(self, value):
212 """Wrap value from client side for chromedriver side.""" 215 """Wrap value from client side for chromedriver side."""
213 if isinstance(value, dict): 216 if isinstance(value, dict):
214 converted = {} 217 converted = {}
215 for key, val in value.items(): 218 for key, val in value.items():
216 converted[key] = self._WrapValue(val) 219 converted[key] = self._WrapValue(val)
217 return converted 220 return converted
218 elif isinstance(value, WebElement): 221 elif isinstance(value, WebElement):
219 return {'ELEMENT': value._id} 222 if (self.w3c_compliant):
223 return {ELEMENT_KEY_W3C: value._id}
224 else:
225 return {ELEMENT_KEY: value._id}
220 elif isinstance(value, list): 226 elif isinstance(value, list):
221 return list(self._WrapValue(item) for item in value) 227 return list(self._WrapValue(item) for item in value)
222 else: 228 else:
223 return value 229 return value
224 230
225 def _UnwrapValue(self, value): 231 def _UnwrapValue(self, value):
226 """Unwrap value from chromedriver side for client side."""
227 if isinstance(value, dict): 232 if isinstance(value, dict):
228 if (len(value) == 1 and 'ELEMENT' in value 233 if (self.w3c_compliant and len(value) == 1
229 and isinstance(value['ELEMENT'], basestring)): 234 and ELEMENT_KEY_W3C in value
230 return WebElement(self, value['ELEMENT']) 235 and isinstance(
236 value[ELEMENT_KEY_W3C], basestring)):
237 return WebElement(self, value[ELEMENT_KEY_W3C])
238 elif (len(value) == 1 and ELEMENT_KEY in value
239 and isinstance(value[ELEMENT_KEY], basestring)):
240 return WebElement(self, value[ELEMENT_KEY])
231 else: 241 else:
232 unwraped = {} 242 unwraped = {}
233 for key, val in value.items(): 243 for key, val in value.items():
234 unwraped[key] = self._UnwrapValue(val) 244 unwraped[key] = self._UnwrapValue(val)
235 return unwraped 245 return unwraped
236 elif isinstance(value, list): 246 elif isinstance(value, list):
237 return list(self._UnwrapValue(item) for item in value) 247 return list(self._UnwrapValue(item) for item in value)
238 else: 248 else:
239 return value 249 return value
240 250
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 482
473 def GetNetworkConnection(self): 483 def GetNetworkConnection(self):
474 return self.ExecuteCommand(Command.GET_NETWORK_CONNECTION) 484 return self.ExecuteCommand(Command.GET_NETWORK_CONNECTION)
475 485
476 def DeleteNetworkConditions(self): 486 def DeleteNetworkConditions(self):
477 self.ExecuteCommand(Command.DELETE_NETWORK_CONDITIONS) 487 self.ExecuteCommand(Command.DELETE_NETWORK_CONDITIONS)
478 488
479 def SetNetworkConnection(self, connection_type): 489 def SetNetworkConnection(self, connection_type):
480 params = {'parameters': {'type': connection_type}} 490 params = {'parameters': {'type': connection_type}}
481 self.ExecuteCommand(Command.SET_NETWORK_CONNECTION, params) 491 self.ExecuteCommand(Command.SET_NETWORK_CONNECTION, params)
OLDNEW
« no previous file with comments | « chrome/test/chromedriver/chrome_launcher.cc ('k') | chrome/test/chromedriver/commands.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698