| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 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( |
| 47 |
path |
| 48 |
), "Safari Technology Preview required! Download it from https://developer.apple.com/safari/technology-preview/" |
| 49 |
return {"executable_path": path} |
| 50 |
|
| 51 |
def test_launch(self, driver): |
| 52 |
assert driver.capabilities["browserName"] == "safari" |
| 53 |
|
| 54 |
|
| 55 |
def test_launch_safari_with_legacy_flag(mocker, driver_class): |
| 56 |
import subprocess |
| 57 |
|
| 58 |
mocker.patch("subprocess.Popen") |
| 59 |
try: |
| 60 |
driver_class(service_args=["--legacy"]) |
| 61 |
except Exception: |
| 62 |
pass |
| 63 |
args, kwargs = subprocess.Popen.call_args |
| 64 |
assert "--legacy" in args[0] |
| 65 |
|
| 66 |
|
| 67 |
def test_launch_safari_without_legacy_flag(mocker, driver_class): |
| 68 |
import subprocess |
| 69 |
|
| 70 |
mocker.patch("subprocess.Popen") |
| 71 |
try: |
| 72 |
driver_class() |
| 73 |
except Exception: |
| 74 |
pass |
| 75 |
args, kwargs = subprocess.Popen.call_args |
| 76 |
assert "--legacy" not in args[0] |