| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
import pytest |
| 19 |
|
| 20 |
from selenium.webdriver.common.by import By |
| 21 |
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities |
| 22 |
from selenium.webdriver.common.options import PageLoadStrategy |
| 23 |
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary |
| 24 |
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile |
| 25 |
from selenium.webdriver.firefox.options import Log |
| 26 |
from selenium.webdriver.firefox.options import Options |
| 27 |
|
| 28 |
|
| 29 |
@pytest.fixture |
| 30 |
def driver_kwargs(driver_kwargs): |
| 31 |
driver_kwargs["options"] = Options() |
| 32 |
return driver_kwargs |
| 33 |
|
| 34 |
|
| 35 |
class TestIntegration: |
| 36 |
def test_we_can_pass_options(self, driver, pages): |
| 37 |
pages.load("formPage.html") |
| 38 |
driver.find_element(By.ID, "cheese") |
| 39 |
|
| 40 |
|
| 41 |
class TestUnit: |
| 42 |
def test_ctor(self): |
| 43 |
opts = Options() |
| 44 |
assert opts._binary is None |
| 45 |
assert not opts._preferences |
| 46 |
assert opts._profile is None |
| 47 |
assert not opts._arguments |
| 48 |
assert isinstance(opts.log, Log) |
| 49 |
|
| 50 |
def test_binary(self): |
| 51 |
opts = Options() |
| 52 |
assert opts.binary is None |
| 53 |
|
| 54 |
other_binary = FirefoxBinary() |
| 55 |
assert other_binary != opts.binary |
| 56 |
opts.binary = other_binary |
| 57 |
assert other_binary == opts.binary |
| 58 |
|
| 59 |
path = "/path/to/binary" |
| 60 |
opts.binary = path |
| 61 |
assert isinstance(opts.binary, FirefoxBinary) |
| 62 |
assert opts.binary._start_cmd == path |
| 63 |
|
| 64 |
def test_prefs(self): |
| 65 |
opts = Options() |
| 66 |
assert len(opts.preferences) == 0 |
| 67 |
assert isinstance(opts.preferences, dict) |
| 68 |
|
| 69 |
opts.set_preference("spam", "ham") |
| 70 |
assert len(opts.preferences) == 1 |
| 71 |
opts.set_preference("eggs", True) |
| 72 |
assert len(opts.preferences) == 2 |
| 73 |
opts.set_preference("spam", "spam") |
| 74 |
assert len(opts.preferences) == 2 |
| 75 |
assert opts.preferences == {"spam": "spam", "eggs": True} |
| 76 |
|
| 77 |
def test_profile(self, tmpdir_factory): |
| 78 |
opts = Options() |
| 79 |
assert opts.profile is None |
| 80 |
|
| 81 |
other_profile = FirefoxProfile() |
| 82 |
assert other_profile != opts.profile |
| 83 |
opts.profile = other_profile |
| 84 |
assert other_profile == opts.profile |
| 85 |
|
| 86 |
opts.profile = str(tmpdir_factory.mktemp("profile")) |
| 87 |
assert isinstance(opts.profile, FirefoxProfile) |
| 88 |
|
| 89 |
def test_arguments(self): |
| 90 |
opts = Options() |
| 91 |
assert len(opts.arguments) == 0 |
| 92 |
|
| 93 |
opts.add_argument("--foo") |
| 94 |
assert len(opts.arguments) == 1 |
| 95 |
opts.arguments.append("--bar") |
| 96 |
assert len(opts.arguments) == 2 |
| 97 |
assert opts.arguments == ["--foo", "--bar"] |
| 98 |
|
| 99 |
def test_to_capabilities(self): |
| 100 |
opts = Options() |
| 101 |
firefox_caps = DesiredCapabilities.FIREFOX.copy() |
| 102 |
firefox_caps.update({"pageLoadStrategy": PageLoadStrategy.normal}) |
| 103 |
assert opts.to_capabilities() == firefox_caps |
| 104 |
|
| 105 |
profile = FirefoxProfile() |
| 106 |
opts.profile = profile |
| 107 |
caps = opts.to_capabilities() |
| 108 |
assert "moz:firefoxOptions" in caps |
| 109 |
assert "profile" in caps["moz:firefoxOptions"] |
| 110 |
assert isinstance(caps["moz:firefoxOptions"]["profile"], str) |
| 111 |
assert caps["moz:firefoxOptions"]["profile"] == profile.encoded |
| 112 |
|
| 113 |
opts.add_argument("--foo") |
| 114 |
caps = opts.to_capabilities() |
| 115 |
assert "moz:firefoxOptions" in caps |
| 116 |
assert "args" in caps["moz:firefoxOptions"] |
| 117 |
assert caps["moz:firefoxOptions"]["args"] == ["--foo"] |
| 118 |
|
| 119 |
binary = FirefoxBinary() |
| 120 |
opts.binary = binary |
| 121 |
caps = opts.to_capabilities() |
| 122 |
assert "moz:firefoxOptions" in caps |
| 123 |
assert "binary" in caps["moz:firefoxOptions"] |
| 124 |
assert isinstance(caps["moz:firefoxOptions"]["binary"], str) |
| 125 |
assert caps["moz:firefoxOptions"]["binary"] == binary._start_cmd |
| 126 |
|
| 127 |
opts.set_preference("spam", "ham") |
| 128 |
caps = opts.to_capabilities() |
| 129 |
assert "moz:firefoxOptions" in caps |
| 130 |
assert "prefs" in caps["moz:firefoxOptions"] |
| 131 |
assert isinstance(caps["moz:firefoxOptions"]["prefs"], dict) |
| 132 |
assert caps["moz:firefoxOptions"]["prefs"]["spam"] == "ham" |