Skip to content

Commit 0f1c753

Browse files
authored
[py] deprecate FirefoxBinary class (#13476)
pass in location of firefox with binary_location property in Options class store binary location not binary in Firefox options
1 parent 19df7bb commit 0f1c753

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

py/selenium/webdriver/firefox/firefox_binary.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,13 @@
2323
from subprocess import STDOUT
2424
from subprocess import Popen
2525

26+
from typing_extensions import deprecated
27+
2628
from selenium.common.exceptions import WebDriverException
2729
from selenium.webdriver.common import utils
2830

2931

32+
@deprecated("Use binary_location property in Firefox Options to set location")
3033
class FirefoxBinary:
3134
NO_FOCUS_LIBRARY_NAME = "x_ignore_nofocus.so"
3235

py/selenium/webdriver/firefox/options.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17-
import typing
1817
from typing import Union
1918

19+
from typing_extensions import deprecated
20+
2021
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
2122
from selenium.webdriver.common.options import ArgOptions
2223
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
@@ -38,35 +39,37 @@ class Options(ArgOptions):
3839

3940
def __init__(self) -> None:
4041
super().__init__()
41-
self._binary: typing.Optional[FirefoxBinary] = None
42+
self._binary_location = ""
4243
self._preferences: dict = {}
4344
self._profile = None
4445
self.log = Log()
4546

4647
@property
48+
@deprecated("use binary_location instead")
4749
def binary(self) -> FirefoxBinary:
4850
"""Returns the FirefoxBinary instance."""
49-
return self._binary
51+
return FirefoxBinary(self._binary_location)
5052

5153
@binary.setter
54+
@deprecated("use binary_location instead")
5255
def binary(self, new_binary: Union[str, FirefoxBinary]) -> None:
5356
"""Sets location of the browser binary, either by string or
5457
``FirefoxBinary`` instance."""
55-
if not isinstance(new_binary, FirefoxBinary):
56-
new_binary = FirefoxBinary(new_binary)
57-
self._binary = new_binary
58+
if isinstance(new_binary, FirefoxBinary):
59+
new_binary = new_binary._start_cmd
60+
self.binary_location = new_binary
5861

5962
@property
6063
def binary_location(self) -> str:
6164
""":Returns: The location of the binary."""
62-
return self.binary._start_cmd
65+
return self._binary_location
6366

6467
@binary_location.setter # noqa
6568
def binary_location(self, value: str) -> None:
6669
"""Sets the location of the browser binary by string."""
6770
if not isinstance(value, str):
6871
raise TypeError(self.BINARY_LOCATION_ERROR)
69-
self.binary = value
72+
self._binary_location = value
7073

7174
@property
7275
def preferences(self) -> dict:
@@ -102,8 +105,8 @@ def to_capabilities(self) -> dict:
102105
caps = self._caps
103106
opts = {}
104107

105-
if self._binary:
106-
opts["binary"] = self._binary._start_cmd
108+
if self._binary_location:
109+
opts["binary"] = self._binary_location
107110
if self._preferences:
108111
opts["prefs"] = self._preferences
109112
if self._profile:

py/test/unit/selenium/webdriver/firefox/firefox_options_tests.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ def options():
3434
def test_set_binary_with_firefox_binary(options):
3535
binary = FirefoxBinary("foo")
3636
options.binary = binary
37-
assert options._binary == binary
37+
assert options.binary_location == "foo"
3838

3939

4040
def test_set_binary_with_path(options):
4141
options.binary = "/foo"
42-
assert options._binary._start_cmd == "/foo"
42+
assert options.binary_location == "/foo"
4343

4444

4545
def test_get_binary(options):
@@ -49,11 +49,11 @@ def test_get_binary(options):
4949

5050
def test_set_binary_location(options):
5151
options.binary_location = "/foo"
52-
assert options._binary._start_cmd == "/foo"
52+
assert options.binary_location == "/foo"
5353

5454

5555
def test_get_binary_location(options):
56-
options._binary = FirefoxBinary("/foo")
56+
options._binary_location = "/foo"
5757
assert options.binary_location == "/foo"
5858

5959

@@ -131,7 +131,7 @@ def test_set_log_level(options):
131131
def test_creates_capabilities(options):
132132
profile = FirefoxProfile()
133133
options._arguments = ["foo"]
134-
options._binary = FirefoxBinary("/bar")
134+
options._binary_location = "/bar"
135135
options._preferences = {"foo": "bar"}
136136
options.proxy = Proxy({"proxyType": ProxyType.MANUAL})
137137
options._profile = profile

0 commit comments

Comments
 (0)