Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/py/test/selenium/webdriver/safari/launcher_tests.py
1865 views
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
from selenium.common.exceptions import NoSuchDriverException
23
from selenium.webdriver.safari.service import Service
24
25
26
def test_launch(driver):
27
assert driver.capabilities["browserName"] == "Safari"
28
29
30
def test_launch_with_invalid_executable_path_raises_exception(driver_class):
31
path = "/this/path/should/never/exist"
32
assert not os.path.exists(path)
33
service = Service(executable_path=path)
34
with pytest.raises(NoSuchDriverException):
35
driver_class(service=service)
36
37
38
@pytest.mark.skipif(
39
not os.path.exists("/Applications/Safari Technology Preview.app/Contents/MacOS/safaridriver"),
40
reason="Preview not installed",
41
)
42
class TestTechnologyPreview:
43
@pytest.fixture
44
def driver_kwargs(self):
45
path = "/Applications/Safari Technology Preview.app/Contents/MacOS/safaridriver"
46
assert os.path.exists(path), (
47
"Safari Technology Preview required! Download it from https://developer.apple.com/safari/technology-preview/"
48
)
49
return {"executable_path": path}
50
51
def test_launch(self, driver):
52
assert driver.capabilities["browserName"] == "safari"
53
54
55
@pytest.mark.skip(reason="Need to be updated")
56
def test_launch_safari_with_legacy_flag(mocker, driver_class):
57
import subprocess
58
59
mocker.patch("subprocess.Popen")
60
try:
61
driver_class(service_args=["--legacy"])
62
except Exception:
63
pass
64
args, kwargs = subprocess.Popen.call_args
65
assert "--legacy" in args[0]
66
67
68
def test_launch_safari_without_legacy_flag(mocker, driver_class):
69
import subprocess
70
71
mocker.patch("subprocess.Popen")
72
try:
73
driver_class()
74
except Exception:
75
pass
76
args, kwargs = subprocess.Popen.call_args
77
assert "--legacy" not in args[0]
78
79