options.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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.options import Options as ChromeOptions
  18. from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
  19. class Options(ChromeOptions):
  20. def __init__(self):
  21. ChromeOptions.__init__(self)
  22. self._android_package_name = ''
  23. self._android_device_socket = ''
  24. self._android_command_line_file = ''
  25. @property
  26. def android_package_name(self):
  27. """
  28. Returns the name of the Opera package
  29. """
  30. return self._android_package_name
  31. @android_package_name.setter
  32. def android_package_name(self, value):
  33. """
  34. Allows you to set the package name
  35. :Args:
  36. - value: devtools socket name
  37. """
  38. self._android_package_name = value
  39. @property
  40. def android_device_socket(self):
  41. """
  42. Returns the name of the devtools socket
  43. """
  44. return self._android_device_socket
  45. @android_device_socket.setter
  46. def android_device_socket(self, value):
  47. """
  48. Allows you to set the devtools socket name
  49. :Args:
  50. - value: devtools socket name
  51. """
  52. self._android_device_socket = value
  53. @property
  54. def android_command_line_file(self):
  55. """
  56. Returns the path of the command line file
  57. """
  58. return self._android_command_line_file
  59. @android_command_line_file.setter
  60. def android_command_line_file(self, value):
  61. """
  62. Allows you to set where the command line file lives
  63. :Args:
  64. - value: command line file path
  65. """
  66. self._android_command_line_file = value
  67. def to_capabilities(self):
  68. """
  69. Creates a capabilities with all the options that have been set and
  70. returns a dictionary with everything
  71. """
  72. capabilities = ChromeOptions.to_capabilities(self)
  73. capabilities.update(DesiredCapabilities.OPERA)
  74. opera_options = capabilities["operaOptions"] = \
  75. capabilities.pop("chromeOptions")
  76. if self.android_package_name:
  77. opera_options["androidPackage"] = self.android_package_name
  78. if self.android_device_socket:
  79. opera_options["androidDeviceSocket"] = self.android_device_socket
  80. if self.android_command_line_file:
  81. opera_options["androidCommandLineFile"] = \
  82. self.android_command_line_file
  83. return capabilities
  84. class AndroidOptions(Options):
  85. def __init__(self):
  86. Options.__init__(self)
  87. self.android_package_name = 'com.opera.browser'