service.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. def __init__(self, executable_path, port=0, verbose=False, log_path=None):
  20. """
  21. Creates a new instance of the EdgeDriver service.
  22. EdgeDriver provides an interface for Microsoft WebDriver to use
  23. with Microsoft Edge.
  24. :param executable_path: Path to the Microsoft WebDriver binary.
  25. :param port: Run the remote service on a specified port.
  26. Defaults to 0, which binds to a random open port of the
  27. system's choosing.
  28. :verbose: Whether to make the webdriver more verbose (passes the
  29. --verbose option to the binary). Defaults to False.
  30. :param log_path: Optional path for the webdriver binary to log to.
  31. Defaults to None which disables logging.
  32. """
  33. self.service_args = []
  34. if verbose:
  35. self.service_args.append("--verbose")
  36. params = {
  37. "executable": executable_path,
  38. "port": port,
  39. "start_error_message": "Please download from http://go.microsoft.com/fwlink/?LinkId=619687"
  40. }
  41. if log_path:
  42. params["log_file"] = open(log_path, "a+")
  43. service.Service.__init__(self, **params)
  44. def command_line_args(self):
  45. return ["--port=%d" % self.port] + self.service_args