Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 | 2 |
| 3 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 """Tests for ChromeDriver. | 7 """Tests for ChromeDriver. |
| 8 | 8 |
| 9 If your test is testing a specific part of the WebDriver API, consider adding | 9 If your test is testing a specific part of the WebDriver API, consider adding |
| 10 it to the appropriate place in the WebDriver tree instead. | 10 it to the appropriate place in the WebDriver tree instead. |
| 11 """ | 11 """ |
| 12 | 12 |
| 13 import hashlib | 13 import hashlib |
| 14 import os | 14 import os |
| 15 import platform | 15 import platform |
| 16 import sys | 16 import sys |
| 17 import tempfile | |
| 17 import unittest | 18 import unittest |
| 18 import urllib | 19 import urllib |
| 19 import urllib2 | 20 import urllib2 |
| 20 import urlparse | 21 import urlparse |
| 21 | 22 |
| 22 from chromedriver_launcher import ChromeDriverLauncher | 23 from chromedriver_launcher import ChromeDriverLauncher |
| 23 import chromedriver_paths | 24 import chromedriver_paths |
| 24 from gtest_text_test_runner import GTestTextTestRunner | 25 from gtest_text_test_runner import GTestTextTestRunner |
| 25 | 26 |
| 26 sys.path += [chromedriver_paths.SRC_THIRD_PARTY] | 27 sys.path += [chromedriver_paths.SRC_THIRD_PARTY] |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 283 | 284 |
| 284 def tearDown(self): | 285 def tearDown(self): |
| 285 self._driver.quit() | 286 self._driver.quit() |
| 286 self._launcher.Kill() | 287 self._launcher.Kill() |
| 287 | 288 |
| 288 def testAddCookie(self): | 289 def testAddCookie(self): |
| 289 self._driver.get(self._launcher.GetURL() + '/test_page.html') | 290 self._driver.get(self._launcher.GetURL() + '/test_page.html') |
| 290 cookie_dict = None | 291 cookie_dict = None |
| 291 cookie_dict = self._driver.get_cookie("chromedriver_cookie_test") | 292 cookie_dict = self._driver.get_cookie("chromedriver_cookie_test") |
| 292 cookie_dict = {} | 293 cookie_dict = {} |
| 293 cookie_dict["name"]= "chromedriver_cookie_test" | 294 cookie_dict["name"] = "chromedriver_cookie_test" |
| 294 cookie_dict["value"] = "this is a test" | 295 cookie_dict["value"] = "this is a test" |
| 295 self._driver.add_cookie(cookie_dict) | 296 self._driver.add_cookie(cookie_dict) |
| 296 cookie_dict = self._driver.get_cookie("chromedriver_cookie_test") | 297 cookie_dict = self._driver.get_cookie("chromedriver_cookie_test") |
| 297 self.assertNotEqual(cookie_dict, None) | 298 self.assertNotEqual(cookie_dict, None) |
| 298 self.assertEqual(cookie_dict["value"], "this is a test") | 299 self.assertEqual(cookie_dict["value"], "this is a test") |
| 299 | 300 |
| 300 def testDeleteCookie(self): | 301 def testDeleteCookie(self): |
| 301 self.testAddCookie(); | 302 self.testAddCookie(); |
| 302 self._driver.delete_cookie("chromedriver_cookie_test") | 303 self._driver.delete_cookie("chromedriver_cookie_test") |
| 303 cookie_dict = self._driver.get_cookie("chromedriver_cookie_test") | 304 cookie_dict = self._driver.get_cookie("chromedriver_cookie_test") |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 589 'autofill-edit-credit-card-apply-button').click() | 590 'autofill-edit-credit-card-apply-button').click() |
| 590 # Refresh the page to ensure the UI is up-to-date. | 591 # Refresh the page to ensure the UI is up-to-date. |
| 591 driver.refresh() | 592 driver.refresh() |
| 592 list_entry = driver.find_element_by_class_name('autofill-list-item') | 593 list_entry = driver.find_element_by_class_name('autofill-list-item') |
| 593 self.assertTrue(list_entry.is_displayed) | 594 self.assertTrue(list_entry.is_displayed) |
| 594 self.assertEqual(list_entry.text, | 595 self.assertEqual(list_entry.text, |
| 595 creditcard_data['CREDIT_CARD_NAME'], | 596 creditcard_data['CREDIT_CARD_NAME'], |
| 596 'Saved CC line item not same as what was entered.') | 597 'Saved CC line item not same as what was entered.') |
| 597 | 598 |
| 598 | 599 |
| 600 class FileUploadControlTest(unittest.TestCase): | |
| 601 """Tests dealing with file upload control.""" | |
| 602 | |
| 603 def setUp(self): | |
| 604 self._launcher = ChromeDriverLauncher(root_path=os.path.dirname(__file__)) | |
| 605 self._driver = WebDriver(self._launcher.GetURL(), | |
| 606 DesiredCapabilities.CHROME) | |
| 607 | |
| 608 def tearDown(self): | |
| 609 self._driver.quit() | |
| 610 self._launcher.Kill() | |
| 611 | |
| 612 def testSetFilePathToFileUploadControl(self): | |
| 613 """Verify a file path is set to the file upload control.""" | |
| 614 self._driver.get(self._launcher.GetURL() + '/upload.html') | |
| 615 | |
| 616 file = tempfile.NamedTemporaryFile() | |
| 617 | |
| 618 fileupload = self._driver.find_element_by_name('fileupload') | |
| 619 fileupload.send_keys(file.name) | |
| 620 path = fileupload.value | |
| 621 self.assertTrue(path.endswith(os.path.basename(file.name))) | |
|
kkania
2011/06/07 15:12:04
do you need to close/delete the temp file?
nodchip
2011/06/08 02:37:19
I think we don't need to manually close/delete the
| |
| 622 | |
| 623 def testSetMultipleFilePathsToFileUploadControl(self): | |
| 624 """Verify multiple file paths are set to the file upload control.""" | |
| 625 self._driver.get(self._launcher.GetURL() + '/upload.html') | |
| 626 | |
| 627 files = list() | |
| 628 filepaths = list() | |
| 629 filenames = set() | |
| 630 for index in xrange(4): | |
| 631 file = tempfile.NamedTemporaryFile() | |
| 632 files.append(file) | |
| 633 filepath = file.name | |
| 634 filepaths.append(filepath) | |
| 635 filenames.add(os.path.basename(filepath)) | |
| 636 | |
| 637 fileupload = self._driver.find_element_by_name('fileupload') | |
| 638 fileupload.send_keys(filepaths[0], filepaths[1], filepaths[2], filepaths[3]) | |
| 639 path = fileupload.value.replace('\\', '//') | |
| 640 self.assertTrue(os.path.basename(path) in filenames) | |
| 641 | |
| 642 | |
| 599 if __name__ == '__main__': | 643 if __name__ == '__main__': |
| 600 unittest.main(module='chromedriver_tests', | 644 unittest.main(module='chromedriver_tests', |
| 601 testRunner=GTestTextTestRunner(verbosity=1)) | 645 testRunner=GTestTextTestRunner(verbosity=1)) |
| OLD | NEW |