14
14
# KIND, either express or implied. See the License for the
15
15
# specific language governing permissions and limitations
16
16
# under the License.
17
- from selenium .common .exceptions import WebDriverException
18
17
19
18
try :
20
19
import http .client as http_client
21
20
except ImportError :
22
21
import httplib as http_client
23
22
23
+ import warnings
24
+
25
+ from selenium .common .exceptions import WebDriverException
24
26
from selenium .webdriver .common .desired_capabilities import DesiredCapabilities
25
27
from selenium .webdriver .remote .webdriver import WebDriver as RemoteWebDriver
28
+ from .options import Options
26
29
from .service import Service
27
30
from .remote_connection import SafariRemoteConnection
28
31
32
+ DEFAULT_EXECUTABLE_PATH = "/usr/bin/safaridriver"
33
+ DEFAULT_SAFARI_CAPS = DesiredCapabilities .SAFARI .copy ()
34
+
29
35
30
36
class WebDriver (RemoteWebDriver ):
31
37
"""
32
38
Controls the SafariDriver and allows you to drive the browser.
33
39
34
40
"""
35
41
36
- def __init__ (self , port = 0 , executable_path = "/usr/bin/safaridriver" , reuse_service = False ,
37
- desired_capabilities = DesiredCapabilities . SAFARI , quiet = False ,
38
- keep_alive = True , service_args = None ):
42
+ def __init__ (self , port = 0 , executable_path = DEFAULT_EXECUTABLE_PATH , reuse_service = False ,
43
+ desired_capabilities = DEFAULT_SAFARI_CAPS , quiet = False ,
44
+ keep_alive = True , service_args = None , options : Options = None , service : Service = None ):
39
45
"""
40
46
41
47
Creates a new Safari driver instance and launches or finds a running safaridriver service.
@@ -47,12 +53,38 @@ def __init__(self, port=0, executable_path="/usr/bin/safaridriver", reuse_servic
47
53
- desired_capabilities: Dictionary object with desired capabilities (Can be used to provide various Safari switches).
48
54
- quiet - If True, the driver's stdout and stderr is suppressed.
49
55
- keep_alive - Whether to configure SafariRemoteConnection to use
50
- HTTP keep-alive. Defaults to False .
56
+ HTTP keep-alive. Defaults to True .
51
57
- service_args : List of args to pass to the safaridriver service
52
58
"""
59
+ if port == 0 :
60
+ warnings .warn ("port has been deprecated, please set it via the service class" ,
61
+ DeprecationWarning , stacklevel = 2 )
62
+
63
+ if executable_path != DEFAULT_EXECUTABLE_PATH :
64
+ warnings .warn ("executable_path has been deprecated, please use the Options class to set it" ,
65
+ DeprecationWarning , stacklevel = 2 )
66
+ if not reuse_service :
67
+ warnings .warn ("reuse_service has been deprecated, please use the Service class to set it" ,
68
+ DeprecationWarning , stacklevel = 2 )
69
+ if desired_capabilities != DEFAULT_SAFARI_CAPS :
70
+ warnings .warn ("desired_capabilities has been deprecated, please use the Options class to set it" ,
71
+ DeprecationWarning , stacklevel = 2 )
72
+ if not quiet :
73
+ warnings .warn ("quiet has been deprecated, please use the Service class to set it" ,
74
+ DeprecationWarning , stacklevel = 2 )
75
+ if not keep_alive :
76
+ warnings .warn ("keep_alive has been deprecated, please use the Service class to set it" ,
77
+ DeprecationWarning , stacklevel = 2 )
78
+
79
+ if service_args :
80
+ warnings .warn ("service_args has been deprecated, please use the Service class to set it" ,
81
+ DeprecationWarning , stacklevel = 2 )
53
82
54
83
self ._reuse_service = reuse_service
55
- self .service = Service (executable_path , port = port , quiet = quiet , service_args = service_args )
84
+ if service :
85
+ self .service = service
86
+ else :
87
+ self .service = Service (executable_path , port = port , quiet = quiet , service_args = service_args )
56
88
if not reuse_service :
57
89
self .service .start ()
58
90
0 commit comments