Skip to content

Commit 22ef533

Browse files
committed
[py] send Base64 encoded addon to driver instead of path String
1 parent 34a3aa2 commit 22ef533

2 files changed

Lines changed: 43 additions & 4 deletions

File tree

py/selenium/webdriver/firefox/webdriver.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17-
18-
from base64 import b64decode
17+
import base64
1918
from shutil import rmtree
2019
import warnings
2120
from contextlib import contextmanager
@@ -247,7 +246,11 @@ def install_addon(self, path, temporary=None) -> str:
247246
248247
driver.install_addon('/path/to/firebug.xpi')
249248
"""
250-
payload = {"path": path}
249+
file_ = open(path, 'rb')
250+
addon = (base64.b64encode(file_.read()).decode('UTF-8'))
251+
file_.close()
252+
253+
payload = {"addon": addon}
251254
if temporary:
252255
payload["temporary"] = temporary
253256
return self.execute("INSTALL_ADDON", payload)["value"]
@@ -317,7 +320,7 @@ def get_full_page_screenshot_as_png(self) -> str:
317320
318321
driver.get_full_page_screenshot_as_png()
319322
"""
320-
return b64decode(self.get_full_page_screenshot_as_base64().encode('ascii'))
323+
return base64.b64decode(self.get_full_page_screenshot_as_base64().encode('ascii'))
321324

322325
def get_full_page_screenshot_as_base64(self) -> str:
323326
"""
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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 os
19+
from pathlib import Path
20+
21+
from selenium.common.exceptions import WebDriverException
22+
23+
24+
def test_install_addon(driver, pages):
25+
extension = os.path.join(Path(__file__).absolute().parents[5], 'third_party/firebug/favourite_colour-1.1-an+fx.xpi')
26+
id = driver.install_addon(extension)
27+
assert id == '[email protected]'
28+
29+
30+
def test_uninstall_addon(driver, pages):
31+
extension = os.path.join(Path(__file__).absolute().parents[5], 'third_party/firebug/favourite_colour-1.1-an+fx.xpi')
32+
id = driver.install_addon(extension)
33+
try:
34+
driver.uninstall_addon(id)
35+
except WebDriverException as exc:
36+
assert False, exc

0 commit comments

Comments
 (0)