webdriver.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 utils
  18. from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
  19. from selenium.webdriver.remote.remote_connection import RemoteConnection
  20. from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
  21. from .service import Service
  22. class WebDriver(RemoteWebDriver):
  23. def __init__(self, executable_path='MicrosoftWebDriver.exe',
  24. capabilities=None, port=0, verbose=False, log_path=None):
  25. self.port = port
  26. if self.port == 0:
  27. self.port = utils.free_port()
  28. self.edge_service = Service(executable_path, port=self.port, verbose=verbose, log_path=log_path)
  29. self.edge_service.start()
  30. if capabilities is None:
  31. capabilities = DesiredCapabilities.EDGE
  32. RemoteWebDriver.__init__(
  33. self,
  34. command_executor=RemoteConnection('http://localhost:%d' % self.port,
  35. resolve_ip=False),
  36. desired_capabilities=capabilities)
  37. self._is_remote = False
  38. def quit(self):
  39. RemoteWebDriver.quit(self)
  40. self.edge_service.stop()