Skip to content

Commit 69c55bb

Browse files
committed
Add support for Safari Technology Preview to python bindings
1 parent e4c8798 commit 69c55bb

File tree

4 files changed

+87
-6
lines changed

4 files changed

+87
-6
lines changed

py/selenium/webdriver/safari/service.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,15 @@ class Service(service.Service):
2525
Object that manages the starting and stopping of the SafariDriver
2626
"""
2727

28-
def __init__(self, port=0, quiet=False):
28+
def __init__(self, executable_path, port=0, quiet=False):
2929
"""
3030
Creates a new instance of the Service
3131
3232
:Args:
3333
- executable_path : Path to the SafariDriver
3434
- port : Port the service is running on """
3535

36-
path = '/usr/bin/safaridriver'
37-
if not os.path.exists(path):
36+
if not os.path.exists(executable_path):
3837
raise Exception("SafariDriver requires Safari 10 on OSX El Capitan or greater")
3938

4039
if port == 0:
@@ -44,7 +43,7 @@ def __init__(self, port=0, quiet=False):
4443
log = PIPE
4544
if quiet:
4645
log = open(os.devnull, 'w')
47-
service.Service.__init__(self, path, port, log)
46+
service.Service.__init__(self, executable_path, port, log)
4847

4948
def command_line_args(self):
5049
return ["-p", "%s" % self.port]

py/selenium/webdriver/safari/webdriver.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ class WebDriver(RemoteWebDriver):
3232
3333
"""
3434

35-
def __init__(self, port=0, desired_capabilities=DesiredCapabilities.SAFARI, quiet=False):
35+
def __init__(self, port=0, executable_path="/usr/bin/safaridriver",
36+
desired_capabilities=DesiredCapabilities.SAFARI, quiet=False):
3637
"""
3738
Creates a new instance of the Safari driver.
3839
@@ -43,7 +44,7 @@ def __init__(self, port=0, desired_capabilities=DesiredCapabilities.SAFARI, quie
4344
- desired_capabilities: Dictionary object with desired capabilities (Can be used to provide various Safari switches).
4445
- quiet - set to True to suppress stdout and stderr of the driver
4546
"""
46-
self.service = Service(port=port, quiet=quiet)
47+
self.service = Service(executable_path, port=port, quiet=quiet)
4748
self.service.start()
4849

4950
RemoteWebDriver.__init__(
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Licensed to the Software Freedom Conservancy (SFC) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The SFC licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
import pytest
19+
20+
from selenium.webdriver import Safari
21+
22+
23+
@pytest.fixture
24+
def driver_class():
25+
return Safari
26+
27+
28+
@pytest.fixture
29+
def driver_kwargs():
30+
return {}
31+
32+
33+
@pytest.fixture
34+
def driver(driver_class, driver_kwargs):
35+
driver = driver_class(**driver_kwargs)
36+
yield driver
37+
driver.quit()
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Licensed to the Software Freedom Conservancy (SFC) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The SFC licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
import os
19+
20+
import pytest
21+
22+
23+
def test_launch(driver):
24+
assert driver.capabilities['browserName'] == 'safari'
25+
26+
27+
def test_launch_with_invalid_executable_path_raises_exception(driver_class):
28+
path = '/this/path/should/never/exist'
29+
assert not os.path.exists(path)
30+
with pytest.raises(Exception) as e:
31+
driver_class(executable_path=path)
32+
assert 'SafariDriver requires Safari 10 on OSX El Capitan' in str(e)
33+
34+
35+
class TestTechnologyPreview(object):
36+
37+
@pytest.fixture
38+
def driver_kwargs(self):
39+
path = '/Applications/Safari Technology Preview.app/Contents/MacOS/safaridriver'
40+
assert os.path.exists(path), 'Safari Technology Preview required! Download it from https://developer.apple.com/safari/technology-preview/'
41+
return {'executable_path': path}
42+
43+
def test_launch(self, driver):
44+
assert driver.capabilities['browserName'] == 'safari'

0 commit comments

Comments
 (0)