Skip to content

Commit 4109066

Browse files
author
AutomatedTester
committed
Add Firefox specific command to switch context between Browser content and Browser chrome
1 parent 7c97c37 commit 4109066

File tree

3 files changed

+76
-1
lines changed

3 files changed

+76
-1
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
from selenium.webdriver.remote.remote_connection import RemoteConnection
19+
20+
class FirefoxRemoteConnection(RemoteConnection):
21+
22+
def __init__(self, remote_server_addr, keep_alive=True):
23+
RemoteConnection.__init__(self, remote_server_addr, keep_alive)
24+
self._commands["SET_CONTEXT"] = ('POST',
25+
'/session/$sessionId/moz/context')

py/selenium/webdriver/firefox/webdriver.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from .service import Service
2929
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
3030
from selenium.webdriver.firefox.extension_connection import ExtensionConnection
31+
from .remote_connection import FirefoxRemoteConnection
3132
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
3233
from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
3334

@@ -60,7 +61,8 @@ def __init__(self, firefox_profile=None, firefox_binary=None, timeout=30,
6061
self.service.start()
6162

6263
RemoteWebDriver.__init__(self,
63-
command_executor=self.service.service_url,
64+
command_executor=FirefoxRemoteConnection(
65+
remote_server_addr=self.service.service_url),
6466
desired_capabilities=capabilities,
6567
keep_alive=True)
6668

@@ -103,3 +105,6 @@ def quit(self):
103105
@property
104106
def firefox_profile(self):
105107
return self.profile
108+
109+
def set_context(self, context):
110+
self.execute("SET_CONTEXT", {"context": context})
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
19+
from selenium import webdriver
20+
from selenium.test.selenium.webdriver.common.webserver import SimpleWebServer
21+
22+
class TestMarionetteSpecific:
23+
24+
def setup_method(self, method):
25+
self.driver = webdriver.Firefox()
26+
self.CHROME = 'chrome'
27+
self.CONTENT = 'content'
28+
29+
def test_we_can_switch_context_to_chrome(self):
30+
self.driver.set_context(self.CHROME)
31+
self.driver.execute_script("var c = Components.classes; return 1;");
32+
33+
def teardown_method(self, method):
34+
try:
35+
self.driver.set_context(self.CONTENT)
36+
self.driver.quit()
37+
except:
38+
pass # Don't care since we may have killed the browser above
39+
40+
41+
def teardown_module(module):
42+
try:
43+
TestMarionetteSpecific.driver.quit()
44+
except:
45+
pass # Don't Care since we may have killed the browser above

0 commit comments

Comments
 (0)