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.
6 """This file allows the bots to be easily configure and run the tests."""
12 from environment import Environment
15 if __name__ == "__main__":
16 parser = argparse.ArgumentParser(
17 description="Password Manager automated tests runner help.")
19 "--chrome-path", action="store", dest="chrome_path",
20 help="Set the chrome path (required).", nargs=1, required=True)
22 "--chromedriver-path", action="store", dest="chromedriver_path",
23 help="Set the chromedriver path (required).", nargs=1, required=True)
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)
31 "--passwords-path", action="store", dest="passwords_path",
32 help="Set the usernames/passwords path (required).", nargs=1,
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()
38 environment = Environment('', '', '', None, False)
39 tests.Tests(environment)
41 xml = open(args.save_path[0],"w")
44 results = tempfile.NamedTemporaryFile(
45 dir=os.path.join(tempfile.gettempdir()), delete=False)
46 results_path = results.name
49 full_path = os.path.realpath(__file__)
50 tests_dir = os.path.dirname(full_path)
51 tests_path = os.path.join(tests_dir, "tests.py")
53 for websitetest in environment.websitetests:
54 # The tests can be flaky. This is why we try to rerun up to 3 times.
56 # TODO(rchtara): Using "pkill" is just temporary until a better,
57 # platform-independent solution is found.
58 os.system("pkill chrome")
60 os.remove(results_path)
63 # TODO(rchtara): Using "timeout is just temporary until a better,
64 # platform-independent solution is found.
66 # The website test runs in two passes, each pass has an internal
67 # timeout of 200s for waiting (see |remaining_time_to_wait| and
68 # Wait() in websitetest.py). Accounting for some more time spent on
69 # the non-waiting execution, 300 seconds should be the upper bound on
70 # the runtime of one pass, thus 600 seconds for the whole test.
71 os.system("timeout 600 python %s %s --chrome-path %s "
72 "--chromedriver-path %s --passwords-path %s --profile-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.
82 count += line.count("successful='True'")
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.
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))
95 os.remove(results_path)