Chromium Code Reviews| 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 """This file allows the bots to be easily configure and run the tests.""" | 6 """This file allows the bots to be easily configure and run the tests.""" |
| 7 | 7 |
| 8 import argparse | 8 import argparse |
| 9 import os | |
| 10 import tempfile | |
| 11 | 9 |
| 12 from environment import Environment | 10 from environment import Environment |
| 13 import tests | 11 import tests |
| 14 | 12 |
| 13 def printResults(results): | |
| 14 """Print the test results. | |
| 15 | |
| 16 Args: | |
| 17 results: A list of the TestResults that are going to be printed. | |
| 18 """ | |
| 19 for result in results: | |
| 20 if result.successful: | |
| 21 print ( | |
| 22 "The test %s for %s was successful." | |
| 23 % (result.test_type, result.name)) | |
| 24 else: | |
| 25 print ( | |
| 26 "The test %s for %s has failed:\n%s" | |
| 27 % (result.test_type, result.name, result.message)) | |
| 28 | |
| 15 if __name__ == "__main__": | 29 if __name__ == "__main__": |
| 16 parser = argparse.ArgumentParser( | 30 parser = argparse.ArgumentParser( |
| 17 description="Password Manager automated tests runner help.") | 31 description="Password Manager automated tests runner help.") |
| 18 parser.add_argument( | 32 parser.add_argument( |
| 19 "--chrome-path", action="store", dest="chrome_path", | 33 "--chrome-path", action="store", dest="chrome_path", |
| 20 help="Set the chrome path (required).", nargs=1, required=True) | 34 help="Set the chrome path (required).", nargs=1, required=True) |
| 21 parser.add_argument( | 35 parser.add_argument( |
| 22 "--chromedriver-path", action="store", dest="chromedriver_path", | 36 "--chromedriver-path", action="store", dest="chromedriver_path", |
| 23 help="Set the chromedriver path (required).", nargs=1, required=True) | 37 help="Set the chromedriver path (required).", nargs=1, required=True) |
| 24 parser.add_argument( | 38 parser.add_argument( |
| 25 "--profile-path", action="store", dest="profile_path", | 39 "--profile-path", action="store", dest="profile_path", |
| 26 help="Set the profile path (required). You just need to choose a " | 40 help="Set the profile path (required). You just need to choose a " |
| 27 "temporary empty folder. If the folder is not empty all its content " | 41 "temporary empty folder. If the folder is not empty all its content " |
| 28 "is going to be removed.", | 42 "is going to be removed.", |
| 29 nargs=1, required=True) | 43 nargs=1, required=True) |
| 30 parser.add_argument( | 44 parser.add_argument( |
| 31 "--passwords-path", action="store", dest="passwords_path", | 45 "--passwords-path", action="store", dest="passwords_path", |
| 32 help="Set the usernames/passwords path (required).", nargs=1, | 46 help="Set the usernames/passwords path (required).", nargs=1, |
| 33 required=True) | 47 required=True) |
| 34 parser.add_argument("--save-path", action="store", nargs=1, dest="save_path", | 48 parser.add_argument("--save-path", action="store", nargs=1, dest="save_path", |
| 35 help="Write the results in a file.", required=True) | 49 help="Write the results in a file.", required=True) |
| 36 args = parser.parse_args() | 50 args = parser.parse_args() |
| 37 | 51 |
| 38 environment = Environment('', '', '', None, False) | 52 environment = Environment('', '', '', None, False) |
| 39 tests.Tests(environment) | 53 tests.Tests(environment) |
| 40 | 54 |
| 41 xml = open(args.save_path[0],"w") | 55 xml = "<xml>" |
| 42 xml.write("<xml>") | |
| 43 try: | |
| 44 results = tempfile.NamedTemporaryFile( | |
| 45 dir=os.path.join(tempfile.gettempdir()), delete=False) | |
| 46 results_path = results.name | |
| 47 results.close() | |
| 48 | 56 |
| 49 full_path = os.path.realpath(__file__) | 57 all_successful = True |
| 50 tests_dir = os.path.dirname(full_path) | 58 for websitetest in environment.websitetests: |
| 51 tests_path = os.path.join(tests_dir, "tests.py") | 59 successful = False |
| 60 # The tests can be flaky. This is why we try to rerun up to 3 times. | |
| 61 for x in range(0, 3): | |
| 62 # This message needs to be printed out to let the trybot know that the | |
|
vabr (Chromium)
2014/07/22 15:41:45
typo: know -> knows
rchtara
2014/07/22 16:18:47
http://www.oxfordlearnersdictionaries.com/definiti
vabr (Chromium)
2014/07/22 16:32:04
You are right, I missed the "let"! :)
Never mind,
| |
| 63 # tests are still working, so they should not be killed. | |
| 64 print "Running tests for %s " % websitetest.name | |
| 65 tests_results = [] | |
| 66 # Exceptions thrown by this test need to be ignored so that the other | |
| 67 # tests can run without any problem. | |
| 68 try: | |
| 69 # Run the test without enable-automatic-password-saving to check whether | |
| 70 # or not the prompt is shown in the way we expected. | |
| 71 tests_results += tests.RunTests( | |
| 72 args.chrome_path[0], | |
| 73 args.chromedriver_path[0], | |
| 74 args.profile_path[0], | |
| 75 args.passwords_path[0], | |
| 76 False, | |
| 77 10, # Debug log level. | |
| 78 True, | |
| 79 None, | |
| 80 tests.TypeOfTestedWebsites.LIST_OF_TESTS, | |
| 81 [websitetest.name]) | |
| 82 except Exception: | |
|
vabr (Chromium)
2014/07/22 15:41:45
Could you print the textual description of the exc
rchtara
2014/07/22 16:18:47
Done.
| |
| 83 pass | |
| 52 | 84 |
| 53 for websitetest in environment.websitetests: | 85 # Exceptions thrown by this test need to be ignored so that the other |
| 54 # The tests can be flaky. This is why we try to rerun up to 3 times. | 86 # tests can run without any problem. |
| 55 for x in range(0, 3): | 87 try: |
| 56 # TODO(rchtara): Using "pkill" is just temporary until a better, | 88 # Run the test with enable-automatic-password-saving to check whether |
| 57 # platform-independent solution is found. | 89 # or not the password is stored in the the way we expected. |
| 58 os.system("pkill chrome") | 90 tests_results += tests.RunTests( |
| 59 try: | 91 args.chrome_path[0], |
| 60 os.remove(results_path) | 92 args.chromedriver_path[0], |
| 61 except Exception: | 93 args.profile_path[0], |
| 62 pass | 94 args.passwords_path[0], |
| 63 # TODO(rchtara): Using "timeout is just temporary until a better, | 95 True, |
| 64 # platform-independent solution is found. | 96 10, # Debug log level. |
| 97 True, | |
| 98 None, | |
| 99 tests.TypeOfTestedWebsites.LIST_OF_TESTS, | |
| 100 [websitetest.name]) | |
| 101 except Exception: | |
| 102 pass | |
| 65 | 103 |
| 66 # The website test runs in two passes, each pass has an internal | 104 if (len(tests_results) > 1 and tests_results[0].successful and |
| 67 # timeout of 200s for waiting (see |remaining_time_to_wait| and | 105 tests_results[1].successful): |
| 68 # Wait() in websitetest.py). Accounting for some more time spent on | 106 successful = True |
| 69 # the non-waiting execution, 300 seconds should be the upper bound on | 107 xml += tests.resultsToXml(tests_results) |
|
vabr (Chromium)
2014/07/22 15:41:45
You currently duplicate here the code from lines 1
rchtara
2014/07/22 16:18:47
Done.
| |
| 70 # the runtime of one pass, thus 600 seconds for the whole test. | 108 printResults(tests_results) |
| 71 os.system("timeout 600 python %s %s --chrome-path %s " | 109 break |
| 72 "--chromedriver-path %s --passwords-path %s --profile-path %s " | |
| 73 "--save-path %s" % | |
| 74 (tests_path, websitetest.name, args.chrome_path[0], | |
| 75 args.chromedriver_path[0], args.passwords_path[0], | |
| 76 args.profile_path[0], results_path)) | |
| 77 if os.path.isfile(results_path): | |
| 78 results = open(results_path, "r") | |
| 79 count = 0 # Count the number of successful tests. | |
| 80 for line in results: | |
| 81 xml.write(line) | |
| 82 count += line.count("successful='True'") | |
| 83 results.close() | |
| 84 # There is only two tests running for every website: the prompt and | |
| 85 # the normal test. If both of the tests were successful, the tests | |
| 86 # would be stopped for the current website. | |
| 87 if count == 2: | |
| 88 break | |
| 89 else: | |
| 90 xml.write("<result><test name='%s' type='prompt' successful='false'>" | |
| 91 "</test><test name='%s' type='normal' successful='false'></test>" | |
| 92 "</result>" % (websitetest.name, websitetest.name)) | |
| 93 finally: | |
| 94 try: | |
| 95 os.remove(results_path) | |
| 96 except Exception: | |
| 97 pass | |
| 98 | 110 |
| 99 xml.write("</xml>") | 111 elif len(tests_results) == 1: |
| 100 xml.close() | 112 failed_test = "prompt" |
| 113 if tests_results[0].type == "prompt": | |
| 114 failed_test = "normal" | |
| 115 tests_results.append( | |
| 116 environment.TestResult(websitetest.name, failed_test, False, | |
| 117 "An expected error has occurred.")) | |
|
vabr (Chromium)
2014/07/22 15:41:45
expected -> unexpected?
(also below)
rchtara
2014/07/22 16:18:47
Done.
| |
| 118 | |
| 119 elif len(tests_results) == 0:: | |
|
vabr (Chromium)
2014/07/22 15:41:45
typo: :: -> :
rchtara
2014/07/22 16:18:47
Done.
| |
| 120 tests_results.append( | |
| 121 environment.TestResult(websitetest.name, "prompt", False, | |
| 122 "An expected error has occurred.")) | |
| 123 tests_results.append( | |
| 124 environment.TestResult(websitetest.name, "normal", False, | |
| 125 "An expected error has occurred.")) | |
| 126 | |
| 127 xml += tests.resultsToXml(tests_results) | |
| 128 printResults(tests_results) | |
| 129 | |
| 130 all_successful = all_successful and successful | |
| 131 | |
| 132 xml += "</xml>" | |
| 133 | |
| 134 # |xml| should be sent to the dashboard, once it is ready. | |
| 135 | |
| 136 json = open(args.save_path[0], "w") | |
| 137 json.write("{'successful': '%s'}" % all_successful) | |
| 138 json.close() | |
| OLD | NEW |