Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # -*- coding: utf-8 -*- | |
| 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 | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 """This file allows the bots to be easily configure and run the tests.""" | |
| 7 | |
| 8 import argparse | |
| 9 import os | |
| 10 import tempfile | |
| 11 | |
| 12 from environment import Environment | |
| 13 import tests | |
| 14 | |
| 15 if __name__ == "__main__": | |
| 16 parser = argparse.ArgumentParser( | |
| 17 description="Password Manager automated tests runner help.") | |
| 18 parser.add_argument( | |
| 19 "--chrome-path", action="store", dest="chrome_path", | |
| 20 help="Set the chrome path (required).", nargs=1, required=True) | |
| 21 parser.add_argument( | |
| 22 "--chromedriver-path", action="store", dest="chromedriver_path", | |
| 23 help="Set the chromedriver path (required).", nargs=1, required=True) | |
| 24 parser.add_argument( | |
| 25 "--profile-path", action="store", dest="profile_path", | |
| 26 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 " | |
| 28 "is going to be removed.", | |
| 29 nargs=1, required=True) | |
| 30 parser.add_argument( | |
| 31 "--passwords-path", action="store", dest="passwords_path", | |
| 32 help="Set the usernames/passwords path (required).", nargs=1, | |
| 33 required=True) | |
| 34 parser.add_argument("--save-path", action="store", nargs=1, dest="save_path", | |
| 35 help="Write the results in a file.", required=True) | |
| 36 args = parser.parse_args() | |
| 37 | |
| 38 environment = Environment('', '', '', None, False) | |
| 39 tests.Tests(environment) | |
| 40 | |
| 41 xml = open(args.save_path[0],"w") | |
| 42 xml.write("<xml>") | |
| 43 try: | |
| 44 results = tempfile.NamedTemporaryFile( | |
| 45 dir=os.path.join(tempfile.gettempdir()), | |
| 46 delete=False) | |
|
vabr (Chromium)
2014/07/16 08:48:44
nit: That's not what I meant -- the arguments do f
rchtara
2014/07/16 16:31:58
Done.
| |
| 47 results_path = results.name | |
| 48 results.close() | |
| 49 | |
| 50 full_path = os.path.realpath(__file__) | |
| 51 tests_dir = os.path.dirname(full_path) | |
| 52 tests_path = os.path.join(tests_dir, "tests.py") | |
| 53 | |
| 54 for websitetest in environment.websitetests: | |
| 55 # The tests are not robust and could some time fail for reasons that are | |
| 56 # not related to the password manager(ex: unexpected chrome crash). This | |
|
vabr (Chromium)
2014/07/16 08:48:44
I don't think we should tolerate unexpected chrome
vabr (Chromium)
2014/07/16 08:48:44
nits:
(1) space before "("
(2) ex: -> e.g.,
rchtara
2014/07/16 16:31:58
Done.
| |
| 57 # is why we need to run them many times to reduce the effect of such | |
|
vabr (Chromium)
2014/07/16 08:48:44
I can see 2 issues with the current approach:
(1)
rchtara
2014/07/16 16:31:59
Done.
| |
| 58 # problems. | |
| 59 for x in range(0, 3): | |
| 60 os.system("pkill -f chrome") | |
| 61 try: | |
| 62 os.remove(results_path) | |
| 63 except OSError: | |
| 64 pass | |
| 65 # The test could sometimes be blocked waiting for a page to be loaded | |
| 66 # or an HTML element to appear. This why we need to run them with a | |
| 67 # timeout to stop the test in this case. The timeout is 200 seconds and | |
| 68 # it's more than enough to run the test. | |
|
vabr (Chromium)
2014/07/16 08:48:44
"it's more than enough" -- that's a bold claim. If
rchtara
2014/07/16 16:31:59
Done.
| |
| 69 os.system("timeout 200 python %s %s --chrome-path %s " | |
| 70 "--chromedriver-path %s --passwords-path %s --profile-path %s " | |
| 71 "--save-path %s" % | |
| 72 (tests_path, websitetest.name, args.chrome_path[0], | |
| 73 args.chromedriver_path[0], args.passwords_path[0], | |
| 74 args.profile_path[0], results_path)) | |
| 75 if os.path.isfile(results_path): | |
| 76 results = open(results_path, "r") | |
| 77 for line in results: | |
| 78 xml.write(line) | |
| 79 results.close() | |
| 80 else: | |
| 81 xml.write("<result><test name='%s' type='prompt' successful='false'>" | |
| 82 "</test><test name='%s' type='normal' successful='false'></test>" | |
| 83 "</result>" % (websitetest.name, websitetest.name)) | |
| 84 except Exception: | |
|
vabr (Chromium)
2014/07/16 08:48:44
Are you sure you want to flush all exceptions here
rchtara
2014/07/16 16:31:59
Done.
| |
| 85 pass | |
| 86 try: | |
| 87 os.remove(results_path) | |
| 88 except Exception: | |
| 89 pass | |
| 90 | |
| 91 xml.write("</xml>") | |
| 92 xml.close() | |
| OLD | NEW |