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 class Dropbox(WebsiteTest): | 25 class Dropbox(WebsiteTest): |
23 | 26 |
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
499 xml = "<result>" | 502 xml = "<result>" |
500 for (name, test_type, success, failure_log) in environment_tests_results: | 503 for (name, test_type, success, failure_log) in environment_tests_results: |
501 if not (save_only_fails and success): | 504 if not (save_only_fails and success): |
502 xml += ( | 505 xml += ( |
503 "<test name='{0}' successful='{1}' type='{2}'>{3}</test>".format( | 506 "<test name='{0}' successful='{1}' type='{2}'>{3}</test>".format( |
504 name, success, test_type, failure_log)) | 507 name, success, test_type, failure_log)) |
505 xml += "</result>" | 508 xml += "</result>" |
506 with open(environment_save_path, "w") as save_file: | 509 with open(environment_save_path, "w") as save_file: |
507 save_file.write(xml) | 510 save_file.write(xml) |
508 | 511 |
512 | |
melandory
2015/04/16 08:48:00
This is intentional: there are two empty lines bet
vabr (Chromium)
2015/04/16 10:48:16
Acknowledged.
| |
509 def RunTest(chrome_path, chromedriver_path, profile_path, | 513 def RunTest(chrome_path, chromedriver_path, profile_path, |
510 environment_passwords_path, website_test_name, test_case_name): | 514 environment_passwords_path, website_test_name, |
515 test_case_name): | |
511 """Runs the test for the specified website. | 516 """Runs the test for the specified website. |
512 | 517 |
513 Args: | 518 Args: |
514 chrome_path: The chrome binary file. | 519 chrome_path: The chrome binary file. |
515 chromedriver_path: The chromedriver binary file. | 520 chromedriver_path: The chromedriver binary file. |
516 profile_path: The chrome testing profile folder. | 521 profile_path: The chrome testing profile folder. |
517 environment_passwords_path: The usernames and passwords file. | 522 environment_passwords_path: The usernames and passwords file. |
518 website_test_name: Name of the website to test (refer to keys in | 523 website_test_name: Name of the website to test (refer to keys in |
519 all_tests above). | 524 all_tests above). |
520 | 525 |
521 Returns: | 526 Returns: |
522 The results of the test as list of TestResults. | 527 The results of the test as list of TestResults. |
523 | 528 |
524 Raises: | 529 Raises: |
525 Exception: An exception is raised if one of the tests for the website | 530 Exception: An exception is raised if one of the tests for the website |
526 fails, or if the website name is not known. | 531 fails, or if the website name is not known. |
527 """ | 532 """ |
528 | 533 |
529 enable_automatic_password_saving = (test_case_name == "SaveAndAutofillTest") | 534 enable_automatic_password_saving = (test_case_name == "SaveAndAutofillTest") |
530 environment = Environment(chrome_path, chromedriver_path, profile_path, | 535 environment = Environment(chrome_path, chromedriver_path, profile_path, |
531 environment_passwords_path, | 536 environment_passwords_path, |
532 enable_automatic_password_saving) | 537 enable_automatic_password_saving) |
538 try: | |
539 if website_test_name in all_tests: | |
540 environment.AddWebsiteTest(all_tests[website_test_name]) | |
541 else: | |
542 raise Exception("Test name {} is unknown.".format(website_test_name)) | |
533 | 543 |
534 if website_test_name in all_tests: | 544 environment.RunTestsOnSites(test_case_name) |
535 environment.AddWebsiteTest(all_tests[website_test_name]) | 545 return environment.tests_results |
536 else: | 546 finally: |
537 raise Exception("Test name {} is unknown.".format(website_test_name)) | 547 environment.Quit() |
538 | |
539 environment.RunTestsOnSites(test_case_name) | |
540 environment.Quit() | |
541 return environment.tests_results | |
542 | 548 |
543 def main(): | 549 def main(): |
544 parser = argparse.ArgumentParser( | 550 parser = argparse.ArgumentParser( |
545 description="Password Manager automated tests help.") | 551 description="Password Manager automated tests help.") |
546 | 552 |
547 parser.add_argument( | 553 parser.add_argument( |
548 "--chrome-path", action="store", dest="chrome_path", | 554 "--chrome-path", action="store", dest="chrome_path", |
549 help="Set the chrome path (required).", required=True) | 555 help="Set the chrome path (required).", required=True) |
550 parser.add_argument( | 556 parser.add_argument( |
551 "--chromedriver-path", action="store", dest="chromedriver_path", | 557 "--chromedriver-path", action="store", dest="chromedriver_path", |
(...skipping 20 matching lines...) Expand all Loading... | |
572 parser.add_argument("--test-cases-to-run", help="Names of test cases which" | 578 parser.add_argument("--test-cases-to-run", help="Names of test cases which" |
573 "should be run. Currently supported test cases are:" | 579 "should be run. Currently supported test cases are:" |
574 "PromptFailTest, PromptSuccessTest, SaveAndAutofillTest", | 580 "PromptFailTest, PromptSuccessTest, SaveAndAutofillTest", |
575 dest="test_cases_to_run", action="store", nargs="*") | 581 dest="test_cases_to_run", action="store", nargs="*") |
576 args = parser.parse_args() | 582 args = parser.parse_args() |
577 | 583 |
578 save_path = None | 584 save_path = None |
579 if args.save_path: | 585 if args.save_path: |
580 save_path = args.save_path | 586 save_path = args.save_path |
581 | 587 |
582 test_cases_to_run = args.test_cases_to_run or\ | 588 test_cases_to_run = args.test_cases_to_run or TEST_CASES |
vabr (Chromium)
2015/04/16 10:48:16
nit: Could you please add a TODO about validating
melandory
2015/04/16 14:38:29
TODO is in this CL:
https://codereview.chromium.or
vabr (Chromium)
2015/04/16 14:55:43
Acknowledged. I should have remembered that, thank
| |
583 ("PromptFailTest", "PromptSuccessTest", "SaveAndAutofillTest") | |
584 | |
585 for test_case in test_cases_to_run: | 589 for test_case in test_cases_to_run: |
586 tests_results = RunTest( | 590 tests_results = RunTest( |
587 args.chrome_path, args.chromedriver_path, args.profile_path, | 591 args.chrome_path, args.chromedriver_path, args.profile_path, |
588 args.passwords_path, args.website, test_case) | 592 args.passwords_path, args.website, test_case) |
589 | 593 |
590 | 594 |
591 SaveResults(tests_results, save_path, save_only_fails=args.save_only_fails) | 595 SaveResults(tests_results, save_path, save_only_fails=args.save_only_fails) |
592 | 596 |
593 if __name__ == "__main__": | 597 if __name__ == "__main__": |
594 main() | 598 main() |
OLD | NEW |