verify-chromedriver.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/usr/bin/env python3
  2. from __future__ import print_function
  3. import argparse
  4. import os
  5. import re
  6. import subprocess
  7. import sys
  8. SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
  9. def main():
  10. args = parse_args()
  11. chromedriver_name = {
  12. 'darwin': 'chromedriver',
  13. 'win32': 'chromedriver.exe',
  14. 'linux': 'chromedriver',
  15. 'linux2': 'chromedriver'
  16. }
  17. chromedriver_path = os.path.join(
  18. args.source_root, args.build_dir, chromedriver_name[sys.platform])
  19. proc = subprocess.Popen([chromedriver_path],
  20. stdout=subprocess.PIPE, universal_newlines=True)
  21. try:
  22. output = proc.stdout.readline()
  23. except KeyboardInterrupt:
  24. returncode = 0
  25. finally:
  26. proc.terminate()
  27. returncode = 0
  28. match = re.search(
  29. '^Starting ChromeDriver [0-9]+.[0-9]+.[0-9]+.[0-9]+ .* on port [0-9]+$',
  30. output
  31. )
  32. if match is None:
  33. returncode = 1
  34. if returncode == 0:
  35. print('ok ChromeDriver is able to be initialized.')
  36. return returncode
  37. def parse_args():
  38. parser=argparse.ArgumentParser(description='Test ChromeDriver')
  39. parser.add_argument('--source-root',
  40. default=SOURCE_ROOT,
  41. required=False)
  42. parser.add_argument('--build-dir',
  43. default=None,
  44. required=True)
  45. return parser.parse_args()
  46. if __name__ == '__main__':
  47. sys.exit(main())