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

Unified Diff: chrome/test/chromedriver/test/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: Modified codes based on reviewer's comments 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/chromedriver/test/run_py_tests.py
diff --git a/chrome/test/chromedriver/test/run_py_tests.py b/chrome/test/chromedriver/test/run_py_tests.py
index 2b106a6783a372544520a9fcae0f182b673be9e2..fec08a07603da7799cfde54e98c33245f0051c9e 100755
--- a/chrome/test/chromedriver/test/run_py_tests.py
+++ b/chrome/test/chromedriver/test/run_py_tests.py
@@ -152,7 +152,7 @@ class ChromeDriverBaseTest(unittest.TestCase):
except:
pass
- def CreateDriver(self, server_url=None, **kwargs):
+ def CreateDriver(self, server_url=None, download_dir=None, **kwargs):
if server_url is None:
server_url = _CHROMEDRIVER_SERVER_URL
@@ -170,6 +170,7 @@ class ChromeDriverBaseTest(unittest.TestCase):
android_package=android_package,
android_activity=android_activity,
android_process=android_process,
+ download_dir=download_dir,
**kwargs)
self._drivers += [driver]
return driver
@@ -223,8 +224,8 @@ class ChromeDriverTest(ChromeDriverBaseTest):
Returns:
Handle to a new window. None if timeout.
"""
- timeout = time.time() + 20
- while time.time() < timeout:
+ deadline = time.time() + 20
+ while time.time() < deadline:
new_handles = self._driver.GetWindowHandles()
if len(new_handles) > len(old_handles):
for index, old_handle in enumerate(old_handles):
@@ -750,6 +751,62 @@ class ChromeDriverAndroidTest(ChromeDriverBaseTest):
self._drivers[0].Quit()
self._drivers[0] = self.CreateDriver()
+class ChromeDownloadDirTest(ChromeDriverBaseTest):
+
+ def testFileDownLoad(self):
+ self.download_dir = tempfile.mkdtemp()
samuong 2014/10/17 21:52:25 let's either put this in setUp() or a try-finally
andrewcheng 2014/10/17 22:59:56 Done.
+ download_name = os.path.join(self.download_dir, 'a_red_dot.png')
+ driver = self.CreateDriver(download_dir=self.download_dir)
+ driver.Load(ChromeDriverTest._http_server.GetUrl() +
+ '/chromedriver/download.html')
+ driver.FindElement('id', 'red-dot').Click()
+ # wait until download completed
+ deadline = time.time() + 60 * 1 # 1 minutes from now
+ while True:
+ time.sleep(0.1)
+ if os.path.isfile(download_name) or time.time() > deadline:
+ break
+
+ self.assertTrue(os.path.isfile(download_name),
+ "Failed to download file!")
samuong 2014/10/17 21:52:25 you could fit this whole assertion on a single lin
andrewcheng 2014/10/17 22:59:56 Done.
+ os.remove(download_name)
+ try:
+ if self.download_dir:
+ os.removedirs(self.download_dir)
+ self.download_dir = None
+ except:
+ self.assertRaises(chromedriver.UnknownError)
samuong 2014/10/17 21:52:25 i think we can delete this try-except block if you
andrewcheng 2014/10/17 22:59:56 Done.
+
+ """ test existing prefence profile - check setting if it is correct """
samuong 2014/10/17 21:52:25 unlike javadoc and doxygen, python docstrings go i
andrewcheng 2014/10/17 22:59:56 Done.
+ def testDownloadDirectoryOverridesExistingPreferences(self):
+ user_data_dir = tempfile.mkdtemp()
+ tmp_download_dir = tempfile.mkdtemp()
+ sub_dir = os.path.join(user_data_dir, 'Default')
+ os.mkdir(sub_dir)
+ prefs_file_path = os.path.join(sub_dir, 'Preferences')
samuong 2014/10/17 21:52:25 don't forget to clean all this up after the test f
andrewcheng 2014/10/17 22:59:56 Done.
+
+ prefs = {
+ 'test': 'this should not be changed',
+ 'download': {
+ 'default_directory': '/old/download/directory'
+ }
+ }
+
+ with open(prefs_file_path, 'w') as f:
+ json.dump(prefs, f)
+
+ driver = self.CreateDriver(chrome_switches=
+ ['user-data-dir=' + user_data_dir],
+ download_dir = tmp_download_dir)
+
+ with open(prefs_file_path) as f:
+ prefs = json.load(f)
+ self.assertEqual(prefs['test'], 'this should not be changed',
+ "Existing preference was unexpectedly overridden")
+ download = prefs['download']
+ self.assertEqual(download['default_directory'],
+ tmp_download_dir,
+ 'Download directory preference was not updated to match capabilities')
class ChromeSwitchesCapabilityTest(ChromeDriverBaseTest):
"""Tests that chromedriver properly processes chromeOptions.args capabilities.

Powered by Google App Engine
This is Rietveld 408576698