Skip to content

Commit

Permalink
Add setting/getting proxy details to Firefox Options
Browse files Browse the repository at this point in the history
This deprecates proxy and browser profile from instantiating
a new webdriver object and moves proxy to options so we only set it
in one place now.
  • Loading branch information
AutomatedTester committed Apr 3, 2017
1 parent 61800fb commit b6f5eaf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 16 additions & 1 deletion py/selenium/webdriver/firefox/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

from selenium.common.exceptions import InvalidArgumentException
from selenium.webdriver.common.proxy import Proxy
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile

Expand All @@ -36,6 +37,7 @@ def __init__(self):
self._binary = None
self._preferences = {}
self._profile = None
self._proxy = None
self._arguments = []
self.log = Log()

Expand Down Expand Up @@ -71,6 +73,17 @@ def set_preference(self, name, value):
"""Sets a preference."""
self._preferences[name] = value

@property
def proxy(self):
""" returns Proxy if set otherwise None."""
return self._proxy

@proxy.setter
def proxy(self, value):
if not isinstance(value, Proxy):
raise InvalidArgumentException("Only Proxy objects can be passed in.")
self._proxy = value

@property
def profile(self):
"""Returns the Firefox profile to use."""
Expand Down Expand Up @@ -112,6 +125,8 @@ def to_capabilities(self):
opts["binary"] = self._binary._start_cmd
if len(self._preferences) > 0:
opts["prefs"] = self._preferences
if self._proxy is not None:
self._proxy.add_to_capabilities(opts)
if self._profile is not None:
opts["profile"] = self._profile.encoded
if len(self._arguments) > 0:
Expand Down
2 changes: 2 additions & 0 deletions py/selenium/webdriver/remote/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ def __init__(self, command_executor='http://127.0.0.1:4444/wd/hub',
if not isinstance(desired_capabilities, dict):
raise WebDriverException("Desired Capabilities must be a dictionary")
if proxy is not None:
warnings.warn("Please use FirefoxOptions to set proxy",
DeprecationWarning)
proxy.add_to_capabilities(desired_capabilities)
self.command_executor = command_executor
if type(self.command_executor) is bytes or isinstance(self.command_executor, str):
Expand Down

0 comments on commit b6f5eaf

Please sign in to comment.