1
1
import os
2
2
3
+ from robot .api import logger
3
4
from robot .errors import ExecutionFailed , HandlerExecutionFailed
4
5
5
6
from .cmdcompleter import CmdCompleter
6
7
from .prompttoolkitcmd import PromptToolkitCmd
7
- from .robotutils import ( SELENIUM_WEBDRIVERS , get_builtin_libs , get_keywords ,
8
- get_lib_keywords , get_libs , get_libs_dict ,
9
- get_robot_instance , match_libs ,
10
- reset_robotframework_exception , run_keyword ,
11
- start_selenium_commands )
8
+ from .robotapp import get_robot_instance , reset_robotframework_exception
9
+ from . robotkeyword import get_keywords , get_lib_keywords , run_keyword
10
+ from . robotlib import get_builtin_libs , get_libs , get_libs_dict , match_libs
11
+ from . robotselenium import SELENIUM_WEBDRIVERS , start_selenium_commands
12
+ from . robotvar import assign_variable
12
13
from .styles import (DEBUG_PROMPT_STYLE , get_debug_prompt_tokens , print_error ,
13
14
print_output )
14
15
@@ -20,21 +21,23 @@ def run_robot_command(robot_instance, command):
20
21
if not command :
21
22
return
22
23
24
+ result = ''
23
25
try :
24
26
result = run_keyword (robot_instance , command )
25
- if result :
26
- head , message = result
27
- print_output (head , message )
28
27
except ExecutionFailed as exc :
29
28
print_error ('! keyword:' , command )
30
- print_error ('!' , exc . message )
29
+ print_error ('! execution failed: ' , str ( exc ) )
31
30
except HandlerExecutionFailed as exc :
32
31
print_error ('! keyword:' , command )
33
- print_error ('!' , exc .full_message )
32
+ print_error ('! handler execution failed: ' , exc .full_message )
34
33
except Exception as exc :
35
34
print_error ('! keyword:' , command )
36
35
print_error ('! FAILED:' , repr (exc ))
37
36
37
+ if result :
38
+ head , message = result
39
+ print_output (head , message )
40
+
38
41
39
42
class DebugCmd (PromptToolkitCmd ):
40
43
"""Interactive debug shell for robotframework."""
@@ -100,8 +103,7 @@ def get_completer(self):
100
103
'Keyword[{0}.]: {1}' .format (keyword ['lib' ], keyword ['doc' ]),
101
104
))
102
105
103
- cmd_completer = CmdCompleter (commands , self )
104
- return cmd_completer
106
+ return CmdCompleter (commands , self )
105
107
106
108
def do_selenium (self , arg ):
107
109
"""Start a selenium webdriver and open url in browser you expect.
@@ -121,7 +123,8 @@ def complete_selenium(self, text, line, begin_idx, end_idx):
121
123
"""Complete selenium command."""
122
124
if len (line .split ()) == 3 :
123
125
command , url , driver_name = line .lower ().split ()
124
- return [d for d in SELENIUM_WEBDRIVERS if d .startswith (driver_name )]
126
+ return [driver for driver in SELENIUM_WEBDRIVERS
127
+ if driver .startswith (driver_name )]
125
128
elif len (line .split ()) == 2 and line .endswith (' ' ):
126
129
return SELENIUM_WEBDRIVERS
127
130
return []
@@ -143,9 +146,9 @@ def do_libs(self, args):
143
146
for lib in get_libs ():
144
147
print_output (' {}' .format (lib .name ), lib .version )
145
148
if lib .doc :
146
- print (' {}' .format (lib .doc .split ('\n ' )[0 ]))
149
+ logger . console (' {}' .format (lib .doc .split ('\n ' )[0 ]))
147
150
if '-s' in args :
148
- print (' {}' .format (lib .source ))
151
+ logger . console (' {}' .format (lib .source ))
149
152
print_output ('<' , 'Builtin libraries:' )
150
153
for name in sorted (get_builtin_libs ()):
151
154
print_output (' ' + name , '' )
@@ -199,8 +202,9 @@ def do_docs(self, kw_name):
199
202
for lib in get_libs ():
200
203
for keyword in get_lib_keywords (lib , long_format = True ):
201
204
if keyword ['name' ].lower () == kw_name .lower ():
202
- print (keyword ['doc' ])
205
+ logger . console (keyword ['doc' ])
203
206
return
204
- print ("could not find documentation for keyword {}" .format (kw_name ))
207
+
208
+ print_error ('< not find keyword' , kw_name )
205
209
206
210
do_d = do_docs
0 commit comments