2022-04-12 11:21:55 +00:00
|
|
|
#!/usr/bin/env python3
|
2020-02-03 18:31:14 +00:00
|
|
|
|
|
|
|
import argparse
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
|
|
|
|
SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
args = parse_args()
|
|
|
|
|
|
|
|
chromedriver_name = {
|
|
|
|
'darwin': 'chromedriver',
|
|
|
|
'win32': 'chromedriver.exe',
|
2023-05-15 09:06:12 +00:00
|
|
|
'linux': 'chromedriver',
|
2020-02-03 18:31:14 +00:00
|
|
|
'linux2': 'chromedriver'
|
|
|
|
}
|
|
|
|
|
|
|
|
chromedriver_path = os.path.join(
|
|
|
|
args.source_root, args.build_dir, chromedriver_name[sys.platform])
|
|
|
|
proc = subprocess.Popen([chromedriver_path],
|
|
|
|
stdout=subprocess.PIPE, universal_newlines=True)
|
|
|
|
try:
|
|
|
|
output = proc.stdout.readline()
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
returncode = 0
|
|
|
|
finally:
|
|
|
|
proc.terminate()
|
|
|
|
|
|
|
|
returncode = 0
|
|
|
|
match = re.search(
|
2020-10-19 11:55:27 +00:00
|
|
|
'^Starting ChromeDriver [0-9]+.[0-9]+.[0-9]+.[0-9]+ .* on port [0-9]+$',
|
|
|
|
output
|
|
|
|
)
|
2020-02-03 18:31:14 +00:00
|
|
|
|
2020-09-14 02:43:16 +00:00
|
|
|
if match is None:
|
2020-02-03 18:31:14 +00:00
|
|
|
returncode = 1
|
|
|
|
|
|
|
|
if returncode == 0:
|
|
|
|
print('ok ChromeDriver is able to be initialized.')
|
|
|
|
|
|
|
|
return returncode
|
|
|
|
|
|
|
|
|
|
|
|
def parse_args():
|
|
|
|
parser=argparse.ArgumentParser(description='Test ChromeDriver')
|
|
|
|
parser.add_argument('--source-root',
|
|
|
|
default=SOURCE_ROOT,
|
|
|
|
required=False)
|
|
|
|
parser.add_argument('--build-dir',
|
|
|
|
default=None,
|
|
|
|
required=True)
|
|
|
|
return parser.parse_args()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
sys.exit(main())
|