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

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

Issue 613163004: [chromedriver] setting browser default download directory (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2013 The Chromium Authors. All rights reserved. 2 # Copyright 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """End to end tests for ChromeDriver.""" 6 """End to end tests for ChromeDriver."""
7 7
8 import base64 8 import base64
9 import json 9 import json
10 import math 10 import math
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 'ChromeDriverTest.testSwitchToWindow', 133 'ChromeDriverTest.testSwitchToWindow',
134 'ChromeDriverTest.testShouldHandleNewWindowLoadingProperly', 134 'ChromeDriverTest.testShouldHandleNewWindowLoadingProperly',
135 ] 135 ]
136 ) 136 )
137 _ANDROID_NEGATIVE_FILTER['chromedriver_webview_shell'] = ( 137 _ANDROID_NEGATIVE_FILTER['chromedriver_webview_shell'] = (
138 _ANDROID_NEGATIVE_FILTER['chrome_shell']) 138 _ANDROID_NEGATIVE_FILTER['chrome_shell'])
139 139
140 140
141 class ChromeDriverBaseTest(unittest.TestCase): 141 class ChromeDriverBaseTest(unittest.TestCase):
142 """Base class for testing chromedriver functionalities.""" 142 """Base class for testing chromedriver functionalities."""
143 143
144 download_dir = tempfile.mkdtemp(dir='/tmp')
samuong 2014/10/01 20:22:12 This is going to be used by all tests, which is no
andrewcheng 2014/10/08 22:08:26 def setUp(self): if self._testMethodName == 't
145
144 def __init__(self, *args, **kwargs): 146 def __init__(self, *args, **kwargs):
145 super(ChromeDriverBaseTest, self).__init__(*args, **kwargs) 147 super(ChromeDriverBaseTest, self).__init__(*args, **kwargs)
146 self._drivers = [] 148 self._drivers = []
147 149
148 def tearDown(self): 150 def tearDown(self):
149 for driver in self._drivers: 151 for driver in self._drivers:
150 try: 152 try:
151 driver.Quit() 153 driver.Quit()
152 except: 154 except:
153 pass 155 pass
154 156
155 def CreateDriver(self, server_url=None, **kwargs): 157 def CreateDriver(self, server_url=None, **kwargs):
156 if server_url is None: 158 if server_url is None:
157 server_url = _CHROMEDRIVER_SERVER_URL 159 server_url = _CHROMEDRIVER_SERVER_URL
158 160
159 android_package = None 161 android_package = None
160 android_activity = None 162 android_activity = None
161 android_process = None 163 android_process = None
162 if _ANDROID_PACKAGE_KEY: 164 if _ANDROID_PACKAGE_KEY:
163 android_package = constants.PACKAGE_INFO[_ANDROID_PACKAGE_KEY].package 165 android_package = constants.PACKAGE_INFO[_ANDROID_PACKAGE_KEY].package
164 if _ANDROID_PACKAGE_KEY == 'chromedriver_webview_shell': 166 if _ANDROID_PACKAGE_KEY == 'chromedriver_webview_shell':
165 android_activity = constants.PACKAGE_INFO[_ANDROID_PACKAGE_KEY].activity 167 android_activity = constants.PACKAGE_INFO[_ANDROID_PACKAGE_KEY].activity
166 android_process = '%s:main' % android_package 168 android_process = '%s:main' % android_package
167 169
168 driver = chromedriver.ChromeDriver(server_url, 170 driver = chromedriver.ChromeDriver(server_url, self.download_dir,
169 chrome_binary=_CHROME_BINARY, 171 chrome_binary=_CHROME_BINARY,
170 android_package=android_package, 172 android_package=android_package,
171 android_activity=android_activity, 173 android_activity=android_activity,
172 android_process=android_process, 174 android_process=android_process,
173 **kwargs) 175 **kwargs)
174 self._drivers += [driver] 176 self._drivers += [driver]
175 return driver 177 return driver
176 178
177 179
178 class ChromeDriverTest(ChromeDriverBaseTest): 180 class ChromeDriverTest(ChromeDriverBaseTest):
179 """End to end tests for ChromeDriver.""" 181 """End to end tests for ChromeDriver."""
180 182
181 @staticmethod 183 @staticmethod
182 def GlobalSetUp(): 184 def GlobalSetUp():
183 ChromeDriverTest._http_server = webserver.WebServer( 185 ChromeDriverTest._http_server = webserver.WebServer(
184 chrome_paths.GetTestData()) 186 chrome_paths.GetTestData())
185 ChromeDriverTest._sync_server = webserver.SyncWebServer() 187 ChromeDriverTest._sync_server = webserver.SyncWebServer()
186 if _ANDROID_PACKAGE_KEY: 188 if _ANDROID_PACKAGE_KEY:
187 ChromeDriverTest._device = device_utils.DeviceUtils( 189 ChromeDriverTest._device = device_utils.DeviceUtils(
188 android_commands.GetAttachedDevices()[0]) 190 android_commands.GetAttachedDevices()[0])
189 http_host_port = ChromeDriverTest._http_server._server.server_port 191 http_host_port = ChromeDriverTest._http_server._server.server_port
190 sync_host_port = ChromeDriverTest._sync_server._server.server_port 192 sync_host_port = ChromeDriverTest._sync_server._server.server_port
(...skipping 10 matching lines...) Expand all
201 @staticmethod 203 @staticmethod
202 def GetHttpUrlForFile(file_path): 204 def GetHttpUrlForFile(file_path):
203 return ChromeDriverTest._http_server.GetUrl() + file_path 205 return ChromeDriverTest._http_server.GetUrl() + file_path
204 206
205 def setUp(self): 207 def setUp(self):
206 self._driver = self.CreateDriver() 208 self._driver = self.CreateDriver()
207 209
208 def testStartStop(self): 210 def testStartStop(self):
209 pass 211 pass
210 212
213 def testFileDownLoad(self):
214 self._driver.Load(self.GetHttpUrlForFile('/chromedriver/download.html'))
samuong 2014/10/01 20:22:12 Before clicking, please also add a check that ensu
andrewcheng 2014/10/08 22:08:26 Done.
andrewcheng 2014/10/08 22:08:26 This is a random generated dir - very unlikely, a
215 self._driver.FindElement('id', 'red-dot').Click()
216 time.sleep(0.5)
samuong 2014/10/01 20:22:13 I'm a bit worried that this is going to be flaky,
andrewcheng 2014/10/08 22:08:26 download_name = ChromeDriverBaseTest.download_dir
217 download_name = ChromeDriverBaseTest.download_dir+"/a_red_dot.png";
samuong 2014/10/01 20:22:12 minor style nit: please put spaces around the + W
andrewcheng 2014/10/08 22:08:26 Done.
218 self.assertTrue(os.path.isfile(download_name), "Test user prefer download di rectory failed!")
samuong 2014/10/01 20:22:12 Another style nit: please keep lines within 80 cha
andrewcheng 2014/10/08 22:08:26 Done.
219 os.remove(download_name)
220 os.removedirs(ChromeDriverBaseTest.download_dir)
samuong 2014/10/01 20:22:12 If we add another test that uses the download dire
andrewcheng 2014/10/08 22:08:26 Done. def tearDown(self): try: if
221
211 def testLoadUrl(self): 222 def testLoadUrl(self):
212 self._driver.Load(self.GetHttpUrlForFile('/chromedriver/empty.html')) 223 self._driver.Load(self.GetHttpUrlForFile('/chromedriver/empty.html'))
213 224
214 def testGetCurrentWindowHandle(self): 225 def testGetCurrentWindowHandle(self):
215 self._driver.GetCurrentWindowHandle() 226 self._driver.GetCurrentWindowHandle()
216 227
217 def _WaitForNewWindow(self, old_handles): 228 def _WaitForNewWindow(self, old_handles):
218 """Wait for at least one new window to show up in 20 seconds. 229 """Wait for at least one new window to show up in 20 seconds.
219 230
220 Args: 231 Args:
(...skipping 950 matching lines...) Expand 10 before | Expand all | Expand 10 after
1171 1182
1172 all_tests_suite = unittest.defaultTestLoader.loadTestsFromModule( 1183 all_tests_suite = unittest.defaultTestLoader.loadTestsFromModule(
1173 sys.modules[__name__]) 1184 sys.modules[__name__])
1174 tests = unittest_util.FilterTestSuite(all_tests_suite, options.filter) 1185 tests = unittest_util.FilterTestSuite(all_tests_suite, options.filter)
1175 ChromeDriverTest.GlobalSetUp() 1186 ChromeDriverTest.GlobalSetUp()
1176 MobileEmulationCapabilityTest.GlobalSetUp() 1187 MobileEmulationCapabilityTest.GlobalSetUp()
1177 result = unittest.TextTestRunner(stream=sys.stdout, verbosity=2).run(tests) 1188 result = unittest.TextTestRunner(stream=sys.stdout, verbosity=2).run(tests)
1178 ChromeDriverTest.GlobalTearDown() 1189 ChromeDriverTest.GlobalTearDown()
1179 MobileEmulationCapabilityTest.GlobalTearDown() 1190 MobileEmulationCapabilityTest.GlobalTearDown()
1180 sys.exit(len(result.failures) + len(result.errors)) 1191 sys.exit(len(result.failures) + len(result.errors))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698