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

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

Issue 1022703004: [Password manager Python tests] Remove some dead code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@369521_remove_disabled_tests
Patch Set: Comments addressed 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 import logging
10 9
11 from environment import Environment 10 from environment import Environment
12 from websitetest import WebsiteTest 11 from websitetest import WebsiteTest
13 12
14 13
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): 14 class Alexa(WebsiteTest):
27 15
28 def Login(self): 16 def Login(self):
29 self.GoTo("https://www.alexa.com/secure/login") 17 self.GoTo("https://www.alexa.com/secure/login")
30 self.FillUsernameInto("#email") 18 self.FillUsernameInto("#email")
31 self.FillPasswordInto("#pwd") 19 self.FillPasswordInto("#pwd")
32 self.Submit("#pwd") 20 self.Submit("#pwd")
33 21
34 22
35 class Dropbox(WebsiteTest): 23 class Dropbox(WebsiteTest):
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 # Password not saved. 426 # Password not saved.
439 class Ziddu(WebsiteTest): 427 class Ziddu(WebsiteTest):
440 428
441 def Login(self): 429 def Login(self):
442 self.GoTo("http://www.ziddu.com/login.php") 430 self.GoTo("http://www.ziddu.com/login.php")
443 self.FillUsernameInto("#email") 431 self.FillUsernameInto("#email")
444 self.FillPasswordInto("#password") 432 self.FillPasswordInto("#password")
445 self.Click(".login input") 433 self.Click(".login input")
446 434
447 435
448 def Tests(environment, tests_to_run=None): 436 all_tests = {
449 437 "163": One63("163"), # http://crbug.com/368690
450 all_tests = { 438 "adobe": Adobe("adobe"), # Password saving not offered.
451 "163": One63("163"), # http://crbug.com/368690 439 "alexa": Alexa("alexa"),
452 "adobe": Adobe("adobe"), # Password saving not offered. 440 "aliexpress": Aliexpress("aliexpress"), # Fails due to test framework issue.
453 "alexa": Alexa("alexa"), 441 "amazon": Amazon("amazon"), # Bug not reproducible without test.
454 "aliexpress": Aliexpress("aliexpress"), # Fails due to test framework issue. 442 "ask": Ask("ask"), # Password not saved.
455 "amazon": Amazon("amazon"), # Bug not reproducible without test. 443 "baidu": Baidu("baidu"), # Password not saved.
456 "ask": Ask("ask"), # Password not saved. 444 "cnn": Cnn("cnn"), # http://crbug.com/368690
457 "baidu": Baidu("baidu"), # Password not saved. 445 "craigslist": Craigslist("craigslist"), # Too many failed logins per time.
458 "cnn": Cnn("cnn"), # http://crbug.com/368690 446 "dailymotion": Dailymotion("dailymotion"), # Crashes.
459 "craigslist": Craigslist("craigslist"), # Too many failed logins per time. 447 "dropbox": Dropbox("dropbox"),
460 "dailymotion": Dailymotion("dailymotion"), # Crashes. 448 "ebay": Ebay("ebay"), # http://crbug.com/368690
461 "dropbox": Dropbox("dropbox"), 449 "espn": Espn("espn"), # Iframe, password saved but not autofilled.
462 "ebay": Ebay("ebay"), # http://crbug.com/368690 450 "facebook": Facebook("facebook"),
463 "espn": Espn("espn"), # Iframe, password saved but not autofilled. 451 "flipkart": Flipkart("flipkart"), # Fails due to test framework issue.
464 "facebook": Facebook("facebook"), 452 "github": Github("github"),
465 "flipkart": Flipkart("flipkart"), # Fails due to test framework issue. 453 "google": Google("google"),
466 "github": Github("github"), 454 "imgur": Imgur("imgur"),
467 "google": Google("google"), 455 "instagram": Instagram("instagram"), # Iframe, pw saved but not autofilled.
468 "imgur": Imgur("imgur"), 456 "linkedin": Linkedin("linkedin"),
469 "instagram": Instagram("instagram"), # Iframe, pw saved but not autofilled. 457 "liveinternet": Liveinternet("liveinternet"),
470 "linkedin": Linkedin("linkedin"), 458 "live": Live("live", username_not_auto=True), # http://crbug.com/367768
471 "liveinternet": Liveinternet("liveinternet"), 459 "mailru": Mailru("mailru"),
472 "live": Live("live", username_not_auto=True), # http://crbug.com/367768 460 "nytimes": Nytimes("nytimes"),
473 "mailru": Mailru("mailru"), 461 "odnoklassniki": Odnoklassniki("odnoklassniki"),
474 "nytimes": Nytimes("nytimes"), 462 "pinterest": Pinterest("pinterest"),
475 "odnoklassniki": Odnoklassniki("odnoklassniki"), 463 "reddit": Reddit("reddit", username_not_auto=True),
476 "pinterest": Pinterest("pinterest"), 464 "stackexchange": StackExchange("stackexchange"), # Iframe, not autofilled.
477 "reddit": Reddit("reddit", username_not_auto=True), 465 "tumblr": Tumblr("tumblr", username_not_auto=True),
478 "stackexchange": StackExchange("stackexchange"), # Iframe, not autofilled. 466 "twitter": Twitter("twitter"),
479 "tumblr": Tumblr("tumblr", username_not_auto=True), 467 "vkontakte": Vkontakte("vkontakte"),
480 "twitter": Twitter("twitter"), 468 "vube": Vube("vube"), # http://crbug.com/368690
481 "vkontakte": Vkontakte("vkontakte"), 469 "wikia": Wikia("wikia"),
482 "vube": Vube("vube"), # http://crbug.com/368690 470 "wikipedia": Wikipedia("wikipedia", username_not_auto=True),
483 "wikia": Wikia("wikia"), 471 "wordpress": Wordpress("wordpress"),
484 "wikipedia": Wikipedia("wikipedia", username_not_auto=True), 472 "yahoo": Yahoo("yahoo", username_not_auto=True),
485 "wordpress": Wordpress("wordpress"), 473 "yandex": Yandex("yandex"),
486 "yahoo": Yahoo("yahoo", username_not_auto=True), 474 "ziddu": Ziddu("ziddu"), # Password not saved.
487 "yandex": Yandex("yandex"), 475 }
488 "ziddu": Ziddu("ziddu"), # Password not saved.
489 }
490
491 tests_to_run = tests_to_run or all_tests.keys()
492 for test_name in tests_to_run:
493 if test_name in all_tests.keys():
494 environment.AddWebsiteTest(all_tests[test_name])
495 476
496 477
497 def saveResults(environment_tests_results, environment_save_path): 478 def saveResults(environment_tests_results, environment_save_path):
498 """Save the test results in an xml file. 479 """Save the test results in an xml file.
499 480
500 Args: 481 Args:
501 environment_tests_results: A list of the TestResults that are going to be 482 environment_tests_results: A list of the TestResults that are going to be
502 saved. 483 saved.
503 environment_save_path: The file where the results are going to be saved. 484 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. 485 If it's None, the results are not going to be stored.
505 Raises: 486 Raises:
506 Exception: An exception is raised if the file is not found. 487 Exception: An exception is raised if the file is not found.
507 """ 488 """
508 if environment_save_path: 489 if environment_save_path:
509 xml = "<result>" 490 xml = "<result>"
510 for test_result in environment_tests_results: 491 for test_result in environment_tests_results:
511 xml += ("<test name='%s' successful='%s' type='%s'>%s</test>" 492 xml += ("<test name='%s' successful='%s' type='%s'>%s</test>"
512 % (test_result.name, str(test_result.successful), 493 % (test_result.name, str(test_result.successful),
513 test_result.test_type, test_result.message)) 494 test_result.test_type, test_result.message))
514 xml += "</result>" 495 xml += "</result>"
515 with open(environment_save_path, "w") as save_file: 496 with open(environment_save_path, "w") as save_file:
516 save_file.write(xml) 497 save_file.write(xml)
517 498
518 def RunTests(chrome_path, chromedriver_path, profile_path, 499 def RunTest(chrome_path, chromedriver_path, profile_path,
519 environment_passwords_path, enable_automatic_password_saving, 500 environment_passwords_path, enable_automatic_password_saving,
520 environment_numeric_level, log_to_console, environment_log_file, 501 website_test_name):
521 environment_tested_websites, tests=None): 502 """Runs the test for the specified website.
522
523 """Runs the the tests
524 503
525 Args: 504 Args:
526 chrome_path: The chrome binary file. 505 chrome_path: The chrome binary file.
527 chromedriver_path: The chromedriver binary file. 506 chromedriver_path: The chromedriver binary file.
528 profile_path: The chrome testing profile folder. 507 profile_path: The chrome testing profile folder.
529 environment_passwords_path: The usernames and passwords file. 508 environment_passwords_path: The usernames and passwords file.
530 enable_automatic_password_saving: If True, the passwords are going to be 509 enable_automatic_password_saving: If True, the passwords are going to be
531 saved without showing the prompt. 510 saved without showing the prompt.
532 environment_numeric_level: The log verbosity. 511 website_test_name: Name of the website to test (refer to keys in
533 log_to_console: If True, the debug logs will be shown on the console. 512 all_tests above).
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 513
541 Returns: 514 Returns:
542 The results of tests as list of TestResults. 515 The results of the test as list of TestResults.
516
543 Raises: 517 Raises:
544 Exception: An exception is raised if one of the tests fails. 518 Exception: An exception is raised if one of the tests for the website
519 fails, or if the website name is not known.
545 """ 520 """
546 521
547 environment = Environment(chrome_path, chromedriver_path, profile_path, 522 environment = Environment(chrome_path, chromedriver_path, profile_path,
548 environment_passwords_path, 523 environment_passwords_path,
549 enable_automatic_password_saving, 524 enable_automatic_password_saving)
550 environment_numeric_level,
551 log_to_console,
552 environment_log_file)
553 525
554 # Test which care about the save-password prompt need the prompt 526 # Test which care about the save-password prompt need the prompt
555 # to be shown. Automatic password saving results in no prompt. 527 # to be shown. Automatic password saving results in no prompt.
556 run_prompt_tests = not enable_automatic_password_saving 528 run_prompt_tests = not enable_automatic_password_saving
557 529
558 Tests(environment, tests) 530 if website_test_name in all_tests:
531 environment.AddWebsiteTest(all_tests[website_test_name])
532 else:
533 raise Exception("Test name {} is unknown.".format(website_test_name))
559 534
560 if environment_tested_websites == TypeOfTestedWebsites.ALL_TESTS: 535 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 536
569 environment.Quit() 537 environment.Quit()
570 return environment.tests_results 538 return environment.tests_results
571 539
572 # Tests setup. 540 # Tests setup.
573 if __name__ == "__main__": 541 if __name__ == "__main__":
574 parser = argparse.ArgumentParser( 542 parser = argparse.ArgumentParser(
575 description="Password Manager automated tests help.") 543 description="Password Manager automated tests help.")
576 544
577 parser.add_argument( 545 parser.add_argument(
578 "--chrome-path", action="store", dest="chrome_path", 546 "--chrome-path", action="store", dest="chrome_path",
579 help="Set the chrome path (required).", nargs=1, required=True) 547 help="Set the chrome path (required).", required=True)
580 parser.add_argument( 548 parser.add_argument(
581 "--chromedriver-path", action="store", dest="chromedriver_path", 549 "--chromedriver-path", action="store", dest="chromedriver_path",
582 help="Set the chromedriver path (required).", nargs=1, required=True) 550 help="Set the chromedriver path (required).", required=True)
583 parser.add_argument( 551 parser.add_argument(
584 "--profile-path", action="store", dest="profile_path", 552 "--profile-path", action="store", dest="profile_path",
585 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 "
586 "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 "
587 "is going to be removed.", 555 "is going to be removed.",
588 nargs=1, required=True) 556 required=True)
589 557
590 parser.add_argument( 558 parser.add_argument(
591 "--passwords-path", action="store", dest="passwords_path", 559 "--passwords-path", action="store", dest="passwords_path",
592 help="Set the usernames/passwords path (required).", nargs=1, 560 help="Set the usernames/passwords path (required).", required=True)
593 required=True) 561 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.") 562 help="Write the results in a file.")
602 parser.add_argument("tests", help="Tests to be run.", nargs="*") 563 parser.add_argument("test", help="Test to be run.")
603 564
604 args = parser.parse_args() 565 args = parser.parse_args()
605 566
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 567 save_path = None
623 if args.save_path: 568 if args.save_path:
624 save_path = args.save_path[0] 569 save_path = args.save_path
625 570
626 # Run the test without enable-automatic-password-saving to check whether or 571 # Run the test without enable-automatic-password-saving to check whether or
627 # not the prompt is shown in the way we expected. 572 # not the prompt is shown in the way we expected.
628 tests_results = RunTests(args.chrome_path[0], 573 tests_results = RunTest(args.chrome_path,
629 args.chromedriver_path[0], 574 args.chromedriver_path,
630 args.profile_path[0], 575 args.profile_path,
631 passwords_path, 576 args.passwords_path,
632 False, 577 False,
633 numeric_level, 578 args.test)
634 args.log_screen,
635 log_file,
636 tested_websites,
637 args.tests)
638 579
639 # Run the test with enable-automatic-password-saving to check whether or not 580 # Run the test with enable-automatic-password-saving to check whether or not
640 # the passwords is stored in the the way we expected. 581 # the passwords is stored in the the way we expected.
641 tests_results += RunTests(args.chrome_path[0], 582 tests_results += RunTest(args.chrome_path,
642 args.chromedriver_path[0], 583 args.chromedriver_path,
643 args.profile_path[0], 584 args.profile_path,
644 passwords_path, 585 args.passwords_path,
645 True, 586 True,
646 numeric_level, 587 args.test)
647 args.log_screen,
648 log_file,
649 tested_websites,
650 args.tests)
651 588
652 saveResults(tests_results, save_path) 589 saveResults(tests_results, save_path)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698