Skip to content

Commit

Permalink
Pass the firefox_profile as a desired capability in the Python client…
Browse files Browse the repository at this point in the history
… when using a remote server
  • Loading branch information
davehunt committed Jun 8, 2016
1 parent e77cfde commit 1e6dd55
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 3 deletions.
6 changes: 3 additions & 3 deletions py/selenium/webdriver/remote/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,14 @@ def start_session(self, desired_capabilities, browser_profile=None):
- javascript_enabled - Whether the new session should support JavaScript.
- browser_profile - A selenium.webdriver.firefox.firefox_profile.FirefoxProfile object. Only used if Firefox is requested.
"""
capabilities = {}
capabilities = {'desiredCapabilities': {}}
for k, v in desired_capabilities.items():
if k not in ('desiredCapabilities', 'requiredCapabilities'):
capabilities.setdefault('desiredCapabilities', {})[k] = v
capabilities['desiredCapabilities'][k] = v
else:
capabilities[k] = v
if browser_profile:
capabilities['requiredCapabilities']['firefox_profile'] = browser_profile.encoded
capabilities['desiredCapabilities']['firefox_profile'] = browser_profile.encoded
response = self.execute(Command.NEW_SESSION, capabilities)
self.session_id = response['sessionId']
self.capabilities = response['value']
Expand Down
16 changes: 16 additions & 0 deletions py/test/selenium/webdriver/remote/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# 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.
56 changes: 56 additions & 0 deletions py/test/selenium/webdriver/remote/remote_firefox_profile_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# 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 import webdriver
from selenium.test.selenium.common import utils
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities


@pytest.fixture(autouse=True)
def server(request):
utils.start_server(request)

def fin():
utils.stop_server(request)
request.addfinalizer(fin)


@pytest.fixture
def capabilities():
return DesiredCapabilities.FIREFOX.copy()


@pytest.yield_fixture
def driver(capabilities, profile):
driver = webdriver.Remote(
desired_capabilities=capabilities,
browser_profile=profile)
yield driver
driver.quit()


@pytest.fixture
def profile():
profile = webdriver.FirefoxProfile()
profile.set_preference('browser.startup.homepage', 'about:')
profile.update_preferences()
return profile


def test_profile_is_used(driver):
assert 'about:' == driver.current_url

0 comments on commit 1e6dd55

Please sign in to comment.