Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removes SeleniumLibrary Firefox profile #885

Merged
merged 7 commits into from
Sep 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ exclude */*.rst # limit previous command to include only *.rst files in root fol
include docs/SeleniumLibrary.html

recursive-include src *.py
graft src/SeleniumLibrary/resources
recursive-exclude src *.pyc
14 changes: 14 additions & 0 deletions src/SeleniumLibrary/base/librarycomponent.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os

from robot.api import logger
from robot.libraries.BuiltIn import BuiltIn, RobotNotRunningError

from .context import ContextAware
from .robotlibcore import PY2


LOG_LEVELS = ['TRACE', 'DEBUG', 'INFO', 'WARN', 'ERROR']
Expand Down Expand Up @@ -56,3 +60,13 @@ def assert_page_not_contains(self, locator, tag=None, message=None,
loglevel='INFO'):
self.element_finder.assert_page_not_contains(locator, tag, message,
loglevel)

@property
def log_dir(self):
try:
logfile = BuiltIn().get_variable_value('${LOG FILE}')
if logfile == 'NONE':
return BuiltIn().get_variable_value('${OUTPUTDIR}')
return os.path.dirname(logfile)
except RobotNotRunningError:
return os.getcwdu() if PY2 else os.getcwd()
24 changes: 18 additions & 6 deletions src/SeleniumLibrary/keywords/browsermanagement.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
from SeleniumLibrary.base import LibraryComponent, keyword
from SeleniumLibrary.locators.windowmanager import WindowManager
from SeleniumLibrary.utils import (is_truthy, is_falsy,
secs_to_timestr, timestr_to_secs)
secs_to_timestr, timestr_to_secs,
SELENIUM_VERSION)


ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
Expand Down Expand Up @@ -126,7 +127,11 @@ def open_browser(
(created with 'Create Dictionary') to allow for more complex configurations.

Optional 'ff_profile_dir' is the path to the firefox profile dir if you
wish to overwrite the default.
wish to overwrite the default. Starting from SeleniumLibrary 3.0.0
the SeleniumLibrary does not anymore contain own profile, instead
Selenium
[https://seleniumhq.github.io/selenium/docs/api/py/webdriver_firefox/selenium.webdriver.firefox.firefox_profile.html|webdriver.FirefoxProfile()]
is used.
"""
if is_truthy(remote_url):
self.info("Opening browser '%s' to base url '%s' through "
Expand Down Expand Up @@ -601,16 +606,17 @@ def _make_browser(self, browser_name, desired_capabilities=None,
return browser

def _make_ff(self, remote, desired_capabilites, profile_dir):

if is_falsy(profile_dir):
profile_dir = FIREFOX_PROFILE_DIR
profile = webdriver.FirefoxProfile(profile_dir)
profile = webdriver.FirefoxProfile()
else:
profile = webdriver.FirefoxProfile(profile_dir)
if is_truthy(remote):
browser = self._create_remote_web_driver(
webdriver.DesiredCapabilities.FIREFOX, remote,
desired_capabilites, profile)
else:
browser = webdriver.Firefox(firefox_profile=profile)
browser = webdriver.Firefox(firefox_profile=profile,
**self._geckodriver_log_config)
return browser

def _make_ie(self, remote, desired_capabilities, profile_dir):
Expand Down Expand Up @@ -718,3 +724,9 @@ def _log_list(self, items, what='item'):
msg.append('{}: {}'.format(index + 1, item))
self.info('\n'.join(msg))
return items

@property
def _geckodriver_log_config(self):
if SELENIUM_VERSION.major == '3':
return {'log_path': os.path.join(self.log_dir, 'geckodriver.log')}
return {}
17 changes: 2 additions & 15 deletions src/SeleniumLibrary/keywords/screenshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import os
import re

from robot.libraries.BuiltIn import BuiltIn, RobotNotRunningError
from robot.utils import get_link_path

from SeleniumLibrary.base import LibraryComponent, keyword
Expand Down Expand Up @@ -147,7 +146,7 @@ def _get_screenshot_directory(self):
return self.screenshot_root_directory

# Otherwise use RF's log directory
return self._get_log_dir()
return self.log_dir

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

filename = filename.replace('/', os.sep)
logdir = self._get_log_dir()
path = os.path.join(screenshotdir, filename)
link = get_link_path(path, logdir)
link = get_link_path(path, self.log_dir)
return path, link

def _get_screenshot_index(self, filename):
if filename not in self._screenshot_index:
self._screenshot_index[filename] = 0
self._screenshot_index[filename] += 1
return self._screenshot_index[filename]

def _get_log_dir(self):
try:
logfile = BuiltIn().get_variable_value('${LOG FILE}')
except RobotNotRunningError:
logfile = os.getcwd()
if logfile != 'NONE':
logdir = os.path.dirname(logfile)
else:
logdir = BuiltIn().get_variable_value('${OUTPUTDIR}')
return logdir
71 changes: 0 additions & 71 deletions src/SeleniumLibrary/resources/firefoxprofile/localstore.rdf

This file was deleted.

53 changes: 0 additions & 53 deletions src/SeleniumLibrary/resources/firefoxprofile/prefs.js

This file was deleted.

1 change: 1 addition & 0 deletions src/SeleniumLibrary/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from .browsercache import BrowserCache
from .deprecated import Deprecated
from .librarylistener import LibraryListener
from .seleniumversion import SELENIUM_VERSION
from .types import is_string, is_truthy, is_falsy


Expand Down
23 changes: 23 additions & 0 deletions src/SeleniumLibrary/utils/seleniumversion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2008-2011 Nokia Networks
# Copyright 2011-2016 Ryan Tomac, Ed Manlove and contributors
# Copyright 2016- Robot Framework Foundation
#
# Licensed 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.

from collections import namedtuple

import selenium

SeleniumVersion = namedtuple('SeleniumVersion', 'major minor micro')
major, minor, micro = (selenium.__version__.split('.') + ['0', '0'])[:3]
SELENIUM_VERSION = SeleniumVersion(major=major, minor=minor, micro=micro)