Chromium Code Reviews| Index: chrome/test/webdriver/chromedriver_tests.py |
| diff --git a/chrome/test/webdriver/chromedriver_tests.py b/chrome/test/webdriver/chromedriver_tests.py |
| index 28892e2c6bdab1c577d9cacefb42394ed6891882..bc88a5ad1718cb5855b7692d08c54458e8abe285 100755 |
| --- a/chrome/test/webdriver/chromedriver_tests.py |
| +++ b/chrome/test/webdriver/chromedriver_tests.py |
| @@ -14,6 +14,7 @@ import hashlib |
| import os |
| import platform |
| import sys |
| +import tempfile |
| import unittest |
| import urllib |
| import urllib2 |
| @@ -31,6 +32,7 @@ try: |
| except ImportError: |
| import json |
| +from selenium.common.exceptions import WebDriverException |
| from selenium.webdriver.remote.command import Command |
| from selenium.webdriver.remote.webdriver import WebDriver |
| from selenium.webdriver.common.keys import Keys |
| @@ -178,7 +180,6 @@ class WebserverTest(unittest.TestCase): |
| """Tests the built-in ChromeDriver webserver.""" |
| def testShouldNotServeFilesByDefault(self): |
| - launcher = ChromeDriverLauncher() |
| try: |
| SendRequest(launcher.GetURL(), method='GET') |
| self.fail('Should have raised a urllib.HTTPError for returned 403') |
| @@ -290,7 +291,7 @@ class CookieTest(unittest.TestCase): |
| cookie_dict = None |
| cookie_dict = self._driver.get_cookie("chromedriver_cookie_test") |
| cookie_dict = {} |
| - cookie_dict["name"]= "chromedriver_cookie_test" |
| + cookie_dict["name"] = "chromedriver_cookie_test" |
| cookie_dict["value"] = "this is a test" |
| self._driver.add_cookie(cookie_dict) |
| cookie_dict = self._driver.get_cookie("chromedriver_cookie_test") |
| @@ -621,6 +622,83 @@ class AutofillTest(unittest.TestCase): |
| 'Saved CC line item not same as what was entered.') |
| +class FileUploadControlTest(unittest.TestCase): |
| + """Tests dealing with file upload control.""" |
| + |
| + def setUp(self): |
| + self._launcher = ChromeDriverLauncher(root_path=os.path.dirname(__file__)) |
| + self._driver = WebDriver(self._launcher.GetURL(), |
| + DesiredCapabilities.CHROME) |
| + |
| + def tearDown(self): |
| + self._driver.quit() |
| + self._launcher.Kill() |
| + |
| + def testSetFilePathToFileUploadControl(self): |
| + """Verify a file path is set to the file upload control.""" |
| + self._driver.get(self._launcher.GetURL() + '/upload.html') |
| + |
| + file = tempfile.NamedTemporaryFile() |
| + |
| + fileupload_single = self._driver.find_element_by_name('fileupload_single') |
| + multiple = fileupload_single.get_attribute('multiple') |
| + self.assertEqual('false', multiple) |
| + fileupload_single.send_keys(file.name) |
| + path = fileupload_single.value |
| + self.assertTrue(path.endswith(os.path.basename(file.name))) |
| + |
| + def testSetMultipleFilePathsToFileuploadControlWithoutMultipleWillFail(self): |
| + """Verify setting file paths to the file upload control without 'multiple' |
| + attribute will fail.""" |
| + self._driver.get(self._launcher.GetURL() + '/upload.html') |
| + |
| + files = list() |
|
kkania
2011/06/16 15:48:59
looks like this is never used; remove?
nodchip
2011/06/27 04:05:53
I think we need to hold file objects because the f
|
| + filepaths = list() |
|
kkania
2011/06/16 15:48:59
list() -> [], everywhere used
nodchip
2011/06/27 04:05:53
Done.
|
| + for index in xrange(4): |
| + file = tempfile.NamedTemporaryFile() |
| + files.append(file) |
| + filepath = file.name |
| + filepaths.append(filepath) |
| + |
| + fileupload_single = self._driver.find_element_by_name('fileupload_single') |
| + multiple = fileupload_single.get_attribute('multiple') |
| + self.assertEqual('false', multiple) |
| + self.assertRaises(WebDriverException, fileupload_single.send_keys, |
| + filepaths[0], filepaths[1], filepaths[2], filepaths[3]) |
| + path = fileupload_single.value |
|
kkania
2011/06/16 15:48:59
value is supposed to be deprectated in the next re
nodchip
2011/06/27 04:05:53
Done.
|
| + self.assertFalse(path) |
| + |
| + def testSetMultipleFilePathsToFileUploadControl(self): |
| + """Verify multiple file paths are set to the file upload control.""" |
| + self._driver.get(self._launcher.GetURL() + '/upload.html') |
| + |
| + files = list() |
|
kkania
2011/06/16 15:48:59
looks like this is never used; remove?
nodchip
2011/06/27 04:05:53
Please see above.
|
| + filepaths = list() |
| + filenames = set() |
| + for index in xrange(4): |
| + file = tempfile.NamedTemporaryFile() |
| + files.append(file) |
| + filepath = file.name |
| + filepaths.append(filepath) |
| + filenames.add(os.path.basename(filepath)) |
| + |
| + fileupload_multi = self._driver.find_element_by_name('fileupload_multi') |
| + multiple = fileupload_multi.get_attribute('multiple') |
| + self.assertEqual('true', multiple) |
| + fileupload_multi.send_keys(filepaths[0], filepaths[1], filepaths[2], |
| + filepaths[3]) |
| + path = fileupload_multi.value.replace('\\', '//') |
|
kkania
2011/06/16 15:48:59
how about remove this and the next line (since it
nodchip
2011/06/27 04:05:53
Done.
|
| + self.assertTrue(os.path.basename(path) in filenames) |
| + |
| + filesOnElement = self._driver.execute_script( |
|
kkania
2011/06/16 15:48:59
files_on_element
nodchip
2011/06/27 04:05:53
Done.
|
| + 'return document.getElementById("fileupload_multi").files;') |
| + self.assertTrue(filesOnElement) |
| + self.assertEqual(4, len(filesOnElement)) |
| + for f in filesOnElement: |
| + name = f['name'] |
| + self.assertTrue(name in filenames) |
|
kkania
2011/06/16 15:48:59
remove name and use f['name'] directly
nodchip
2011/06/27 04:05:53
Done.
|
| + |
| + |
| if __name__ == '__main__': |
| unittest.main(module='chromedriver_tests', |
| testRunner=GTestTextTestRunner(verbosity=1)) |