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. |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
344 | 344 |
345 url_parts = urlparse.urlparse(self.session_url)[2].split('/') | 345 url_parts = urlparse.urlparse(self.session_url)[2].split('/') |
346 self.assertEquals(5, len(url_parts)) | 346 self.assertEquals(5, len(url_parts)) |
347 self.assertEquals('', url_parts[0]) | 347 self.assertEquals('', url_parts[0]) |
348 self.assertEquals('wd', url_parts[1]) | 348 self.assertEquals('wd', url_parts[1]) |
349 self.assertEquals('hub', url_parts[2]) | 349 self.assertEquals('hub', url_parts[2]) |
350 self.assertEquals('session', url_parts[3]) | 350 self.assertEquals('session', url_parts[3]) |
351 self.assertEquals(data['sessionId'], url_parts[4]) | 351 self.assertEquals(data['sessionId'], url_parts[4]) |
352 | 352 |
353 | 353 |
354 class AutofillTest(unittest.TestCase): | |
355 """Autofill tests that interacts with web UI.""" | |
kkania
2011/03/31 00:48:48
web settings UI?, is that what you mean
kkania
2011/03/31 00:48:48
Can you put these tests near the end of the file,
dyu1
2011/03/31 03:19:31
I don't think all Autofill tests will be related t
dyu1
2011/03/31 03:19:31
Done.
| |
356 AUTOFILL_EDIT_ADDRESS = 'chrome://settings/autoFillEditAddress' | |
357 | |
358 def setUp(self): | |
359 self._launcher = ChromeDriverLauncher() | |
360 | |
361 def tearDown(self): | |
362 self._launcher.Kill() | |
363 | |
364 def testPostalCodeAndStateLabelsBasedOnCountry(self): | |
365 """Verify postal code and state labels based on selected country.""" | |
366 file_path = os.path.join('state_zip_labels.txt') | |
367 import simplejson | |
368 test_data = simplejson.loads(open(file_path).read()) | |
369 | |
370 driver = WebDriver(self._launcher.GetURL(), {}) | |
371 driver.get(self.AUTOFILL_EDIT_ADDRESS) | |
372 state_label = driver.find_element_by_id('state-label').text | |
373 self.assertEqual('State', state_label) | |
374 for country_code in test_data: | |
375 query = '//option[@value="%s"]' % country_code | |
376 driver.find_element_by_id( | |
kkania
2011/03/31 00:48:48
this looks a bit funky; can you check the style gu
dyu1
2011/03/31 03:19:31
Turns out the line fits fine. The newline can go a
| |
377 'country').find_element_by_xpath(query).select() | |
378 | |
379 # Compare postal labels. | |
380 actual_postal_label = driver.find_element_by_id( | |
381 'postal-code-label').text | |
382 expected_postal_label = test_data[country_code]['postalCodeLabel'] | |
383 self.assertEqual( | |
384 actual_postal_label, expected_postal_label, | |
385 'Postal code label does not match Country "%s"' % country_code) | |
386 # Compare state labels. | |
387 actual_state_label = driver.find_element_by_id('state-label').text | |
388 expected_state_label = test_data[country_code]['stateLabel'] | |
389 self.assertEqual( | |
390 actual_state_label, expected_state_label, | |
391 'State label does not match Country "%s"' % country_code) | |
392 | |
393 | |
354 # TODO(jleyba): Port this to WebDriver's own python test suite. | 394 # TODO(jleyba): Port this to WebDriver's own python test suite. |
355 class ElementEqualityTest(unittest.TestCase): | 395 class ElementEqualityTest(unittest.TestCase): |
356 """Tests that the server properly checks element equality.""" | 396 """Tests that the server properly checks element equality.""" |
357 | 397 |
358 def setUp(self): | 398 def setUp(self): |
359 self._launcher = ChromeDriverLauncher(root_path=os.path.dirname(__file__)) | 399 self._launcher = ChromeDriverLauncher(root_path=os.path.dirname(__file__)) |
360 self._driver = WebDriver(self._launcher.GetURL(), {}) | 400 self._driver = WebDriver(self._launcher.GetURL(), {}) |
361 | 401 |
362 def tearDown(self): | 402 def tearDown(self): |
363 self._driver.quit() | 403 self._driver.quit() |
364 self._launcher.Kill() | 404 self._launcher.Kill() |
365 | 405 |
366 def testElementEquality(self): | 406 def testElementEquality(self): |
367 self._driver.get(self._launcher.GetURL() + '/test_page.html') | 407 self._driver.get(self._launcher.GetURL() + '/test_page.html') |
368 body1 = self._driver.find_element_by_tag_name('body') | 408 body1 = self._driver.find_element_by_tag_name('body') |
369 body2 = self._driver.execute_script('return document.body') | 409 body2 = self._driver.execute_script('return document.body') |
370 | 410 |
371 # TODO(jleyba): WebDriver's python bindings should expose a proper API | 411 # TODO(jleyba): WebDriver's python bindings should expose a proper API |
372 # for this. | 412 # for this. |
373 result = body1.execute(Command.ELEMENT_EQUALS, { | 413 result = body1.execute(Command.ELEMENT_EQUALS, { |
374 'other': body2.id | 414 'other': body2.id |
375 }) | 415 }) |
376 self.assertTrue(result['value']) | 416 self.assertTrue(result['value']) |
377 | 417 |
378 | 418 |
379 if __name__ == '__main__': | 419 if __name__ == '__main__': |
380 unittest.main(module='chromedriver_tests', | 420 unittest.main(module='chromedriver_tests', |
381 testRunner=GTestTextTestRunner(verbosity=1)) | 421 testRunner=GTestTextTestRunner(verbosity=1)) |
OLD | NEW |