webdriver.py 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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.chrome.webdriver import WebDriver as ChromiumDriver
  18. from .options import Options
  19. class OperaDriver(ChromiumDriver):
  20. """Controls the new OperaDriver and allows you
  21. to drive the Opera browser based on Chromium."""
  22. def __init__(self, executable_path=None, port=0,
  23. opera_options=None, service_args=None,
  24. desired_capabilities=None, service_log_path=None):
  25. """
  26. Creates a new instance of the operadriver.
  27. Starts the service and then creates new instance of operadriver.
  28. :Args:
  29. - executable_path - path to the executable. If the default is used
  30. it assumes the executable is in the $PATH
  31. - port - port you would like the service to run, if left as 0,
  32. a free port will be found.
  33. - desired_capabilities: Dictionary object with non-browser specific
  34. capabilities only, such as "proxy" or "loggingPref".
  35. - chrome_options: this takes an instance of ChromeOptions
  36. """
  37. executable_path = (executable_path if executable_path is not None
  38. else "operadriver")
  39. ChromiumDriver.__init__(self,
  40. executable_path=executable_path,
  41. port=port,
  42. chrome_options=opera_options,
  43. service_args=service_args,
  44. desired_capabilities=desired_capabilities,
  45. service_log_path=service_log_path)
  46. def create_options(self):
  47. return Options()
  48. class WebDriver(OperaDriver):
  49. class ServiceType:
  50. CHROMIUM = 2
  51. def __init__(self,
  52. desired_capabilities=None,
  53. executable_path=None,
  54. port=0,
  55. service_log_path=None,
  56. service_args=None,
  57. opera_options=None):
  58. OperaDriver.__init__(self, executable_path=executable_path,
  59. port=port, opera_options=opera_options,
  60. service_args=service_args,
  61. desired_capabilities=desired_capabilities,
  62. service_log_path=service_log_path)