Skip to content

Commit b6f5eaf

Browse files
Add setting/getting proxy details to Firefox Options
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.
1 parent 61800fb commit b6f5eaf

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

py/selenium/webdriver/firefox/options.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17-
17+
from selenium.common.exceptions import InvalidArgumentException
18+
from selenium.webdriver.common.proxy import Proxy
1819
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
1920
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
2021

@@ -36,6 +37,7 @@ def __init__(self):
3637
self._binary = None
3738
self._preferences = {}
3839
self._profile = None
40+
self._proxy = None
3941
self._arguments = []
4042
self.log = Log()
4143

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

76+
@property
77+
def proxy(self):
78+
""" returns Proxy if set otherwise None."""
79+
return self._proxy
80+
81+
@proxy.setter
82+
def proxy(self, value):
83+
if not isinstance(value, Proxy):
84+
raise InvalidArgumentException("Only Proxy objects can be passed in.")
85+
self._proxy = value
86+
7487
@property
7588
def profile(self):
7689
"""Returns the Firefox profile to use."""
@@ -112,6 +125,8 @@ def to_capabilities(self):
112125
opts["binary"] = self._binary._start_cmd
113126
if len(self._preferences) > 0:
114127
opts["prefs"] = self._preferences
128+
if self._proxy is not None:
129+
self._proxy.add_to_capabilities(opts)
115130
if self._profile is not None:
116131
opts["profile"] = self._profile.encoded
117132
if len(self._arguments) > 0:

py/selenium/webdriver/remote/webdriver.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ def __init__(self, command_executor='http://127.0.0.1:4444/wd/hub',
8181
if not isinstance(desired_capabilities, dict):
8282
raise WebDriverException("Desired Capabilities must be a dictionary")
8383
if proxy is not None:
84+
warnings.warn("Please use FirefoxOptions to set proxy",
85+
DeprecationWarning)
8486
proxy.add_to_capabilities(desired_capabilities)
8587
self.command_executor = command_executor
8688
if type(self.command_executor) is bytes or isinstance(self.command_executor, str):

0 commit comments

Comments
 (0)