Skip to content

Commit 5827d7b

Browse files
committed
Pass the firefox_profile as a desired capability in the Python client when using a remote server
1 parent c54d81c commit 5827d7b

File tree

3 files changed

+75
-3
lines changed

3 files changed

+75
-3
lines changed

py/selenium/webdriver/remote/webdriver.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,14 @@ def start_session(self, desired_capabilities, browser_profile=None):
166166
- javascript_enabled - Whether the new session should support JavaScript.
167167
- browser_profile - A selenium.webdriver.firefox.firefox_profile.FirefoxProfile object. Only used if Firefox is requested.
168168
"""
169-
capabilities = {}
169+
capabilities = {'desiredCapabilities': {}}
170170
for k, v in desired_capabilities.items():
171171
if k not in ('desiredCapabilities', 'requiredCapabilities'):
172-
capabilities.setdefault('desiredCapabilities', {})[k] = v
172+
capabilities['desiredCapabilities'][k] = v
173173
else:
174174
capabilities[k] = v
175175
if browser_profile:
176-
capabilities['requiredCapabilities']['firefox_profile'] = browser_profile.encoded
176+
capabilities['desiredCapabilities']['firefox_profile'] = browser_profile.encoded
177177
response = self.execute(Command.NEW_SESSION, capabilities)
178178
self.session_id = response['sessionId']
179179
self.capabilities = response['value']
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Licensed to the Software Freedom Conservancy (SFC) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The SFC licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Licensed to the Software Freedom Conservancy (SFC) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The SFC licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
import pytest
19+
from selenium import webdriver
20+
from selenium.test.selenium.common import utils
21+
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
22+
23+
24+
@pytest.fixture(autouse=True)
25+
def server(request):
26+
utils.start_server(request)
27+
28+
def fin():
29+
utils.stop_server(request)
30+
request.addfinalizer(fin)
31+
32+
33+
@pytest.fixture
34+
def capabilities():
35+
return DesiredCapabilities.FIREFOX.copy()
36+
37+
38+
@pytest.yield_fixture
39+
def driver(capabilities, profile):
40+
driver = webdriver.Remote(
41+
desired_capabilities=capabilities,
42+
browser_profile=profile)
43+
yield driver
44+
driver.quit()
45+
46+
47+
@pytest.fixture
48+
def profile():
49+
profile = webdriver.FirefoxProfile()
50+
profile.set_preference('browser.startup.homepage', 'about:')
51+
profile.update_preferences()
52+
return profile
53+
54+
55+
def test_profile_is_used(driver):
56+
assert 'about:' == driver.current_url

0 commit comments

Comments
 (0)