-
Notifications
You must be signed in to change notification settings - Fork 0
/
py_test.py
executable file
·62 lines (54 loc) · 2.2 KB
/
py_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python
# Copyright 2008-2009 WebDriver committers
# Copyright 2008-2009 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""A script for running the unit test and example tests for the python
binding."""
import optparse
import os
import shutil
import subprocess
import sys
def run_script(script_name, *args):
command = [sys.executable, script_name.replace("/", os.path.sep)]
command.extend(args)
return subprocess.Popen(command)
if __name__ == "__main__":
usage = 'usage: %prog [options] arg'
parser = optparse.OptionParser(usage)
parser.add_option('-d', '--driver', dest='driver', action='store',
default='firefox', type='choice',
choices=['chrome', 'firefox', 'remote'],
help='Which driver to test.')
(options, args) = parser.parse_args()
driver_tests_dict = {
'chrome': ['api_examples'],
'firefox': ['api_examples', 'cookie_tests', 'firefox_launcher_tests'],
'remote': ['api_examples'],
}
base_dir = os.path.abspath(os.path.dirname(__file__))
print 'base_dir:',base_dir
os.environ["WEBDRIVER"] = base_dir
os.environ["PYTHONPATH"] = os.pathsep.join([os.environ.get("PYTHONPATH", ""),
os.path.join(base_dir, "../../../", "firefox", "lib-src"),
os.path.join(base_dir, '..')])
try:
for test in driver_tests_dict[options.driver]:
process = run_script(os.path.join(base_dir, "%s_tests/%s.py" % (options.driver, test)))
assert process.wait() == 0, "Test %s failed" % test
finally:
try:
os.kill(process.pid, 9)
except:
pass