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 import logging | 9 import logging |
engedy
2015/03/26 16:18:55
I think this can be removed.
vabr (Chromium)
2015/03/26 18:01:50
Done.
| |
10 | 10 |
11 from environment import Environment | 11 from environment import Environment |
12 from websitetest import WebsiteTest | 12 from websitetest import WebsiteTest |
13 | 13 |
14 | 14 |
15 class TypeOfTestedWebsites: | |
16 """An enum to specify which groups of tests to run.""" | |
17 # Runs all the tests. | |
18 ALL_TESTS = 0 | |
19 # Runs a specified list of tests. | |
20 LIST_OF_TESTS = 1 | |
21 | |
22 def __init__(self): | |
23 pass | |
24 | |
25 | |
26 class Alexa(WebsiteTest): | 15 class Alexa(WebsiteTest): |
27 | 16 |
28 def Login(self): | 17 def Login(self): |
29 self.GoTo("https://www.alexa.com/secure/login") | 18 self.GoTo("https://www.alexa.com/secure/login") |
30 self.FillUsernameInto("#email") | 19 self.FillUsernameInto("#email") |
31 self.FillPasswordInto("#pwd") | 20 self.FillPasswordInto("#pwd") |
32 self.Submit("#pwd") | 21 self.Submit("#pwd") |
33 | 22 |
34 | 23 |
35 class Dropbox(WebsiteTest): | 24 class Dropbox(WebsiteTest): |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
438 # Password not saved. | 427 # Password not saved. |
439 class Ziddu(WebsiteTest): | 428 class Ziddu(WebsiteTest): |
440 | 429 |
441 def Login(self): | 430 def Login(self): |
442 self.GoTo("http://www.ziddu.com/login.php") | 431 self.GoTo("http://www.ziddu.com/login.php") |
443 self.FillUsernameInto("#email") | 432 self.FillUsernameInto("#email") |
444 self.FillPasswordInto("#password") | 433 self.FillPasswordInto("#password") |
445 self.Click(".login input") | 434 self.Click(".login input") |
446 | 435 |
447 | 436 |
448 def Tests(environment, tests_to_run=None): | 437 all_tests = { |
438 "163": One63("163"), # http://crbug.com/368690 | |
439 "adobe": Adobe("adobe"), # Password saving not offered. | |
440 "alexa": Alexa("alexa"), | |
441 "aliexpress": Aliexpress("aliexpress"), # Fails due to test framework issue. | |
442 "amazon": Amazon("amazon"), # Bug not reproducible without test. | |
443 "ask": Ask("ask"), # Password not saved. | |
444 "baidu": Baidu("baidu"), # Password not saved. | |
445 "cnn": Cnn("cnn"), # http://crbug.com/368690 | |
446 "craigslist": Craigslist("craigslist"), # Too many failed logins per time. | |
447 "dailymotion": Dailymotion("dailymotion"), # Crashes. | |
448 "dropbox": Dropbox("dropbox"), | |
449 "ebay": Ebay("ebay"), # http://crbug.com/368690 | |
450 "espn": Espn("espn"), # Iframe, password saved but not autofilled. | |
451 "facebook": Facebook("facebook"), | |
452 "flipkart": Flipkart("flipkart"), # Fails due to test framework issue. | |
453 "github": Github("github"), | |
454 "google": Google("google"), | |
455 "imgur": Imgur("imgur"), | |
456 "instagram": Instagram("instagram"), # Iframe, pw saved but not autofilled. | |
457 "linkedin": Linkedin("linkedin"), | |
458 "liveinternet": Liveinternet("liveinternet"), | |
459 "live": Live("live", username_not_auto=True), # http://crbug.com/367768 | |
460 "mailru": Mailru("mailru"), | |
461 "nytimes": Nytimes("nytimes"), | |
462 "odnoklassniki": Odnoklassniki("odnoklassniki"), | |
463 "pinterest": Pinterest("pinterest"), | |
464 "reddit": Reddit("reddit", username_not_auto=True), | |
465 "stackexchange": StackExchange("stackexchange"), # Iframe, not autofilled. | |
466 "tumblr": Tumblr("tumblr", username_not_auto=True), | |
467 "twitter": Twitter("twitter"), | |
468 "vkontakte": Vkontakte("vkontakte"), | |
469 "vube": Vube("vube"), # http://crbug.com/368690 | |
470 "wikia": Wikia("wikia"), | |
471 "wikipedia": Wikipedia("wikipedia", username_not_auto=True), | |
472 "wordpress": Wordpress("wordpress"), | |
473 "yahoo": Yahoo("yahoo", username_not_auto=True), | |
474 "yandex": Yandex("yandex"), | |
475 "ziddu": Ziddu("ziddu"), # Password not saved. | |
476 } | |
449 | 477 |
450 all_tests = { | |
451 "163": One63("163"), # http://crbug.com/368690 | |
452 "adobe": Adobe("adobe"), # Password saving not offered. | |
453 "alexa": Alexa("alexa"), | |
454 "aliexpress": Aliexpress("aliexpress"), # Fails due to test framework issue. | |
455 "amazon": Amazon("amazon"), # Bug not reproducible without test. | |
456 "ask": Ask("ask"), # Password not saved. | |
457 "baidu": Baidu("baidu"), # Password not saved. | |
458 "cnn": Cnn("cnn"), # http://crbug.com/368690 | |
459 "craigslist": Craigslist("craigslist"), # Too many failed logins per time. | |
460 "dailymotion": Dailymotion("dailymotion"), # Crashes. | |
461 "dropbox": Dropbox("dropbox"), | |
462 "ebay": Ebay("ebay"), # http://crbug.com/368690 | |
463 "espn": Espn("espn"), # Iframe, password saved but not autofilled. | |
464 "facebook": Facebook("facebook"), | |
465 "flipkart": Flipkart("flipkart"), # Fails due to test framework issue. | |
466 "github": Github("github"), | |
467 "google": Google("google"), | |
468 "imgur": Imgur("imgur"), | |
469 "instagram": Instagram("instagram"), # Iframe, pw saved but not autofilled. | |
470 "linkedin": Linkedin("linkedin"), | |
471 "liveinternet": Liveinternet("liveinternet"), | |
472 "live": Live("live", username_not_auto=True), # http://crbug.com/367768 | |
473 "mailru": Mailru("mailru"), | |
474 "nytimes": Nytimes("nytimes"), | |
475 "odnoklassniki": Odnoklassniki("odnoklassniki"), | |
476 "pinterest": Pinterest("pinterest"), | |
477 "reddit": Reddit("reddit", username_not_auto=True), | |
478 "stackexchange": StackExchange("stackexchange"), # Iframe, not autofilled. | |
479 "tumblr": Tumblr("tumblr", username_not_auto=True), | |
480 "twitter": Twitter("twitter"), | |
481 "vkontakte": Vkontakte("vkontakte"), | |
482 "vube": Vube("vube"), # http://crbug.com/368690 | |
483 "wikia": Wikia("wikia"), | |
484 "wikipedia": Wikipedia("wikipedia", username_not_auto=True), | |
485 "wordpress": Wordpress("wordpress"), | |
486 "yahoo": Yahoo("yahoo", username_not_auto=True), | |
487 "yandex": Yandex("yandex"), | |
488 "ziddu": Ziddu("ziddu"), # Password not saved. | |
489 } | |
490 | 478 |
491 tests_to_run = tests_to_run or all_tests.keys() | 479 def Tests(environment, test_to_run): |
engedy
2015/03/26 16:18:55
nit: Do we even need this function? (Fine to leave
vabr (Chromium)
2015/03/26 18:01:50
Good call, removed.
Done.
| |
492 for test_name in tests_to_run: | 480 """Initialize |environment| with the test to run. |
493 if test_name in all_tests.keys(): | 481 |
494 environment.AddWebsiteTest(all_tests[test_name]) | 482 TODO(vabr): If we end up using 1 environment for 1 tests, we need to |
483 reconsider the structure and make some things more direct. | |
484 | |
485 test_to_run: The name of the test to be run. This is a key for | |
486 |all_tests| dictionary above. | |
487 """ | |
488 | |
489 if test_to_run in all_tests.keys(): | |
engedy
2015/03/26 16:18:55
nit: We could just use the 'in' operator.
vabr (Chromium)
2015/03/26 18:01:50
You meant -- use it on the dictionary directly?
Th
engedy
2015/03/26 18:04:54
Yes, that's what I meant.
| |
490 environment.AddWebsiteTest(all_tests[test_to_run]) | |
495 | 491 |
496 | 492 |
497 def saveResults(environment_tests_results, environment_save_path): | 493 def saveResults(environment_tests_results, environment_save_path): |
498 """Save the test results in an xml file. | 494 """Save the test results in an xml file. |
499 | 495 |
500 Args: | 496 Args: |
501 environment_tests_results: A list of the TestResults that are going to be | 497 environment_tests_results: A list of the TestResults that are going to be |
502 saved. | 498 saved. |
503 environment_save_path: The file where the results are going to be saved. | 499 environment_save_path: The file where the results are going to be saved. |
504 If it's None, the results are not going to be stored. | 500 If it's None, the results are not going to be stored. |
505 Raises: | 501 Raises: |
506 Exception: An exception is raised if the file is not found. | 502 Exception: An exception is raised if the file is not found. |
507 """ | 503 """ |
508 if environment_save_path: | 504 if environment_save_path: |
509 xml = "<result>" | 505 xml = "<result>" |
510 for test_result in environment_tests_results: | 506 for test_result in environment_tests_results: |
511 xml += ("<test name='%s' successful='%s' type='%s'>%s</test>" | 507 xml += ("<test name='%s' successful='%s' type='%s'>%s</test>" |
512 % (test_result.name, str(test_result.successful), | 508 % (test_result.name, str(test_result.successful), |
513 test_result.test_type, test_result.message)) | 509 test_result.test_type, test_result.message)) |
514 xml += "</result>" | 510 xml += "</result>" |
515 with open(environment_save_path, "w") as save_file: | 511 with open(environment_save_path, "w") as save_file: |
516 save_file.write(xml) | 512 save_file.write(xml) |
517 | 513 |
518 def RunTests(chrome_path, chromedriver_path, profile_path, | 514 def RunTests(chrome_path, chromedriver_path, profile_path, |
engedy
2015/03/26 16:18:55
nit: Rename this to RunTest if it does not interfe
vabr (Chromium)
2015/03/26 18:01:50
Done.
| |
519 environment_passwords_path, enable_automatic_password_saving, | 515 environment_passwords_path, enable_automatic_password_saving, |
520 environment_numeric_level, log_to_console, environment_log_file, | 516 test_to_run): |
521 environment_tested_websites, tests=None): | |
522 | 517 |
523 """Runs the the tests | 518 """Runs the the tests |
engedy
2015/03/26 16:18:55
typo/nit: Runs the specified test.
vabr (Chromium)
2015/03/26 18:01:50
I actually rephrased a bit more, because there was
engedy
2015/03/26 18:04:54
Acknowledged.
| |
524 | 519 |
525 Args: | 520 Args: |
526 chrome_path: The chrome binary file. | 521 chrome_path: The chrome binary file. |
527 chromedriver_path: The chromedriver binary file. | 522 chromedriver_path: The chromedriver binary file. |
528 profile_path: The chrome testing profile folder. | 523 profile_path: The chrome testing profile folder. |
529 environment_passwords_path: The usernames and passwords file. | 524 environment_passwords_path: The usernames and passwords file. |
530 enable_automatic_password_saving: If True, the passwords are going to be | 525 enable_automatic_password_saving: If True, the passwords are going to be |
531 saved without showing the prompt. | 526 saved without showing the prompt. |
532 environment_numeric_level: The log verbosity. | 527 test_to_run: Name of the test to run. |
533 log_to_console: If True, the debug logs will be shown on the console. | |
534 environment_log_file: The file where to store the log. If it's empty, the | |
535 log is not stored. | |
536 environment_tested_websites: One of the TypeOfTestedWebsites values, | |
537 indicating which group of tests to run. | |
538 tests: Specifies which tests to run. Ignored unless | |
539 |environment_tested_websites| is equal to LIST_OF_TESTS. | |
540 | 528 |
541 Returns: | 529 Returns: |
542 The results of tests as list of TestResults. | 530 The results of tests as list of TestResults. |
531 | |
543 Raises: | 532 Raises: |
544 Exception: An exception is raised if one of the tests fails. | 533 Exception: An exception is raised if one of the tests fails. |
545 """ | 534 """ |
546 | 535 |
547 environment = Environment(chrome_path, chromedriver_path, profile_path, | 536 environment = Environment(chrome_path, chromedriver_path, profile_path, |
548 environment_passwords_path, | 537 environment_passwords_path, |
549 enable_automatic_password_saving, | 538 enable_automatic_password_saving) |
550 environment_numeric_level, | |
551 log_to_console, | |
552 environment_log_file) | |
553 | 539 |
554 # Test which care about the save-password prompt need the prompt | 540 # Test which care about the save-password prompt need the prompt |
555 # to be shown. Automatic password saving results in no prompt. | 541 # to be shown. Automatic password saving results in no prompt. |
556 run_prompt_tests = not enable_automatic_password_saving | 542 run_prompt_tests = not enable_automatic_password_saving |
557 | 543 |
558 Tests(environment, tests) | 544 Tests(environment, test_to_run) |
559 | 545 |
560 if environment_tested_websites == TypeOfTestedWebsites.ALL_TESTS: | 546 environment.AllTests(run_prompt_tests) |
561 environment.AllTests(run_prompt_tests) | |
562 elif environment_tested_websites == TypeOfTestedWebsites.LIST_OF_TESTS: | |
563 environment.Test(tests, run_prompt_tests) | |
564 else: | |
565 raise Exception("Error: |environment_tested_websites| has to be one of the" | |
566 "TypeOfTestedWebsites values") | |
567 | |
568 | 547 |
569 environment.Quit() | 548 environment.Quit() |
570 return environment.tests_results | 549 return environment.tests_results |
571 | 550 |
572 # Tests setup. | 551 # Tests setup. |
573 if __name__ == "__main__": | 552 if __name__ == "__main__": |
574 parser = argparse.ArgumentParser( | 553 parser = argparse.ArgumentParser( |
575 description="Password Manager automated tests help.") | 554 description="Password Manager automated tests help.") |
576 | 555 |
577 parser.add_argument( | 556 parser.add_argument( |
578 "--chrome-path", action="store", dest="chrome_path", | 557 "--chrome-path", action="store", dest="chrome_path", |
579 help="Set the chrome path (required).", nargs=1, required=True) | 558 help="Set the chrome path (required).", required=True) |
580 parser.add_argument( | 559 parser.add_argument( |
581 "--chromedriver-path", action="store", dest="chromedriver_path", | 560 "--chromedriver-path", action="store", dest="chromedriver_path", |
582 help="Set the chromedriver path (required).", nargs=1, required=True) | 561 help="Set the chromedriver path (required).", required=True) |
583 parser.add_argument( | 562 parser.add_argument( |
584 "--profile-path", action="store", dest="profile_path", | 563 "--profile-path", action="store", dest="profile_path", |
585 help="Set the profile path (required). You just need to choose a " | 564 help="Set the profile path (required). You just need to choose a " |
586 "temporary empty folder. If the folder is not empty all its content " | 565 "temporary empty folder. If the folder is not empty all its content " |
587 "is going to be removed.", | 566 "is going to be removed.", |
588 nargs=1, required=True) | 567 required=True) |
589 | 568 |
590 parser.add_argument( | 569 parser.add_argument( |
591 "--passwords-path", action="store", dest="passwords_path", | 570 "--passwords-path", action="store", dest="passwords_path", |
592 help="Set the usernames/passwords path (required).", nargs=1, | 571 help="Set the usernames/passwords path (required).", required=True) |
593 required=True) | 572 parser.add_argument("--save-path", action="store", dest="save_path", |
594 parser.add_argument("--log", action="store", nargs=1, dest="log_level", | |
595 help="Set log level.") | |
596 parser.add_argument("--log-screen", action="store_true", dest="log_screen", | |
597 help="Show log on the screen.") | |
598 parser.add_argument("--log-file", action="store", dest="log_file", | |
599 help="Write the log in a file.", nargs=1) | |
600 parser.add_argument("--save-path", action="store", nargs=1, dest="save_path", | |
601 help="Write the results in a file.") | 573 help="Write the results in a file.") |
602 parser.add_argument("tests", help="Tests to be run.", nargs="*") | 574 parser.add_argument("test", help="Test to be run.") |
603 | 575 |
604 args = parser.parse_args() | 576 args = parser.parse_args() |
605 | 577 |
606 passwords_path = args.passwords_path[0] | |
607 | |
608 tested_websites = TypeOfTestedWebsites.ALL_TESTS | |
609 if args.tests: | |
610 tested_websites = TypeOfTestedWebsites.LIST_OF_TESTS | |
611 | |
612 numeric_level = None | |
613 if args.log_level: | |
614 numeric_level = getattr(logging, args.log_level[0].upper(), None) | |
615 if not isinstance(numeric_level, int): | |
616 raise ValueError("Invalid log level: %s" % args.log_level[0]) | |
617 | |
618 log_file = None | |
619 if args.log_file: | |
620 log_file = args.log_file[0] | |
621 | |
622 save_path = None | 578 save_path = None |
623 if args.save_path: | 579 if args.save_path: |
624 save_path = args.save_path[0] | 580 save_path = args.save_path |
625 | 581 |
626 # Run the test without enable-automatic-password-saving to check whether or | 582 # Run the test without enable-automatic-password-saving to check whether or |
627 # not the prompt is shown in the way we expected. | 583 # not the prompt is shown in the way we expected. |
628 tests_results = RunTests(args.chrome_path[0], | 584 tests_results = RunTests(args.chrome_path, |
629 args.chromedriver_path[0], | 585 args.chromedriver_path, |
630 args.profile_path[0], | 586 args.profile_path, |
631 passwords_path, | 587 args.passwords_path, |
632 False, | 588 False, |
633 numeric_level, | 589 args.test) |
634 args.log_screen, | |
635 log_file, | |
636 tested_websites, | |
637 args.tests) | |
638 | 590 |
639 # Run the test with enable-automatic-password-saving to check whether or not | 591 # Run the test with enable-automatic-password-saving to check whether or not |
640 # the passwords is stored in the the way we expected. | 592 # the passwords is stored in the the way we expected. |
641 tests_results += RunTests(args.chrome_path[0], | 593 tests_results += RunTests(args.chrome_path, |
642 args.chromedriver_path[0], | 594 args.chromedriver_path, |
643 args.profile_path[0], | 595 args.profile_path, |
644 passwords_path, | 596 args.passwords_path, |
645 True, | 597 True, |
646 numeric_level, | 598 args.test) |
647 args.log_screen, | |
648 log_file, | |
649 tested_websites, | |
650 args.tests) | |
651 | 599 |
652 saveResults(tests_results, save_path) | 600 saveResults(tests_results, save_path) |
OLD | NEW |