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

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

Issue 11414267: Fix finding chrome binary for ChromeDriver. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/test/chromedriver/run_all_tests.py » ('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 (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 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 ctypes 5 import ctypes
6 import json 6 import json
7 7
8 class ChromeDriverException(Exception): 8 class ChromeDriverException(Exception):
9 pass 9 pass
10 class UnknownCommand(ChromeDriverException): 10 class UnknownCommand(ChromeDriverException):
(...skipping 12 matching lines...) Expand all
23 33: SessionNotCreatedException, 23 33: SessionNotCreatedException,
24 100: NoSuchSession 24 100: NoSuchSession
25 } 25 }
26 status = response['status'] 26 status = response['status']
27 msg = response['value']['message'] 27 msg = response['value']['message']
28 return exception_class_map.get(status, ChromeDriverException)(msg) 28 return exception_class_map.get(status, ChromeDriverException)(msg)
29 29
30 class ChromeDriver(object): 30 class ChromeDriver(object):
31 """Starts and controls a single Chrome instance on this machine.""" 31 """Starts and controls a single Chrome instance on this machine."""
32 32
33 def __init__(self, lib_path): 33 def __init__(self, lib_path, chrome_binary=None):
34 self._lib = ctypes.CDLL(lib_path) 34 self._lib = ctypes.CDLL(lib_path)
35 self._session_id = self._ExecuteCommand('newSession') 35 if chrome_binary is None:
36 params = {}
37 else:
38 params = {
39 'desiredCapabilities': {
40 'chrome': {
41 'binary': chrome_binary
42 }
43 }
44 }
45 self._session_id = self._ExecuteCommand('newSession', params)
36 46
37 def _ExecuteCommand(self, name, params={}, session_id=''): 47 def _ExecuteCommand(self, name, params={}, session_id=''):
38 cmd = { 48 cmd = {
39 'name': name, 49 'name': name,
40 'parameters': params, 50 'parameters': params,
41 'sessionId': session_id 51 'sessionId': session_id
42 } 52 }
43 cmd_json = json.dumps(cmd) 53 cmd_json = json.dumps(cmd)
44 response_data = ctypes.c_char_p() 54 response_data = ctypes.c_char_p()
45 response_size = ctypes.c_uint() 55 response_size = ctypes.c_uint()
46 self._lib.ExecuteCommand( 56 self._lib.ExecuteCommand(
47 ctypes.c_char_p(cmd_json), 57 ctypes.c_char_p(cmd_json),
48 ctypes.c_uint(len(cmd_json)), 58 ctypes.c_uint(len(cmd_json)),
49 ctypes.byref(response_data), 59 ctypes.byref(response_data),
50 ctypes.byref(response_size)) 60 ctypes.byref(response_size))
51 response_json = ctypes.string_at(response_data, response_size.value) 61 response_json = ctypes.string_at(response_data, response_size.value)
52 self._lib.Free(response_data) 62 self._lib.Free(response_data)
53 response = json.loads(response_json) 63 response = json.loads(response_json)
54 if response['status'] != 0: 64 if response['status'] != 0:
55 raise _ExceptionForResponse(response) 65 raise _ExceptionForResponse(response)
56 return response['value'] 66 return response['value']
57 67
58 def _ExecuteSessionCommand(self, name, params={}): 68 def _ExecuteSessionCommand(self, name, params={}):
59 return self._ExecuteCommand(name, params, self._session_id) 69 return self._ExecuteCommand(name, params, self._session_id)
60 70
61 def Quit(self): 71 def Quit(self):
62 """Quits the browser and ends the session.""" 72 """Quits the browser and ends the session."""
63 self._ExecuteSessionCommand('quit') 73 self._ExecuteSessionCommand('quit')
OLDNEW
« no previous file with comments | « no previous file | chrome/test/chromedriver/run_all_tests.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698