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. |
| (...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.""" | |
| 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 NewDriver(self): | |
|
Huyen
2011/03/30 19:17:02
Fold the code here into where you're calling NewDr
dyu1
2011/03/30 21:51:45
What do you mean by fold the code here? If I didn'
Huyen
2011/03/30 22:08:03
Inline WebDriver(self._launcher.GetUrl(), {}) wher
dyu1
2011/03/30 22:33:10
If I fold it in then instead of driver.get for all
Huyen
2011/03/30 23:23:12
When you add more tests later you can add that met
| |
| 365 return WebDriver(self._launcher.GetURL(), {}) | |
| 366 | |
| 367 def testPostalCodeAndStateLabelsBasedOnCountry(self): | |
| 368 """Verify postal code and state labels based on selected country.""" | |
| 369 file_path = os.path.join('state_zip_labels.txt') | |
| 370 import simplejson | |
| 371 print dir(simplejson) | |
|
Huyen
2011/03/30 19:17:02
Do you need this print? Remove if it is for debugg
dyu1
2011/03/30 21:51:45
Done.
| |
| 372 test_data = simplejson.loads(open(file_path).read()) | |
| 373 | |
| 374 driver = self.NewDriver() | |
| 375 driver.get(self.AUTOFILL_EDIT_ADDRESS) | |
| 376 state_label = driver.find_element_by_id('state-label').text | |
| 377 self.assertEqual('State', state_label) | |
| 378 for country_code in test_data: | |
| 379 query = '//option[@value="%s"]' % country_code | |
| 380 driver.find_element_by_id( | |
|
Huyen
2011/03/30 19:17:02
This is fine but if multiple postal codes are not
dyu1
2011/03/30 21:51:45
What do you mean by multiple postal codes? In this
Huyen
2011/03/30 22:08:03
You're looping through the list of postal codes to
| |
| 381 'country').find_element_by_xpath(query).select() | |
| 382 | |
| 383 # Compare postal labels. | |
| 384 actual_postal_label = driver.find_element_by_id( | |
| 385 'postal-code-label').text | |
| 386 expected_postal_label = test_data[country_code]['postalCodeLabel'] | |
| 387 self.assertEqual( | |
| 388 actual_postal_label, expected_postal_label, | |
| 389 'Postal code label on the UI does not correspond to the selected \ | |
|
Huyen
2011/03/30 19:17:02
This is a UI test so you don't need to say "on the
dyu1
2011/03/30 21:51:45
Done.
| |
| 390 Country "%s"' % country_code) | |
| 391 # Compare state labels. | |
| 392 actual_state_label = driver.find_element_by_id('state-label').text | |
| 393 expected_state_label = test_data[country_code]['stateLabel'] | |
| 394 self.assertEqual( | |
| 395 actual_state_label, expected_state_label, | |
| 396 'State label on the UI does not correspond to the selected \ | |
|
Huyen
2011/03/30 19:17:02
Same as above.
dyu1
2011/03/30 21:51:45
Done.
| |
| 397 Country "%s"' % country_code) | |
| 398 | |
|
Huyen
2011/03/30 19:17:02
You might want to call driver.quit() here.
dyu1
2011/03/30 21:51:45
The driver quits on it's own when I run the test.
| |
| 399 | |
| 354 # TODO(jleyba): Port this to WebDriver's own python test suite. | 400 # TODO(jleyba): Port this to WebDriver's own python test suite. |
| 355 class ElementEqualityTest(unittest.TestCase): | 401 class ElementEqualityTest(unittest.TestCase): |
| 356 """Tests that the server properly checks element equality.""" | 402 """Tests that the server properly checks element equality.""" |
| 357 | 403 |
| 358 def setUp(self): | 404 def setUp(self): |
| 359 self._launcher = ChromeDriverLauncher(root_path=os.path.dirname(__file__)) | 405 self._launcher = ChromeDriverLauncher(root_path=os.path.dirname(__file__)) |
| 360 self._driver = WebDriver(self._launcher.GetURL(), {}) | 406 self._driver = WebDriver(self._launcher.GetURL(), {}) |
| 361 | 407 |
| 362 def tearDown(self): | 408 def tearDown(self): |
| 363 self._driver.quit() | 409 self._driver.quit() |
| 364 self._launcher.Kill() | 410 self._launcher.Kill() |
| 365 | 411 |
| 366 def testElementEquality(self): | 412 def testElementEquality(self): |
| 367 self._driver.get(self._launcher.GetURL() + '/test_page.html') | 413 self._driver.get(self._launcher.GetURL() + '/test_page.html') |
| 368 body1 = self._driver.find_element_by_tag_name('body') | 414 body1 = self._driver.find_element_by_tag_name('body') |
| 369 body2 = self._driver.execute_script('return document.body') | 415 body2 = self._driver.execute_script('return document.body') |
| 370 | 416 |
| 371 # TODO(jleyba): WebDriver's python bindings should expose a proper API | 417 # TODO(jleyba): WebDriver's python bindings should expose a proper API |
| 372 # for this. | 418 # for this. |
| 373 result = body1.execute(Command.ELEMENT_EQUALS, { | 419 result = body1.execute(Command.ELEMENT_EQUALS, { |
| 374 'other': body2.id | 420 'other': body2.id |
| 375 }) | 421 }) |
| 376 self.assertTrue(result['value']) | 422 self.assertTrue(result['value']) |
| 377 | 423 |
| 378 | 424 |
| 379 if __name__ == '__main__': | 425 if __name__ == '__main__': |
| 380 unittest.main(module='chromedriver_tests', | 426 unittest.main(module='chromedriver_tests', |
| 381 testRunner=GTestTextTestRunner(verbosity=1)) | 427 testRunner=GTestTextTestRunner(verbosity=1)) |
| OLD | NEW |