Skip to content

Commit

Permalink
update documents
Browse files Browse the repository at this point in the history
  • Loading branch information
xyb committed Aug 11, 2017
1 parent 153d98d commit 986b502
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 24 deletions.
7 changes: 7 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
2017-08-11 Xie Yanbo <[email protected]>

* use python-prompt-toolkit to handle prompt with color support
* auto completion for robotframework keywords and debug shell commands
* save history to file
* rename shell script rfshell to rfdebug

2017-08-03 Xie Yanbo <[email protected]>

* fix sys.stdout.encoding error
Expand Down
22 changes: 15 additions & 7 deletions DebugLibrary.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,23 @@
Run standalone:
$ python DebugLibrary.py
[...snap...]
>>>>> Enter interactive shell, only accepted plain text format keyword.
>>>>> Enter interactive shell
Only accepted plain text format keyword seperated with two or more spaces.
Type "help" for more information.
> log hello
> get time
< '2016-07-20 11:51:33'
< '2016-07-20 11:51:33'
> import library String
> get substring helloworld 5 8
< 'wor'
> ${secs} = Get Time epoch
< ${secs} = 1474814470
# ${secs} = 1474814470
> Log to console ${secs}
1474814470
> selenium google.com chrome
import library Selenium2Library
open browser http://google.com chrome
# import library Selenium2Library
# open browser http://google.com chrome
< 1
> close all browsers
> Ctrl-D
>>>>> Exit shell.
Expand Down Expand Up @@ -183,6 +186,7 @@ def get_keywords():


def print_output(head, message, style=NORMAL_STYLE):
"""Print prompt-toolkit tokens to output"""
tokens = [
(Token.Head, head + ' '),
(Token.Message, message),
Expand All @@ -192,6 +196,7 @@ def print_output(head, message, style=NORMAL_STYLE):


def print_error(head, message, style=ERROR_STYLE):
"""Print to output with error style"""
print_output(head, message, style=style)


Expand Down Expand Up @@ -244,7 +249,7 @@ def __init__(self, commands, cmd_repl=None):
self.cmd_repl = cmd_repl

def get_argument_completions(self, completer, document):
"""Call Cmd.py's completer arguments to complete arguments"""
"""Using Cmd.py's completer to complete arguments"""
endidx = document.cursor_position_col
line = document.current_line
begidx = (line[:endidx].rfind(' ') + 1
Expand Down Expand Up @@ -309,12 +314,14 @@ def get_cmd_names(self):
return [_[cut:] for _ in self.get_names() if _.startswith(pre)]

def get_help_string(self, command_name):
"""Get help document of command"""
func = getattr(self, 'do_' + command_name, None)
if not func:
return ''
return func.__doc__

def get_helps(self):
"""Get all help documents of commands"""
return [(name, self.get_help_string(name) or name)
for name in self.get_cmd_names()]

Expand Down Expand Up @@ -362,6 +369,7 @@ def cmdloop(self, intro=None):


def get_prompt_tokens(self, cli):
"""Print prompt-toolkit prompt"""
return [
(Token.Prompt, u'> '),
]
Expand Down Expand Up @@ -605,7 +613,7 @@ def shell():
Library DebugLibrary
** test case **
REPL
RFDEBUG REPL
debug
''')
source.flush()
Expand Down
45 changes: 28 additions & 17 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,18 @@ Debug Library for Robot Framework
Introduction
------------

Robotframework-DebugLibrary is A debug library for `RobotFramework`_,
Robotframework-DebugLibrary is a debug library for `RobotFramework`_,
which can be used as an interactive shell(REPL) also.

.. _`RobotFramework`: http://robotframework.org/

Installation
------------

Installation is done just as for any other Python library.
Using the ``pip`` or ``easy_install`` command from setuptools is the easiest.

To install using ``pip``::

pip install robotframework-debuglibrary

To install using ``easy_install``::

easy_install robotframework-debuglibrary

Usage
-----
Expand All @@ -42,36 +36,53 @@ keyword in your test files like this::

Or you can run it standalone as a ``RobotFramework`` shell::

$ rfshell
$ rfdebug
[...snap...]
>>>>> Enter interactive shell, only accepted plain text format keyword.
> help
Input Robotframework keywords, or commands listed below.
Use "libs" or "l" to see available libraries,
use "keywords" or "k" see list of library keywords.

Documented commands (type help <topic>):
========================================
EOF exit help k keywords l libs pdb s selenium

> log hello
> get time
< '2011-10-13 18:50:31'
< '2011-10-13 18:50:31'
> import library String
> get substring helloworld 5 8
< 'wor'
> ${secs} = Get Time epoch
< ${secs} = 1474814470
# ${secs} = 1474814470
> Log to console ${secs}
1474814470
> @{list} = Create List hello world
< @{list} = [u'hello', u'world']
# @{list} = ['hello', 'world']
> Log to console ${list}
[u'hello', u'world']
['hello', 'world']
> &{dict} = Create Dictionary name=admin [email protected]
< &{dict} = {u'name': u'admin', u'email': u'[email protected]'}
# &{dict} = {'name': 'admin', 'email': '[email protected]'}
> Log ${dict.name}
> help selenium
s(elenium) [<url>] [<browser>]
Start a selenium 2 webdriver and open google.com or other url in firefox or other browser you expect.
Start a selenium 2 webdriver and open url in browser you expect.

s(elenium) [<url>] [<browser>]

default url is google.com, default browser is firefox.
> selenium google.com chrome
import library Selenium2Library
open browser http://google.com/ chrome
# import library Selenium2Library
# open browser http://google.com chrome
< 1
> close all browsers
> Ctrl-D
>>>>> Exit shell.

The interactive shell support auto completion for robotframework keywords and
commands. The history will save at `~/.rfdebug_history` default, or any file
defined in environment variable `RFDEBUG_HISTORY`.

Submitting issues
-----------------

Expand Down

0 comments on commit 986b502

Please sign in to comment.