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 |
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
502 for (name, test_type, success, failure_log) in environment_tests_results: | 502 for (name, test_type, success, failure_log) in environment_tests_results: |
503 if not (save_only_failures and success): | 503 if not (save_only_failures and success): |
504 xml += ( | 504 xml += ( |
505 "<test name='{0}' successful='{1}' type='{2}'>{3}</test>".format( | 505 "<test name='{0}' successful='{1}' type='{2}'>{3}</test>".format( |
506 name, success, test_type, failure_log)) | 506 name, success, test_type, failure_log)) |
507 xml += "</result>" | 507 xml += "</result>" |
508 with open(environment_save_path, "w") as save_file: | 508 with open(environment_save_path, "w") as save_file: |
509 save_file.write(xml) | 509 save_file.write(xml) |
510 | 510 |
511 def RunTest(chrome_path, chromedriver_path, profile_path, | 511 def RunTest(chrome_path, chromedriver_path, profile_path, |
512 environment_passwords_path, website_test_name, test_type): | 512 environment_passwords_path, website_test_name, test_case_name): |
513 """Runs the test for the specified website. | 513 """Runs the test for the specified website. |
514 | 514 |
515 Args: | 515 Args: |
516 chrome_path: The chrome binary file. | 516 chrome_path: The chrome binary file. |
517 chromedriver_path: The chromedriver binary file. | 517 chromedriver_path: The chromedriver binary file. |
518 profile_path: The chrome testing profile folder. | 518 profile_path: The chrome testing profile folder. |
519 environment_passwords_path: The usernames and passwords file. | 519 environment_passwords_path: The usernames and passwords file. |
520 website_test_name: Name of the website to test (refer to keys in | 520 website_test_name: Name of the website to test (refer to keys in |
521 all_tests above). | 521 all_tests above). |
522 | 522 |
523 Returns: | 523 Returns: |
524 The results of the test as list of TestResults. | 524 The results of the test as list of TestResults. |
525 | 525 |
526 Raises: | 526 Raises: |
527 Exception: An exception is raised if one of the tests for the website | 527 Exception: An exception is raised if one of the tests for the website |
528 fails, or if the website name is not known. | 528 fails, or if the website name is not known. |
529 """ | 529 """ |
530 | 530 |
531 enable_automatic_password_saving = ( | 531 enable_automatic_password_saving = (test_case_name == "SaveAndAutofillTest") |
532 test_type == WebsiteTest.TEST_TYPE_SAVE_AND_AUTOFILL) | |
533 environment = Environment(chrome_path, chromedriver_path, profile_path, | 532 environment = Environment(chrome_path, chromedriver_path, profile_path, |
534 environment_passwords_path, | 533 environment_passwords_path, |
535 enable_automatic_password_saving) | 534 enable_automatic_password_saving) |
536 | 535 |
537 if website_test_name in all_tests: | 536 if website_test_name in all_tests: |
538 environment.AddWebsiteTest(all_tests[website_test_name]) | 537 environment.AddWebsiteTest(all_tests[website_test_name]) |
539 else: | 538 else: |
540 raise Exception("Test name {} is unknown.".format(website_test_name)) | 539 raise Exception("Test name {} is unknown.".format(website_test_name)) |
541 | 540 |
542 environment.RunTestsOnSites(test_type) | 541 environment.RunTestsOnSites(test_case_name) |
543 environment.Quit() | 542 environment.Quit() |
544 return environment.tests_results | 543 return environment.tests_results |
545 | 544 |
546 def main(): | 545 def main(): |
547 parser = argparse.ArgumentParser( | 546 parser = argparse.ArgumentParser( |
548 description="Password Manager automated tests help.") | 547 description="Password Manager automated tests help.") |
549 | 548 |
550 parser.add_argument( | 549 parser.add_argument( |
551 "--chrome-path", action="store", dest="chrome_path", | 550 "--chrome-path", action="store", dest="chrome_path", |
552 help="Set the chrome path (required).", required=True) | 551 help="Set the chrome path (required).", required=True) |
553 parser.add_argument( | 552 parser.add_argument( |
554 "--chromedriver-path", action="store", dest="chromedriver_path", | 553 "--chromedriver-path", action="store", dest="chromedriver_path", |
555 help="Set the chromedriver path (required).", required=True) | 554 help="Set the chromedriver path (required).", required=True) |
556 parser.add_argument( | 555 parser.add_argument( |
557 "--profile-path", action="store", dest="profile_path", | 556 "--profile-path", action="store", dest="profile_path", |
558 help="Set the profile path (required). You just need to choose a " | 557 help="Set the profile path (required). You just need to choose a " |
559 "temporary empty folder. If the folder is not empty all its content " | 558 "temporary empty folder. If the folder is not empty all its content " |
560 "is going to be removed.", | 559 "is going to be removed.", |
561 required=True) | 560 required=True) |
562 | 561 |
563 parser.add_argument( | 562 parser.add_argument( |
564 "--passwords-path", action="store", dest="passwords_path", | 563 "--passwords-path", action="store", dest="passwords_path", |
565 help="Set the usernames/passwords path (required).", required=True) | 564 help="Set the usernames/passwords path (required).", required=True) |
566 parser.add_argument("--save-path", action="store", dest="save_path", | 565 parser.add_argument("--save-path", action="store", dest="save_path", |
567 help="Write the results in a file.") | 566 help="Write the results in a file.") |
568 parser.add_argument("test", help="Test to be run.") | |
569 parser.add_argument("--save-only-failures", | 567 parser.add_argument("--save-only-failures", |
570 help="Only save logs for failing tests.", | 568 help="Only save logs for failing tests.", |
571 dest="save_only_failures", action="store_true", | 569 dest="save_only_failures", action="store_true", |
572 default=False) | 570 parser.add_argument("website", help="Website test name on which" |
573 | 571 "tests should be run.") |
572 # TODO(melandory): Think about supporting test case specifying on website | |
vabr (Chromium)
2015/04/13 15:26:20
I'm not sure I understand what you want to think a
melandory
2015/04/14 07:22:36
Hm, actually this todo doesn't belong here. And pr
| |
573 # basis. | |
574 parser.add_argument("--test-cases-to-run", help="Names of test cases which" | |
575 "should be run. Currently supported test cases are:" | |
576 "PromptFailTest, PromptSuccessTest, SaveAndAutofillTest", | |
577 dest="test_cases_to_run", action="store", nargs="*") | |
574 args = parser.parse_args() | 578 args = parser.parse_args() |
575 | 579 |
576 save_path = None | 580 save_path = None |
577 if args.save_path: | 581 if args.save_path: |
578 save_path = args.save_path | 582 save_path = args.save_path |
579 | 583 |
580 tests_results = RunTest( | 584 test_cases_to_run = args.test_cases_to_run or\ |
581 args.chrome_path, args.chromedriver_path, args.profile_path, | 585 ("PromptFailTest", "PromptSuccessTest", "SaveAndAutofillTest") |
582 args.passwords_path, args.test, WebsiteTest.TEST_TYPE_PROMPT_FAIL) | |
583 | 586 |
584 tests_results += RunTest( | 587 for test_case in test_cases_to_run: |
585 args.chrome_path, args.chromedriver_path, args.profile_path, | 588 tests_results = RunTest( |
586 args.passwords_path, args.test, WebsiteTest.TEST_TYPE_PROMPT_SUCCESS) | 589 args.chrome_path, args.chromedriver_path, args.profile_path, |
590 args.passwords_path, args.website, test_case) | |
587 | 591 |
588 tests_results += RunTest( | |
589 args.chrome_path, args.chromedriver_path, args.profile_path, | |
590 args.passwords_path, args.test, WebsiteTest.TEST_TYPE_SAVE_AND_AUTOFILL) | |
591 | 592 |
592 SaveResults(tests_results, save_path, | 593 SaveResults(tests_results, save_path, |
593 save_only_failures=args.save_only_failures) | 594 save_only_failures=args.save_only_failures) |
594 | 595 |
595 if __name__ == "__main__": | 596 if __name__ == "__main__": |
596 main() | 597 main() |
OLD | NEW |