Skip to content

Commit

Permalink
[py] add unit tests for Firefox Options
Browse files Browse the repository at this point in the history
  • Loading branch information
lmtierney committed Nov 16, 2017
1 parent 35e795b commit 39f2e4e
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 8 deletions.
8 changes: 5 additions & 3 deletions py/selenium/webdriver/firefox/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __init__(self):

@property
def binary(self):
"""Returns the location of the binary."""
"""Returns the FirefoxBinary instance"""
return self._binary

@binary.setter
Expand All @@ -58,10 +58,12 @@ def binary(self, new_binary):

@property
def binary_location(self):
return self.binary
"""Returns the location of the binary."""
return self.binary._start_cmd

@binary.setter # noqa
@binary_location.setter # noqa
def binary_location(self, value):
""" Sets the location of the browser binary by string """
self.binary = value

@property
Expand Down
13 changes: 8 additions & 5 deletions py/test/unit/selenium/webdriver/chrome/chrome_options_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,12 @@ def test_creates_capabilities(options):
options._binary_location = '/bar'
options._extensions = ['baz']
options._debugger_address = '/foo/bar'
options._experimental_options = {'foo': 'bar'}
caps = options.to_capabilities()
assert Options.KEY in caps
assert 'foo' in caps[Options.KEY]['args']
assert caps[Options.KEY]['binary'] == '/bar'
assert 'baz' in caps[Options.KEY]['extensions']
assert caps[Options.KEY]['debuggerAddress'] == '/foo/bar'
opts = caps.get(Options.KEY)
assert opts
assert 'foo' in opts['args']
assert opts['binary'] == '/bar'
assert 'baz' in opts['extensions']
assert opts['debuggerAddress'] == '/foo/bar'
assert opts['foo'] == 'bar'
152 changes: 152 additions & 0 deletions py/test/unit/selenium/webdriver/firefox/firefox_options_tests.py
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'

0 comments on commit 39f2e4e

Please sign in to comment.