11# This Source Code Form is subject to the terms of the Mozilla Public
22# License, v. 2.0. If a copy of the MPL was not distributed with this
33# file, You can obtain one at http://mozilla.org/MPL/2.0/.
4- from packaging .version import Version
5- import warnings
64import logging
75
86import pytest
9- from selenium import __version__ as SELENIUM_VERSION
10- from selenium .webdriver import FirefoxProfile
11- from selenium .webdriver .firefox .firefox_binary import FirefoxBinary
7+
128from selenium .webdriver .firefox .options import Options
139
1410LOGGER = logging .getLogger (__name__ )
1511
1612
17- def pytest_addoption (parser ):
18- group = parser .getgroup ("selenium" , "selenium" )
19- group ._addoption (
20- "--firefox-path" , metavar = "path" , help = "path to the firefox binary."
21- )
22- group ._addoption (
23- "--firefox-preference" ,
24- action = "append" ,
25- default = [],
26- dest = "firefox_preferences" ,
27- metavar = ("name" , "value" ),
28- nargs = 2 ,
29- help = "additional firefox preferences." ,
30- )
31- group ._addoption (
32- "--firefox-profile" , metavar = "path" , help = "path to the firefox profile."
33- )
34- group ._addoption (
35- "--firefox-extension" ,
36- action = "append" ,
37- default = [],
38- dest = "firefox_extensions" ,
39- metavar = "path" ,
40- help = "path to a firefox extension." ,
41- )
42-
43-
4413def pytest_configure (config ):
4514 config .addinivalue_line (
4615 "markers" ,
@@ -58,36 +27,22 @@ def pytest_configure(config):
5827
5928
6029def driver_kwargs (capabilities , driver_log , driver_path , firefox_options , ** kwargs ):
61-
62- # Selenium 3.14.0 deprecated log_path in favour of service_log_path
63- if Version (SELENIUM_VERSION ) < Version ("3.14.0" ):
64- kwargs = {"log_path" : driver_log }
65- else :
66- kwargs = {"service_log_path" : driver_log }
30+ kwargs = {"service_log_path" : driver_log }
6731
6832 if capabilities :
6933 kwargs ["capabilities" ] = capabilities
7034 if driver_path is not None :
7135 kwargs ["executable_path" ] = driver_path
7236
73- # Selenium 3.8.0 deprecated firefox_options in favour of options
74- if Version (SELENIUM_VERSION ) < Version ("3.8.0" ):
75- kwargs ["firefox_options" ] = firefox_options
76- else :
77- kwargs ["options" ] = firefox_options
37+ kwargs ["options" ] = firefox_options
38+
7839 return kwargs
7940
8041
8142@pytest .fixture
82- def firefox_options (request , firefox_path , firefox_profile ):
43+ def firefox_options (request ):
8344 options = Options ()
8445
85- if firefox_profile is not None :
86- options .profile = firefox_profile
87-
88- if firefox_path is not None :
89- options .binary = FirefoxBinary (firefox_path )
90-
9146 for arg in get_arguments_from_markers (request .node ):
9247 options .add_argument (arg )
9348
@@ -109,64 +64,3 @@ def get_preferences_from_markers(node):
10964 for mark in node .iter_markers ("firefox_preferences" ):
11065 preferences .update (mark .args [0 ])
11166 return preferences
112-
113-
114- @pytest .fixture (scope = "session" )
115- def firefox_path (pytestconfig ):
116- if pytestconfig .getoption ("firefox_path" ):
117- warnings .warn (
118- "--firefox-path has been deprecated and will be removed in a "
119- "future release. Please make sure the Firefox binary is in the "
120- "default location, or the system path. If you want to specify a "
121- "binary path then use the firefox_options fixture to and set this "
122- "using firefox_options.binary." ,
123- DeprecationWarning ,
124- )
125- return pytestconfig .getoption ("firefox_path" )
126-
127-
128- @pytest .fixture
129- def firefox_profile (pytestconfig ):
130- profile = None
131- if pytestconfig .getoption ("firefox_profile" ):
132- profile = FirefoxProfile (pytestconfig .getoption ("firefox_profile" ))
133- warnings .warn (
134- "--firefox-profile has been deprecated and will be removed in "
135- "a future release. Please use the firefox_options fixture to "
136- "set a profile path or FirefoxProfile object using "
137- "firefox_options.profile." ,
138- DeprecationWarning ,
139- )
140- if pytestconfig .getoption ("firefox_preferences" ):
141- profile = profile or FirefoxProfile ()
142- warnings .warn (
143- "--firefox-preference has been deprecated and will be removed in "
144- "a future release. Please use the firefox_options fixture to set "
145- "preferences using firefox_options.set_preference. If you are "
146- "using Firefox 47 or earlier then you will need to create a "
147- "FirefoxProfile object with preferences and set this using "
148- "firefox_options.profile." ,
149- DeprecationWarning ,
150- )
151- for preference in pytestconfig .getoption ("firefox_preferences" ):
152- name , value = preference
153- if value .isdigit ():
154- # handle integer preferences
155- value = int (value )
156- elif value .lower () in ["true" , "false" ]:
157- # handle boolean preferences
158- value = value .lower () == "true"
159- profile .set_preference (name , value )
160- profile .update_preferences ()
161- if pytestconfig .getoption ("firefox_extensions" ):
162- profile = profile or FirefoxProfile ()
163- warnings .warn (
164- "--firefox-extensions has been deprecated and will be removed in "
165- "a future release. Please use the firefox_options fixture to "
166- "create a FirefoxProfile object with extensions and set this "
167- "using firefox_options.profile." ,
168- DeprecationWarning ,
169- )
170- for extension in pytestconfig .getoption ("firefox_extensions" ):
171- profile .add_extension (extension )
172- return profile
0 commit comments