Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1116)

Side by Side Diff: components/test/data/password_manager/automated_tests/tests.py

Issue 1084553003: [Password manager tests automation] Adds an ability to specify test_case which should be run. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@save_only_errors
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 487 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 for (name, test_type, success, failure_log) in environment_tests_results: 498 for (name, test_type, success, failure_log) in environment_tests_results:
499 if not (save_only_failures and success): 499 if not (save_only_failures and success):
500 xml += ( 500 xml += (
501 "<test name='{0}' successful='{1}' type='{2}'>{3}</test>".format( 501 "<test name='{0}' successful='{1}' type='{2}'>{3}</test>".format(
502 name, success, test_type, failure_log)) 502 name, success, test_type, failure_log))
503 xml += "</result>" 503 xml += "</result>"
504 with open(environment_save_path, "w") as save_file: 504 with open(environment_save_path, "w") as save_file:
505 save_file.write(xml) 505 save_file.write(xml)
506 506
507 def RunTest(chrome_path, chromedriver_path, profile_path, 507 def RunTest(chrome_path, chromedriver_path, profile_path,
508 environment_passwords_path, website_test_name, test_type): 508 environment_passwords_path, website_test_name, test_case_name):
509 """Runs the test for the specified website. 509 """Runs the test for the specified website.
510 510
511 Args: 511 Args:
512 chrome_path: The chrome binary file. 512 chrome_path: The chrome binary file.
513 chromedriver_path: The chromedriver binary file. 513 chromedriver_path: The chromedriver binary file.
514 profile_path: The chrome testing profile folder. 514 profile_path: The chrome testing profile folder.
515 environment_passwords_path: The usernames and passwords file. 515 environment_passwords_path: The usernames and passwords file.
516 website_test_name: Name of the website to test (refer to keys in 516 website_test_name: Name of the website to test (refer to keys in
517 all_tests above). 517 all_tests above).
518 518
519 Returns: 519 Returns:
520 The results of the test as list of TestResults. 520 The results of the test as list of TestResults.
521 521
522 Raises: 522 Raises:
523 Exception: An exception is raised if one of the tests for the website 523 Exception: An exception is raised if one of the tests for the website
524 fails, or if the website name is not known. 524 fails, or if the website name is not known.
525 """ 525 """
526 526
527 enable_automatic_password_saving = ( 527 enable_automatic_password_saving = (test_case_name == "SaveAndAutofillTest")
528 test_type == WebsiteTest.TEST_TYPE_SAVE_AND_AUTOFILL)
529 environment = Environment(chrome_path, chromedriver_path, profile_path, 528 environment = Environment(chrome_path, chromedriver_path, profile_path,
530 environment_passwords_path, 529 environment_passwords_path,
531 enable_automatic_password_saving) 530 enable_automatic_password_saving)
532 531
533 if website_test_name in all_tests: 532 if website_test_name in all_tests:
534 environment.AddWebsiteTest(all_tests[website_test_name]) 533 environment.AddWebsiteTest(all_tests[website_test_name])
535 else: 534 else:
536 raise Exception("Test name {} is unknown.".format(website_test_name)) 535 raise Exception("Test name {} is unknown.".format(website_test_name))
537 536
538 environment.RunTestsOnSites(test_type) 537 environment.RunTestsOnSites(test_case_name)
539 environment.Quit() 538 environment.Quit()
540 return environment.tests_results 539 return environment.tests_results
541 540
542 def main(): 541 def main():
543 parser = argparse.ArgumentParser( 542 parser = argparse.ArgumentParser(
544 description="Password Manager automated tests help.") 543 description="Password Manager automated tests help.")
545 544
546 parser.add_argument( 545 parser.add_argument(
547 "--chrome-path", action="store", dest="chrome_path", 546 "--chrome-path", action="store", dest="chrome_path",
548 help="Set the chrome path (required).", required=True) 547 help="Set the chrome path (required).", required=True)
549 parser.add_argument( 548 parser.add_argument(
550 "--chromedriver-path", action="store", dest="chromedriver_path", 549 "--chromedriver-path", action="store", dest="chromedriver_path",
551 help="Set the chromedriver path (required).", required=True) 550 help="Set the chromedriver path (required).", required=True)
552 parser.add_argument( 551 parser.add_argument(
553 "--profile-path", action="store", dest="profile_path", 552 "--profile-path", action="store", dest="profile_path",
554 help="Set the profile path (required). You just need to choose a " 553 help="Set the profile path (required). You just need to choose a "
555 "temporary empty folder. If the folder is not empty all its content " 554 "temporary empty folder. If the folder is not empty all its content "
556 "is going to be removed.", 555 "is going to be removed.",
557 required=True) 556 required=True)
558 557
559 parser.add_argument( 558 parser.add_argument(
560 "--passwords-path", action="store", dest="passwords_path", 559 "--passwords-path", action="store", dest="passwords_path",
561 help="Set the usernames/passwords path (required).", required=True) 560 help="Set the usernames/passwords path (required).", required=True)
562 parser.add_argument("--save-path", action="store", dest="save_path", 561 parser.add_argument("--save-path", action="store", dest="save_path",
563 help="Write the results in a file.") 562 help="Write the results in a file.")
564 parser.add_argument("test", help="Test to be run.")
565 parser.add_argument("--save-only-failures", 563 parser.add_argument("--save-only-failures",
566 help="Only save logs for failing tests.", 564 help="Only save logs for failing tests.",
567 dest="save_only_failures", action="store_true", 565 dest="save_only_failures", action="store_true",
568 default=False) 566 parser.add_argument("website", help="Website test name on which"
569 567 "tests should be run.")
568 parser.add_argument("--test-cases-to-run", help="Names of test cases which"
569 "should be run. Currently supported test cases are:"
570 "PromptFailTest, PromptSuccessTest, SaveAndAutofillTest",
571 dest="test_cases_to_run", action="store", nargs="*")
570 args = parser.parse_args() 572 args = parser.parse_args()
571 573
572 save_path = None 574 save_path = None
573 if args.save_path: 575 if args.save_path:
574 save_path = args.save_path 576 save_path = args.save_path
575 577
576 tests_results = RunTest( 578 test_cases_to_run = args.test_cases_to_run or\
577 args.chrome_path, args.chromedriver_path, args.profile_path, 579 ("PromptFailTest", "PromptSuccessTest", "SaveAndAutofillTest")
578 args.passwords_path, args.test, WebsiteTest.TEST_TYPE_PROMPT_FAIL)
579 580
580 tests_results += RunTest( 581 for test_case in test_cases_to_run:
581 args.chrome_path, args.chromedriver_path, args.profile_path, 582 tests_results = RunTest(
582 args.passwords_path, args.test, WebsiteTest.TEST_TYPE_PROMPT_SUCCESS) 583 args.chrome_path, args.chromedriver_path, args.profile_path,
584 args.passwords_path, args.website, test_case)
583 585
584 tests_results += RunTest(
585 args.chrome_path, args.chromedriver_path, args.profile_path,
586 args.passwords_path, args.test, WebsiteTest.TEST_TYPE_SAVE_AND_AUTOFILL)
587 586
588 SaveResults(tests_results, save_path, 587 SaveResults(tests_results, save_path,
589 save_only_failures=args.save_only_failures) 588 save_only_failures=args.save_only_failures)
590 589
591 if __name__ == "__main__": 590 if __name__ == "__main__":
592 main() 591 main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698