webdriver.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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.common.desired_capabilities import DesiredCapabilities
  20. from .service import Service
  21. DEFAULT_TIMEOUT = 30
  22. DEFAULT_PORT = 0
  23. DEFAULT_HOST = None
  24. DEFAULT_LOG_LEVEL = None
  25. DEFAULT_LOG_FILE = None
  26. class WebDriver(RemoteWebDriver):
  27. def __init__(self, executable_path='IEDriverServer.exe', capabilities=None,
  28. port=DEFAULT_PORT, timeout=DEFAULT_TIMEOUT, host=DEFAULT_HOST,
  29. log_level=DEFAULT_LOG_LEVEL, log_file=DEFAULT_LOG_FILE):
  30. self.port = port
  31. if self.port == 0:
  32. self.port = utils.free_port()
  33. self.host = host
  34. self.log_level = log_level
  35. self.log_file = log_file
  36. self.iedriver = Service(
  37. executable_path,
  38. port=self.port,
  39. host=self.host,
  40. log_level=self.log_level,
  41. log_file=self.log_file)
  42. self.iedriver.start()
  43. if capabilities is None:
  44. capabilities = DesiredCapabilities.INTERNETEXPLORER
  45. RemoteWebDriver.__init__(
  46. self,
  47. command_executor='http://localhost:%d' % self.port,
  48. desired_capabilities=capabilities)
  49. self._is_remote = False
  50. def quit(self):
  51. RemoteWebDriver.quit(self)
  52. self.iedriver.stop()