| OLD | NEW |
| 1 # -*- coding: utf-8 -*- | 1 # -*- coding: utf-8 -*- |
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Automated tests for many websites""" | 6 """Automated tests for many websites""" |
| 7 | 7 |
| 8 import argparse | 8 import argparse |
| 9 | 9 |
| 10 from environment import Environment | 10 from environment import Environment |
| 11 from websitetest import WebsiteTest | 11 from websitetest import WebsiteTest |
| 12 | 12 |
| 13 | 13 |
| 14 TEST_CASES = ("PromptFailTest", "PromptSuccessTest", "SaveAndAutofillTest") |
| 15 |
| 16 |
| 14 class Alexa(WebsiteTest): | 17 class Alexa(WebsiteTest): |
| 15 | 18 |
| 16 def Login(self): | 19 def Login(self): |
| 17 self.GoTo("https://www.alexa.com/secure/login") | 20 self.GoTo("https://www.alexa.com/secure/login") |
| 18 self.FillUsernameInto("#email") | 21 self.FillUsernameInto("#email") |
| 19 self.FillPasswordInto("#pwd") | 22 self.FillPasswordInto("#pwd") |
| 20 self.Submit("#pwd") | 23 self.Submit("#pwd") |
| 21 | 24 |
| 22 | 25 |
| 23 class Dropbox(WebsiteTest): | 26 class Dropbox(WebsiteTest): |
| (...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 xml = "<result>" | 500 xml = "<result>" |
| 498 for (name, test_type, success, failure_log) in environment_tests_results: | 501 for (name, test_type, success, failure_log) in environment_tests_results: |
| 499 if not (save_only_failures and success): | 502 if not (save_only_failures and success): |
| 500 xml += ( | 503 xml += ( |
| 501 "<test name='{0}' successful='{1}' type='{2}'>{3}</test>".format( | 504 "<test name='{0}' successful='{1}' type='{2}'>{3}</test>".format( |
| 502 name, success, test_type, failure_log)) | 505 name, success, test_type, failure_log)) |
| 503 xml += "</result>" | 506 xml += "</result>" |
| 504 with open(environment_save_path, "w") as save_file: | 507 with open(environment_save_path, "w") as save_file: |
| 505 save_file.write(xml) | 508 save_file.write(xml) |
| 506 | 509 |
| 510 |
| 507 def RunTest(chrome_path, chromedriver_path, profile_path, | 511 def RunTest(chrome_path, chromedriver_path, profile_path, |
| 508 environment_passwords_path, website_test_name, test_case_name): | 512 environment_passwords_path, website_test_name, |
| 513 test_case_name): |
| 509 """Runs the test for the specified website. | 514 """Runs the test for the specified website. |
| 510 | 515 |
| 511 Args: | 516 Args: |
| 512 chrome_path: The chrome binary file. | 517 chrome_path: The chrome binary file. |
| 513 chromedriver_path: The chromedriver binary file. | 518 chromedriver_path: The chromedriver binary file. |
| 514 profile_path: The chrome testing profile folder. | 519 profile_path: The chrome testing profile folder. |
| 515 environment_passwords_path: The usernames and passwords file. | 520 environment_passwords_path: The usernames and passwords file. |
| 516 website_test_name: Name of the website to test (refer to keys in | 521 website_test_name: Name of the website to test (refer to keys in |
| 517 all_tests above). | 522 all_tests above). |
| 518 | 523 |
| 519 Returns: | 524 Returns: |
| 520 The results of the test as list of TestResults. | 525 The results of the test as list of TestResults. |
| 521 | 526 |
| 522 Raises: | 527 Raises: |
| 523 Exception: An exception is raised if one of the tests for the website | 528 Exception: An exception is raised if one of the tests for the website |
| 524 fails, or if the website name is not known. | 529 fails, or if the website name is not known. |
| 525 """ | 530 """ |
| 526 | 531 |
| 527 enable_automatic_password_saving = (test_case_name == "SaveAndAutofillTest") | 532 enable_automatic_password_saving = (test_case_name == "SaveAndAutofillTest") |
| 528 environment = Environment(chrome_path, chromedriver_path, profile_path, | 533 environment = Environment(chrome_path, chromedriver_path, profile_path, |
| 529 environment_passwords_path, | 534 environment_passwords_path, |
| 530 enable_automatic_password_saving) | 535 enable_automatic_password_saving) |
| 536 try: |
| 537 if website_test_name in all_tests: |
| 538 environment.AddWebsiteTest(all_tests[website_test_name]) |
| 539 else: |
| 540 raise Exception("Test name {} is unknown.".format(website_test_name)) |
| 531 | 541 |
| 532 if website_test_name in all_tests: | 542 environment.RunTestsOnSites(test_case_name) |
| 533 environment.AddWebsiteTest(all_tests[website_test_name]) | 543 return environment.tests_results |
| 534 else: | 544 finally: |
| 535 raise Exception("Test name {} is unknown.".format(website_test_name)) | 545 environment.Quit() |
| 536 | |
| 537 environment.RunTestsOnSites(test_case_name) | |
| 538 environment.Quit() | |
| 539 return environment.tests_results | |
| 540 | 546 |
| 541 def main(): | 547 def main(): |
| 542 parser = argparse.ArgumentParser( | 548 parser = argparse.ArgumentParser( |
| 543 description="Password Manager automated tests help.") | 549 description="Password Manager automated tests help.") |
| 544 | 550 |
| 545 parser.add_argument( | 551 parser.add_argument( |
| 546 "--chrome-path", action="store", dest="chrome_path", | 552 "--chrome-path", action="store", dest="chrome_path", |
| 547 help="Set the chrome path (required).", required=True) | 553 help="Set the chrome path (required).", required=True) |
| 548 parser.add_argument( | 554 parser.add_argument( |
| 549 "--chromedriver-path", action="store", dest="chromedriver_path", | 555 "--chromedriver-path", action="store", dest="chromedriver_path", |
| (...skipping 18 matching lines...) Expand all Loading... |
| 568 parser.add_argument("--test-cases-to-run", help="Names of test cases which" | 574 parser.add_argument("--test-cases-to-run", help="Names of test cases which" |
| 569 "should be run. Currently supported test cases are:" | 575 "should be run. Currently supported test cases are:" |
| 570 "PromptFailTest, PromptSuccessTest, SaveAndAutofillTest", | 576 "PromptFailTest, PromptSuccessTest, SaveAndAutofillTest", |
| 571 dest="test_cases_to_run", action="store", nargs="*") | 577 dest="test_cases_to_run", action="store", nargs="*") |
| 572 args = parser.parse_args() | 578 args = parser.parse_args() |
| 573 | 579 |
| 574 save_path = None | 580 save_path = None |
| 575 if args.save_path: | 581 if args.save_path: |
| 576 save_path = args.save_path | 582 save_path = args.save_path |
| 577 | 583 |
| 578 test_cases_to_run = args.test_cases_to_run or\ | 584 test_cases_to_run = args.test_cases_to_run or TEST_CASES |
| 579 ("PromptFailTest", "PromptSuccessTest", "SaveAndAutofillTest") | |
| 580 | |
| 581 for test_case in test_cases_to_run: | 585 for test_case in test_cases_to_run: |
| 582 tests_results = RunTest( | 586 tests_results = RunTest( |
| 583 args.chrome_path, args.chromedriver_path, args.profile_path, | 587 args.chrome_path, args.chromedriver_path, args.profile_path, |
| 584 args.passwords_path, args.website, test_case) | 588 args.passwords_path, args.website, test_case) |
| 585 | 589 |
| 586 | 590 |
| 587 SaveResults(tests_results, save_path, | 591 SaveResults(tests_results, save_path, |
| 588 save_only_failures=args.save_only_failures) | 592 save_only_failures=args.save_only_failures) |
| 589 | 593 |
| 590 if __name__ == "__main__": | 594 if __name__ == "__main__": |
| 591 main() | 595 main() |
| OLD | NEW |