service.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # Licensed to the Software Freedom Conservancy (SFC) under one
  2. # or more contributor license agreements. See the NOTICE file
  3. # distributed with this work for additional information
  4. # regarding copyright ownership. The SFC licenses this file
  5. # to you under the Apache License, Version 2.0 (the
  6. # "License"); you may not use this file except in compliance
  7. # with the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing,
  12. # software distributed under the License is distributed on an
  13. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. # KIND, either express or implied. See the License for the
  15. # specific language governing permissions and limitations
  16. # under the License.
  17. from selenium.webdriver.common import service
  18. class Service(service.Service):
  19. """
  20. Object that manages the starting and stopping of the ChromeDriver
  21. """
  22. def __init__(self, executable_path, port=0, service_args=None,
  23. log_path=None, env=None):
  24. """
  25. Creates a new instance of the Service
  26. :Args:
  27. - executable_path : Path to the ChromeDriver
  28. - port : Port the service is running on
  29. - service_args : List of args to pass to the chromedriver service
  30. - log_path : Path for the chromedriver service to log to"""
  31. self.service_args = service_args or []
  32. if log_path:
  33. self.service_args.append('--log-path=%s' % log_path)
  34. service.Service.__init__(self, executable_path, port=port, env=env,
  35. start_error_message="Please see https://sites.google.com/a/chromium.org/chromedriver/home")
  36. def command_line_args(self):
  37. return ["--port=%d" % self.port] + self.service_args