|
| 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 | + |
| 18 | +from selenium.webdriver.common.desired_capabilities import DesiredCapabilities |
| 19 | + |
| 20 | + |
| 21 | +class Options(object): |
| 22 | + |
| 23 | + def __init__(self): |
| 24 | + self._browser_executable_path = '' |
| 25 | + self._browser_arguments = [] |
| 26 | + self._overlay_scrollbars_enabled = True |
| 27 | + |
| 28 | + @property |
| 29 | + def browser_executable_path(self): |
| 30 | + """ |
| 31 | + Returns the location of the browser binary otherwise an empty string |
| 32 | + """ |
| 33 | + return self._browser_executable_path |
| 34 | + |
| 35 | + @browser_executable_path.setter |
| 36 | + def browser_executable_path(self, value): |
| 37 | + """ |
| 38 | + Allows you to set the browser binary to launch |
| 39 | +
|
| 40 | + :Args: |
| 41 | + - value : path to the browser binary |
| 42 | + """ |
| 43 | + self._browser_executable_path = value |
| 44 | + |
| 45 | + @property |
| 46 | + def browser_arguments(self): |
| 47 | + """ |
| 48 | + Returns a list of arguments needed for the browser |
| 49 | + """ |
| 50 | + return self._browser_arguments |
| 51 | + |
| 52 | + def add_browser_argument(self, argument): |
| 53 | + """ |
| 54 | + Adds an argument to the list |
| 55 | +
|
| 56 | + :Args: |
| 57 | + - Sets the arguments |
| 58 | + """ |
| 59 | + if argument: |
| 60 | + self._browser_arguments.append(argument) |
| 61 | + else: |
| 62 | + raise ValueError("argument can not be null") |
| 63 | + |
| 64 | + @property |
| 65 | + def overlay_scrollbars_enabled(self): |
| 66 | + """ |
| 67 | + Returns whether overlay scrollbars should be enabled |
| 68 | + """ |
| 69 | + return self._overlay_scrollbars_enabled |
| 70 | + |
| 71 | + @overlay_scrollbars_enabled.setter |
| 72 | + def overlay_scrollbars_enabled(self, value): |
| 73 | + """ |
| 74 | + Allows you to enable or disable overlay scrollbars |
| 75 | +
|
| 76 | + :Args: |
| 77 | + - value : True or False |
| 78 | + """ |
| 79 | + self._overlay_scrollbars_enabled = value |
| 80 | + |
| 81 | + def to_capabilities(self): |
| 82 | + """ |
| 83 | + Creates a capabilities with all the options that have been set and |
| 84 | + returns a dictionary with everything |
| 85 | + """ |
| 86 | + webkitgtk = DesiredCapabilities.WEBKITGTK.copy() |
| 87 | + |
| 88 | + browser_options = {} |
| 89 | + if self.browser_executable_path: |
| 90 | + browser_options["binary"] = self.browser_executable_path |
| 91 | + browser_options["args"] = self.browser_arguments |
| 92 | + browser_options["useOverlayScrollbars"] = self.overlay_scrollbars_enabled |
| 93 | + |
| 94 | + webkitgtk["webkitgtk:browserOptions"] = browser_options |
| 95 | + |
| 96 | + return webkitgtk |
0 commit comments