Skip to content

Commit 091e359

Browse files
authored
Removes SeleniumLibrary Firefox profile (robotframework#885)
* Removes SeleniumLibrary Firefox profile The SeleniumLibrary default Firefox profile is now removed. When Firefox created and if Firefox profile is not defined, then the default Selenium FirefoxProfile is used. Updated Open Browser keyword documentation when the FF profile has changed. Adds namedtuple which contains selenium version Fixes based on the comments Fixes robotframework#883
1 parent fa1fee3 commit 091e359

File tree

8 files changed

+58
-146
lines changed

8 files changed

+58
-146
lines changed

MANIFEST.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@ exclude */*.rst # limit previous command to include only *.rst files in root fol
77
include docs/SeleniumLibrary.html
88

99
recursive-include src *.py
10-
graft src/SeleniumLibrary/resources
1110
recursive-exclude src *.pyc

src/SeleniumLibrary/base/librarycomponent.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17+
import os
18+
1719
from robot.api import logger
20+
from robot.libraries.BuiltIn import BuiltIn, RobotNotRunningError
1821

1922
from .context import ContextAware
23+
from .robotlibcore import PY2
2024

2125

2226
LOG_LEVELS = ['TRACE', 'DEBUG', 'INFO', 'WARN', 'ERROR']
@@ -56,3 +60,13 @@ def assert_page_not_contains(self, locator, tag=None, message=None,
5660
loglevel='INFO'):
5761
self.element_finder.assert_page_not_contains(locator, tag, message,
5862
loglevel)
63+
64+
@property
65+
def log_dir(self):
66+
try:
67+
logfile = BuiltIn().get_variable_value('${LOG FILE}')
68+
if logfile == 'NONE':
69+
return BuiltIn().get_variable_value('${OUTPUTDIR}')
70+
return os.path.dirname(logfile)
71+
except RobotNotRunningError:
72+
return os.getcwdu() if PY2 else os.getcwd()

src/SeleniumLibrary/keywords/browsermanagement.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
from SeleniumLibrary.base import LibraryComponent, keyword
2626
from SeleniumLibrary.locators.windowmanager import WindowManager
2727
from SeleniumLibrary.utils import (is_truthy, is_falsy,
28-
secs_to_timestr, timestr_to_secs)
28+
secs_to_timestr, timestr_to_secs,
29+
SELENIUM_VERSION)
2930

3031

3132
ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
@@ -126,7 +127,11 @@ def open_browser(
126127
(created with 'Create Dictionary') to allow for more complex configurations.
127128
128129
Optional 'ff_profile_dir' is the path to the firefox profile dir if you
129-
wish to overwrite the default.
130+
wish to overwrite the default. Starting from SeleniumLibrary 3.0.0
131+
the SeleniumLibrary does not anymore contain own profile, instead
132+
Selenium
133+
[https://seleniumhq.github.io/selenium/docs/api/py/webdriver_firefox/selenium.webdriver.firefox.firefox_profile.html|webdriver.FirefoxProfile()]
134+
is used.
130135
"""
131136
if is_truthy(remote_url):
132137
self.info("Opening browser '%s' to base url '%s' through "
@@ -601,16 +606,17 @@ def _make_browser(self, browser_name, desired_capabilities=None,
601606
return browser
602607

603608
def _make_ff(self, remote, desired_capabilites, profile_dir):
604-
605609
if is_falsy(profile_dir):
606-
profile_dir = FIREFOX_PROFILE_DIR
607-
profile = webdriver.FirefoxProfile(profile_dir)
610+
profile = webdriver.FirefoxProfile()
611+
else:
612+
profile = webdriver.FirefoxProfile(profile_dir)
608613
if is_truthy(remote):
609614
browser = self._create_remote_web_driver(
610615
webdriver.DesiredCapabilities.FIREFOX, remote,
611616
desired_capabilites, profile)
612617
else:
613-
browser = webdriver.Firefox(firefox_profile=profile)
618+
browser = webdriver.Firefox(firefox_profile=profile,
619+
**self._geckodriver_log_config)
614620
return browser
615621

616622
def _make_ie(self, remote, desired_capabilities, profile_dir):
@@ -718,3 +724,9 @@ def _log_list(self, items, what='item'):
718724
msg.append('{}: {}'.format(index + 1, item))
719725
self.info('\n'.join(msg))
720726
return items
727+
728+
@property
729+
def _geckodriver_log_config(self):
730+
if SELENIUM_VERSION.major == '3':
731+
return {'log_path': os.path.join(self.log_dir, 'geckodriver.log')}
732+
return {}

src/SeleniumLibrary/keywords/screenshot.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import os
1919
import re
2020

21-
from robot.libraries.BuiltIn import BuiltIn, RobotNotRunningError
2221
from robot.utils import get_link_path
2322

2423
from SeleniumLibrary.base import LibraryComponent, keyword
@@ -147,7 +146,7 @@ def _get_screenshot_directory(self):
147146
return self.screenshot_root_directory
148147

149148
# Otherwise use RF's log directory
150-
return self._get_log_dir()
149+
return self.log_dir
151150

152151
# should only be called by set_screenshot_directory
153152
def _restore_screenshot_directory(self):
@@ -170,24 +169,12 @@ def _get_screenshot_paths(self, filename_template):
170169
index=self._get_screenshot_index(filename_template))
171170

172171
filename = filename.replace('/', os.sep)
173-
logdir = self._get_log_dir()
174172
path = os.path.join(screenshotdir, filename)
175-
link = get_link_path(path, logdir)
173+
link = get_link_path(path, self.log_dir)
176174
return path, link
177175

178176
def _get_screenshot_index(self, filename):
179177
if filename not in self._screenshot_index:
180178
self._screenshot_index[filename] = 0
181179
self._screenshot_index[filename] += 1
182180
return self._screenshot_index[filename]
183-
184-
def _get_log_dir(self):
185-
try:
186-
logfile = BuiltIn().get_variable_value('${LOG FILE}')
187-
except RobotNotRunningError:
188-
logfile = os.getcwd()
189-
if logfile != 'NONE':
190-
logdir = os.path.dirname(logfile)
191-
else:
192-
logdir = BuiltIn().get_variable_value('${OUTPUTDIR}')
193-
return logdir

src/SeleniumLibrary/resources/firefoxprofile/localstore.rdf

Lines changed: 0 additions & 71 deletions
This file was deleted.

src/SeleniumLibrary/resources/firefoxprofile/prefs.js

Lines changed: 0 additions & 53 deletions
This file was deleted.

src/SeleniumLibrary/utils/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from .browsercache import BrowserCache
2020
from .deprecated import Deprecated
2121
from .librarylistener import LibraryListener
22+
from .seleniumversion import SELENIUM_VERSION
2223
from .types import is_string, is_truthy, is_falsy
2324

2425

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright 2008-2011 Nokia Networks
2+
# Copyright 2011-2016 Ryan Tomac, Ed Manlove and contributors
3+
# Copyright 2016- Robot Framework Foundation
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# 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, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
from collections import namedtuple
18+
19+
import selenium
20+
21+
SeleniumVersion = namedtuple('SeleniumVersion', 'major minor micro')
22+
major, minor, micro = (selenium.__version__.split('.') + ['0', '0'])[:3]
23+
SELENIUM_VERSION = SeleniumVersion(major=major, minor=minor, micro=micro)

0 commit comments

Comments
 (0)