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

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

Issue 12224106: [chromedriver] Implement command: switchToWindow. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments. Created 7 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/test/chromedriver/command_executor_impl.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 (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 from webelement import WebElement 8 from webelement import WebElement
9 9
10 class ChromeDriverException(Exception): 10 class ChromeDriverException(Exception):
11 pass 11 pass
12 class NoSuchElement(ChromeDriverException): 12 class NoSuchElement(ChromeDriverException):
13 pass 13 pass
14 class UnknownCommand(ChromeDriverException): 14 class UnknownCommand(ChromeDriverException):
15 pass 15 pass
16 class StaleElementReference(ChromeDriverException): 16 class StaleElementReference(ChromeDriverException):
17 pass 17 pass
18 class UnknownError(ChromeDriverException): 18 class UnknownError(ChromeDriverException):
19 pass 19 pass
20 class XPathLookupError(ChromeDriverException): 20 class XPathLookupError(ChromeDriverException):
21 pass 21 pass
22 class NoSuchWindow(ChromeDriverException):
23 pass
22 class InvalidSelector(ChromeDriverException): 24 class InvalidSelector(ChromeDriverException):
23 pass 25 pass
24 class SessionNotCreatedException(ChromeDriverException): 26 class SessionNotCreatedException(ChromeDriverException):
25 pass 27 pass
26 class NoSuchSession(ChromeDriverException): 28 class NoSuchSession(ChromeDriverException):
27 pass 29 pass
28 30
29 def _ExceptionForResponse(response): 31 def _ExceptionForResponse(response):
30 exception_class_map = { 32 exception_class_map = {
31 7: NoSuchElement, 33 7: NoSuchElement,
32 9: UnknownCommand, 34 9: UnknownCommand,
33 10: StaleElementReference, 35 10: StaleElementReference,
34 13: UnknownError, 36 13: UnknownError,
35 19: XPathLookupError, 37 19: XPathLookupError,
38 23: NoSuchWindow,
36 32: InvalidSelector, 39 32: InvalidSelector,
37 33: SessionNotCreatedException, 40 33: SessionNotCreatedException,
38 100: NoSuchSession 41 100: NoSuchSession
39 } 42 }
40 status = response['status'] 43 status = response['status']
41 msg = response['value']['message'] 44 msg = response['value']['message']
42 return exception_class_map.get(status, ChromeDriverException)(msg) 45 return exception_class_map.get(status, ChromeDriverException)(msg)
43 46
44 class ChromeDriver(object): 47 class ChromeDriver(object):
45 """Starts and controls a single Chrome instance on this machine.""" 48 """Starts and controls a single Chrome instance on this machine."""
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 return response 122 return response
120 123
121 def ExecuteSessionCommand(self, name, params={}): 124 def ExecuteSessionCommand(self, name, params={}):
122 params = self._WrapValue(params) 125 params = self._WrapValue(params)
123 return self._UnwrapValue( 126 return self._UnwrapValue(
124 self._ExecuteCommand(name, params, self._session_id)['value']) 127 self._ExecuteCommand(name, params, self._session_id)['value'])
125 128
126 def GetWindowHandles(self): 129 def GetWindowHandles(self):
127 return self.ExecuteSessionCommand('getWindowHandles') 130 return self.ExecuteSessionCommand('getWindowHandles')
128 131
132 def SwitchToWindow(self, handle_or_name):
133 self.ExecuteSessionCommand('switchToWindow', {'name': handle_or_name})
134
129 def GetCurrentWindowHandle(self): 135 def GetCurrentWindowHandle(self):
130 return self.ExecuteSessionCommand('getCurrentWindowHandle') 136 return self.ExecuteSessionCommand('getCurrentWindowHandle')
131 137
132 def Load(self, url): 138 def Load(self, url):
133 self.ExecuteSessionCommand('get', {'url': url}) 139 self.ExecuteSessionCommand('get', {'url': url})
134 140
135 def ExecuteScript(self, script, *args): 141 def ExecuteScript(self, script, *args):
136 converted_args = list(args) 142 converted_args = list(args)
137 return self.ExecuteSessionCommand( 143 return self.ExecuteSessionCommand(
138 'executeScript', {'script': script, 'args': converted_args}) 144 'executeScript', {'script': script, 'args': converted_args})
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 197
192 def MouseButtonUp(self, button=0): 198 def MouseButtonUp(self, button=0):
193 self.ExecuteSessionCommand('mouseButtonUp', {'button': button}) 199 self.ExecuteSessionCommand('mouseButtonUp', {'button': button})
194 200
195 def MouseDoubleClick(self, button=0): 201 def MouseDoubleClick(self, button=0):
196 self.ExecuteSessionCommand('mouseDoubleClick', {'button': button}) 202 self.ExecuteSessionCommand('mouseDoubleClick', {'button': button})
197 203
198 def Quit(self): 204 def Quit(self):
199 """Quits the browser and ends the session.""" 205 """Quits the browser and ends the session."""
200 self.ExecuteSessionCommand('quit') 206 self.ExecuteSessionCommand('quit')
OLDNEW
« no previous file with comments | « no previous file | chrome/test/chromedriver/command_executor_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698