-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[py] add unit tests for Firefox Options
- Loading branch information
Showing
3 changed files
with
165 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
152 changes: 152 additions & 0 deletions
152
py/test/unit/selenium/webdriver/firefox/firefox_options_tests.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
# Licensed to the Software Freedom Conservancy (SFC) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The SFC licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
import pytest | ||
|
||
from selenium.common.exceptions import InvalidArgumentException | ||
from selenium.webdriver.common.proxy import Proxy, ProxyType | ||
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary | ||
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile | ||
from selenium.webdriver.firefox.options import Options | ||
|
||
|
||
@pytest.fixture | ||
def options(): | ||
yield Options() | ||
|
||
|
||
def test_set_binary_with_firefox_binary(options): | ||
binary = FirefoxBinary('foo') | ||
options.binary = binary | ||
assert options._binary == binary | ||
|
||
|
||
def test_set_binary_with_path(options): | ||
options.binary = '/foo' | ||
assert options._binary._start_cmd == '/foo' | ||
|
||
|
||
def test_get_binary(options): | ||
options.binary = '/foo' | ||
assert options.binary._start_cmd == '/foo' | ||
|
||
|
||
def test_set_binary_location(options): | ||
options.binary_location = '/foo' | ||
assert options._binary._start_cmd == '/foo' | ||
|
||
|
||
def test_get_binary_location(options): | ||
options._binary = FirefoxBinary('/foo') | ||
assert options.binary_location == '/foo' | ||
|
||
|
||
def test_set_preference(options): | ||
options.set_preference('foo', 'bar') | ||
assert options._preferences['foo'] == 'bar' | ||
|
||
|
||
def test_get_preferences(options): | ||
options._preferences = {'foo': 'bar'} | ||
assert options.preferences['foo'] == 'bar' | ||
|
||
|
||
def test_set_proxy(options): | ||
proxy = Proxy({'proxyType': ProxyType.MANUAL}) | ||
options.proxy = proxy | ||
assert options._proxy == proxy | ||
|
||
|
||
def test_raises_exception_if_proxy_is_not_proxy_object(options): | ||
with pytest.raises(InvalidArgumentException): | ||
options.proxy = 'foo' | ||
|
||
|
||
def test_get_proxy(options): | ||
options._proxy = 'foo' | ||
assert options.proxy == 'foo' | ||
|
||
|
||
def test_set_profile_with_firefox_profile(options): | ||
profile = FirefoxProfile() | ||
options.profile = profile | ||
assert options._profile == profile | ||
|
||
|
||
def test_set_profile_with_path(options): | ||
options.profile = None | ||
assert isinstance(options._profile, FirefoxProfile) | ||
|
||
|
||
def test_get_profile(options): | ||
options._profile = 'foo' | ||
assert options.profile == 'foo' | ||
|
||
|
||
def test_add_arguments(options): | ||
options.add_argument('foo') | ||
assert 'foo' in options._arguments | ||
|
||
|
||
def test_get_arguments(options): | ||
options._arguments = ['foo'] | ||
assert 'foo' in options.arguments | ||
|
||
|
||
def test_raises_exception_if_argument_is_falsy(options): | ||
with pytest.raises(ValueError): | ||
options.add_argument(None) | ||
|
||
|
||
def test_set_log_level(options): | ||
options.log.level = 'debug' | ||
assert options.log.level == 'debug' | ||
|
||
|
||
def test_set_headless(options): | ||
options.set_headless() | ||
assert '-headless' in options._arguments | ||
|
||
|
||
def test_unset_headless(options): | ||
options._arguments = ['-headless'] | ||
options.set_headless(False) | ||
assert '-headless' not in options._arguments | ||
|
||
|
||
def test_get_headless(options): | ||
options._arguments = ['-headless'] | ||
assert options.headless | ||
|
||
|
||
def test_creates_capabilities(options): | ||
profile = FirefoxProfile() | ||
options._arguments = ['foo'] | ||
options._binary = FirefoxBinary('/bar') | ||
options._preferences = {'foo': 'bar'} | ||
options._proxy = Proxy({'proxyType': ProxyType.MANUAL}) | ||
options._profile = profile | ||
options.log.level = 'debug' | ||
caps = options.to_capabilities() | ||
opts = caps.get(Options.KEY) | ||
assert opts | ||
assert 'foo' in opts['args'] | ||
assert opts['binary'] == '/bar' | ||
assert opts['prefs']['foo'] == 'bar' | ||
assert opts['profile'] == profile.encoded | ||
assert opts['proxy']['proxyType'] == ProxyType.MANUAL['string'] | ||
assert opts['log']['level'] == 'debug' |