diff options
author | rchtara@chromium.org <rchtara@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-01 15:09:50 +0000 |
---|---|---|
committer | rchtara@chromium.org <rchtara@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-01 15:09:50 +0000 |
commit | 1220a843c563a4487e0d6e1510a250a671a324e4 (patch) | |
tree | e81ed4b8ad6ed5bc1bb8f205b8ea78f5636a5fed | |
parent | 2fea6bc662d8403963373b02855454512a9ab027 (diff) | |
download | chromium_src-1220a843c563a4487e0d6e1510a250a671a324e4.zip chromium_src-1220a843c563a4487e0d6e1510a250a671a324e4.tar.gz chromium_src-1220a843c563a4487e0d6e1510a250a671a324e4.tar.bz2 |
The results of the password manager Python tests need to be exportable
as xml.
This CL allows saving the results of the password manager Python tests as an xml file so they can be easily used by the dashboard and adds a new argument (--save-path) for the tests.py to set the location where the file is going to be saved.
BUG=369521
Review URL: https://codereview.chromium.org/346223005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@280824 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | components/test/data/password_manager/README | 2 | ||||
-rw-r--r-- | components/test/data/password_manager/environment.py | 52 | ||||
-rw-r--r-- | components/test/data/password_manager/tests.py | 75 | ||||
-rw-r--r-- | components/test/data/password_manager/websitetest.py | 2 |
4 files changed, 100 insertions, 31 deletions
diff --git a/components/test/data/password_manager/README b/components/test/data/password_manager/README index 3bc561c..91e7f98 100644 --- a/components/test/data/password_manager/README +++ b/components/test/data/password_manager/README @@ -57,6 +57,8 @@ python tests.py --log DEBUG|INFO|WARNING|ERROR|CRITICAL --log-screen To save debugging messages into a file, use: python tests.py --log DEBUG|INFO|WARNING|ERROR|CRITICAL --log-file LOG_FILE +To save the result of the tests as an xml file, use: +python tests.py --save-path SAVERESULTPATH =====Creating new test===== diff --git a/components/test/data/password_manager/environment.py b/components/test/data/password_manager/environment.py index b3ff7cd..487f533 100644 --- a/components/test/data/password_manager/environment.py +++ b/components/test/data/password_manager/environment.py @@ -22,6 +22,23 @@ MESSAGE_ASK = "Message: Decision: ASK the user" MESSAGE_SAVE = "Message: Decision: SAVE the password" +class TestResult: + """Stores the information related to a test result. """ + def __init__(self, name, test_type, successful, message): + """Creates a new TestResult. + + Args: + name: The tested website name. + test_type: The test type. + successful: Whether or not the test was successful. + message: The error message of the test. + """ + self.name = name + self.test_type = test_type + self.successful = successful + self.message = message + + class Environment: """Sets up the testing Environment. """ @@ -76,6 +93,7 @@ class Environment: # we don't need to initilize the webdriver. if chrome_path: options = Options() + self.enable_automatic_password_saving = enable_automatic_password_saving if enable_automatic_password_saving: options.add_argument("enable-automatic-password-saving") # Chrome path. @@ -110,6 +128,8 @@ class Environment: # GoTo. This is why we store here whether or not it's the first time to # execute GoTo. self.first_go_to = True + # List of all tests results. + self.tests_results = [] def AddWebsiteTest(self, websitetest, disabled=False): """Adds a WebsiteTest to the testing Environment. @@ -312,13 +332,20 @@ class Environment: self.RemoveAllPasswords() for websitetest in websitetests: - websitetest.WrongLoginTest() - websitetest.SuccessfulLoginTest() - websitetest.SuccessfulLoginWithAutofilledPasswordTest() - - self.RemoveAllPasswords() - for websitetest in websitetests: - websitetest.SuccessfulLoginTest() + successful = True + error = "" + try: + websitetest.was_run = True + websitetest.WrongLoginTest() + websitetest.SuccessfulLoginTest() + websitetest.SuccessfulLoginWithAutofilledPasswordTest() + self.RemoveAllPasswords() + websitetest.SuccessfulLoginTest() + except Exception: + successful = False + error = traceback.format_exc() + self.tests_results.append(TestResult(websitetest.name, "normal", + successful, escape(error))) def PromptTestList(self, websitetests): """Runs the prompt tests on the websites in |websitetests|. @@ -332,7 +359,16 @@ class Environment: self.RemoveAllPasswords() for websitetest in websitetests: - websitetest.PromptTest() + successful = True + error = "" + try: + websitetest.was_run = True + websitetest.PromptTest() + except Exception: + successful = False + error = traceback.format_exc() + self.tests_results.append(TestResult(websitetest.name, "prompt", + successful, escape(error))) def Quit(self): """Closes the tests.""" diff --git a/components/test/data/password_manager/tests.py b/components/test/data/password_manager/tests.py index af9f44e..1e2f225 100644 --- a/components/test/data/password_manager/tests.py +++ b/components/test/data/password_manager/tests.py @@ -1,8 +1,8 @@ +# -*- coding: utf-8 -*- # Copyright 2014 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -# -*- coding: utf-8 -*- """Automated tests for many websites""" import argparse @@ -392,6 +392,26 @@ def Tests(environment): environment.AddWebsiteTest(Yahoo("yahoo", username_not_auto=True), disabled=True) +def saveResults(environment_tests_results, environment_save_path): + """Save the test results in an xml file. + + Args: + environment_tests_results: A list of the TestResults that are going to be + saved. + environment_save_path: The file where the results are going to be saved. + If it's None, the results are not going to be stored. + Raises: + Exception: An exception is raised if the file is not found. + """ + if environment_save_path: + xml = "<result>" + for test_result in environment_tests_results: + xml += ("<test name='%s' successful='%s' type='%s'>%s</test>" + % (test_result.name, str(test_result.successful), + test_result.test_type, test_result.message)) + xml += "</result>" + with open(environment_save_path, "w") as save_file: + save_file.write(xml) def RunTests(chrome_path, chromedriver_path, profile_path, environment_passwords_path, enable_automatic_password_saving, @@ -414,8 +434,10 @@ def RunTests(chrome_path, chromedriver_path, profile_path, all_tests: If True, all the tests are going to be ran. tests: A list of the names of the WebsiteTests that are going to be tested. + Returns: + The results of tests as list of TestResults. Raises: - Exception: An exception is raised if the one of the tests fails. + Exception: An exception is raised if one of the tests fails. """ environment = Environment(chrome_path, chromedriver_path, profile_path, @@ -439,7 +461,7 @@ def RunTests(chrome_path, chromedriver_path, profile_path, environment.WorkingTests(run_prompt_tests) environment.Quit() - + return environment.tests_results # Tests setup. if __name__ == "__main__": @@ -472,6 +494,8 @@ if __name__ == "__main__": help="Show log on the screen.") parser.add_argument("--log-file", action="store", dest="log_file", help="Write the log in a file.", nargs=1) + parser.add_argument("--save-path", action="store", nargs=1, dest="save_path", + help="Write the results in a file.") parser.add_argument("tests", help="Tests to be run.", nargs="*") args = parser.parse_args() @@ -488,28 +512,33 @@ if __name__ == "__main__": if args.log_file: log_file = args.log_file[0] + save_path = None + if args.save_path: + save_path = args.save_path[0] + # Run the test without enable-automatic-password-saving to check whether or # not the prompt is shown in the way we expected. - RunTests(args.chrome_path[0], - args.chromedriver_path[0], - args.profile_path[0], - passwords_path, - False, - numeric_level, - args.log_screen, - log_file, - args.all, - args.tests) + tests_results = RunTests(args.chrome_path[0], + args.chromedriver_path[0], + args.profile_path[0], + passwords_path, + False, + numeric_level, + args.log_screen, + log_file, + args.all, + args.tests) # Run the test with enable-automatic-password-saving to check whether or not # the passwords is stored in the the way we expected. - RunTests(args.chrome_path[0], - args.chromedriver_path[0], - args.profile_path[0], - passwords_path, - True, - numeric_level, - args.log_screen, - log_file, - args.all, - args.tests) + tests_results += RunTests(args.chrome_path[0], + args.chromedriver_path[0], + args.profile_path[0], + passwords_path, + True, + numeric_level, + args.log_screen, + log_file, + args.all, + args.tests) + saveResults(tests_results, save_path) diff --git a/components/test/data/password_manager/websitetest.py b/components/test/data/password_manager/websitetest.py index a0df593..d88ac32 100644 --- a/components/test/data/password_manager/websitetest.py +++ b/components/test/data/password_manager/websitetest.py @@ -68,6 +68,8 @@ class WebsiteTest: self.environment = None # The webdriver. self.driver = None + # Whether or not the test was ran. + self.was_run = False # Mouse/Keyboard actions. |