-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactory: split robotframework's logic into more files
- Loading branch information
Showing
15 changed files
with
229 additions
and
212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
from .keywords import DebugKeywords | ||
from .version import VERSION | ||
|
||
"""A debug library and REPL for RobotFramework.""" | ||
|
||
|
||
class DebugLibrary(DebugKeywords): | ||
"""Debug Library for RobotFramework.""" | ||
|
||
ROBOT_LIBRARY_SCOPE = 'GLOBAL' | ||
ROBOT_LIBRARY_VERSION = VERSION |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
|
||
from robot.api import logger | ||
from robot.libraries.BuiltIn import BuiltIn | ||
from robot.running.signalhandler import STOP_SIGNAL_MONITOR | ||
|
||
|
||
def get_robot_instance(): | ||
"""Get robotframework builtin instance as context.""" | ||
return BuiltIn() | ||
|
||
|
||
def reset_robotframework_exception(): | ||
"""Resume RF after press ctrl+c during keyword running.""" | ||
if STOP_SIGNAL_MONITOR._signal_count: | ||
STOP_SIGNAL_MONITOR._signal_count = 0 | ||
STOP_SIGNAL_MONITOR._running_keyword = True | ||
logger.info('Reset last exception of DebugLibrary') | ||
|
||
|
||
def assign_variable(robot_instance, variable_name, args): | ||
"""Assign a robotframework variable.""" | ||
variable_value = robot_instance.run_keyword(*args) | ||
robot_instance._variables.__setitem__(variable_name, variable_value) | ||
return variable_value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import re | ||
|
||
from robot.libdocpkg.model import LibraryDoc | ||
|
||
from .memoize import memoize | ||
from .robotlib import ImportedLibraryDocBuilder, get_libs | ||
from .robotvar import assign_variable | ||
|
||
try: | ||
from robot.variables.search import is_variable | ||
except ImportError: | ||
from robot.variables import is_var as is_variable # robotframework < 3.2 | ||
|
||
KEYWORD_SEP = re.compile(' +|\t') | ||
|
||
|
||
def parse_keyword(command): | ||
"""Split a robotframework keyword string.""" | ||
return KEYWORD_SEP.split(command) | ||
|
||
|
||
@memoize | ||
def get_lib_keywords(library, long_format=False): | ||
"""Get keywords of imported library.""" | ||
lib = ImportedLibraryDocBuilder().build(library) | ||
keywords = [] | ||
for keyword in lib.keywords: | ||
if long_format: | ||
doc = keyword.doc | ||
else: | ||
doc = keyword.doc.split('\n')[0] | ||
keywords.append({ | ||
'name': keyword.name, | ||
'lib': library.name, | ||
'doc': doc, | ||
}) | ||
return keywords | ||
|
||
|
||
def get_keywords(): | ||
"""Get all keywords of libraries.""" | ||
for lib in get_libs(): | ||
yield from get_lib_keywords(lib) | ||
|
||
|
||
def run_keyword(robot_instance, keyword): | ||
"""Run a keyword in robotframewrk environment.""" | ||
if not keyword: | ||
return | ||
|
||
keyword_args = parse_keyword(keyword) | ||
keyword = keyword_args[0] | ||
args = keyword_args[1:] | ||
|
||
is_comment = keyword.strip().startswith('#') | ||
if is_comment: | ||
return | ||
|
||
variable_name = keyword.rstrip('= ') | ||
if is_variable(variable_name): | ||
variable_only = not args | ||
if variable_only: | ||
display_value = ['Log to console', keyword] | ||
robot_instance.run_keyword(*display_value) | ||
else: | ||
variable_value = assign_variable( | ||
robot_instance, | ||
variable_name, | ||
args, | ||
) | ||
echo = '{0} = {1!r}'.format(variable_name, variable_value) | ||
return ('#', echo) | ||
else: | ||
output = robot_instance.run_keyword(keyword, *args) | ||
if output: | ||
return ('<', repr(output)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import re | ||
|
||
from robot.libdocpkg.model import LibraryDoc | ||
from robot.libdocpkg.robotbuilder import KeywordDocBuilder, LibraryDocBuilder | ||
from robot.libraries import STDLIBS | ||
from robot.running.namespace import IMPORTER | ||
|
||
|
||
def get_builtin_libs(): | ||
"""Get robotframework builtin library names.""" | ||
return list(STDLIBS) | ||
|
||
|
||
def get_libs(): | ||
"""Get imported robotframework library names.""" | ||
return sorted(IMPORTER._library_cache._items, key=lambda _: _.name) | ||
|
||
|
||
def get_libs_dict(): | ||
"""Get imported robotframework libraries as a name -> lib dict""" | ||
return {lib.name: lib for lib in IMPORTER._library_cache._items} | ||
|
||
|
||
def match_libs(name=''): | ||
"""Find libraries by prefix of library name, default all""" | ||
libs = [_.name for _ in get_libs()] | ||
matched = [_ for _ in libs if _.lower().startswith(name.lower())] | ||
return matched | ||
|
||
|
||
class ImportedLibraryDocBuilder(LibraryDocBuilder): | ||
|
||
def build(self, lib): | ||
libdoc = LibraryDoc( | ||
name=lib.name, | ||
doc=self._get_doc(lib), | ||
doc_format=lib.doc_format, | ||
) | ||
libdoc.inits = self._get_initializers(lib) | ||
libdoc.keywords = KeywordDocBuilder().build_keywords(lib) | ||
return libdoc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
from .robotkeyword import parse_keyword | ||
|
||
SELENIUM_WEBDRIVERS = ['firefox', 'chrome', 'ie', | ||
'opera', 'safari', 'phantomjs', 'remote'] | ||
|
||
|
||
def start_selenium_commands(arg): | ||
"""Start a selenium webdriver and open url in browser you expect. | ||
arg: [<url> or google] [<browser> or firefox] | ||
""" | ||
yield 'import library SeleniumLibrary' | ||
|
||
# Set defaults, overriden if args set | ||
url = 'http://www.google.com/' | ||
browser = 'firefox' | ||
if arg: | ||
args = parse_keyword(arg) | ||
if len(args) == 2: | ||
url, browser = args | ||
else: | ||
url = arg | ||
if '://' not in url: | ||
url = 'http://' + url | ||
|
||
yield 'open browser %s %s' % (url, browser) |
Oops, something went wrong.
9f87267
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note, for your information, that there are some forks that have fixed other bugs.
If you are interested, it could be worth while to add them to the main branch "before this one"
9f87267
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stdedos Good idea, I will check if I can merge some forks into the main branch. Thank you very much for your notice! I did this refactoring to make it easier for contributors to add new features. If you think whose fork deserves priority attention, please let me know.
9f87267
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From an old list of mine:
https://github.com/DanielPBak/robotframework-debuglibrary
https://github.com/jollychang/robotframework-debuglibrary
https://github.com/peritus/robotframework-debuglibrary
But I don't have my generating-script available somewhere here and I didn't do any deeper digging, so YMMV.
I have already asked Github to add a +/- commits on the forks screen, but it does not seem to get traction.
Feel free to bug the Github support team:
9f87267
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stdedos I have reviewed three forks you pointed and confirm there's nothing to merge back into. DanielPBak try to implement step debugging but not finished, so I spent some time research and done it in version v2.1.0
9f87267
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it is so then it is so! Thank you for spending time :-D
I do think, however, someone had changed the default filename extension for the throwaway file you use to initiate Robot (must be
*.robot
instead of*.txt
)I haven't checked if you had done it already though
9f87267
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stdedos changed already:
robotframework-debuglibrary/DebugLibrary/shell.py
Line 22 in fa99c55
9f87267
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, okay - you stashed the change in that commit 😛