10
10
from importlib import import_module , reload
11
11
from io import StringIO
12
12
13
+
14
+ def log (message ):
15
+ js .postMessage (json .dumps ({"std_output" : message }))
16
+
17
+
18
+ requirements_list = json .loads (requirements )
19
+
13
20
try :
14
21
import robot
15
22
from robot .libdocpkg import LibraryDocumentation
16
23
except ImportError :
17
- js . postMessage ( json . dumps ({ "std_output" : f"Install Robot Framework" }) )
24
+ log ( f"Install Robot Framework" )
18
25
rf_version = f"=={ version } " if version else ""
19
26
try :
20
- await micropip .install (f"robotframework{ rf_version } " )
27
+ await micropip .install (requirements_list or f"robotframework{ rf_version } " )
21
28
time .sleep (1 )
22
29
import robot
23
30
from robot .libdocpkg import LibraryDocumentation
24
31
except Exception as e :
25
32
js .console .log (f"Robot Run Exception: { e } " )
26
33
js .console .log (traceback .format_exc ())
27
- js .postMessage (json .dumps ({"std_output" : f" = version { robot .__version__ } \n " }))
28
-
34
+ log (f" = version { robot .__version__ } \n " )
35
+ if requirements_list :
36
+ log (f"Installed Requirements: { requirements_list } \n " )
29
37
30
38
os .chdir ("/" )
31
39
dirname = "robot_files"
@@ -43,7 +51,7 @@ class Listener:
43
51
ROBOT_LISTENER_API_VERSION = 2
44
52
45
53
def _post_message (self ):
46
- js . postMessage ( json . dumps ({ "std_output" : sys .stdout .getvalue ()} ))
54
+ log ( sys .stdout .getvalue ())
47
55
sys .__stdout__ .truncate (0 )
48
56
49
57
def library_import (self , name , attrs ):
@@ -90,6 +98,7 @@ def write_file(file):
90
98
f .writelines (file ["content" ])
91
99
92
100
file_list = json .loads (file_catalog )
101
+ robot_arguments = json .loads (robot_args )
93
102
94
103
for file in file_list :
95
104
write_file (file )
@@ -104,14 +113,13 @@ def write_file(file):
104
113
kwargs = {}
105
114
testcli = ""
106
115
107
- js .postMessage (
108
- json .dumps (
109
- {
110
- "std_output" : f"> robot --loglevel TRACE:INFO --exclude EXCL --skip SKIP\n "
111
- f" --removekeywords tag:REMOVE --flattenkeywords tag:FLAT{ testcli } .\n "
112
- }
113
- )
114
- )
116
+ if robot_arguments :
117
+ log (f"Robot Run Arguments: { robot_args } \n " )
118
+ log (f"\n Running Robot Framework:\n " )
119
+ else :
120
+ log (f"> robot --loglevel TRACE:INFO --exclude EXCL --skip SKIP\n "
121
+ f" --removekeywords tag:REMOVE --flattenkeywords tag:FLAT{ testcli } .\n " )
122
+
115
123
org_stdout = sys .__stdout__
116
124
org_stderr = sys .__stderr__
117
125
sys .stdout = sys .__stdout__ = StringIO ()
@@ -124,19 +132,25 @@ def write_file(file):
124
132
js .console .log (f'reimporting: { file ["fileName" ]} ' )
125
133
m = import_module (file_name )
126
134
m = reload (m )
127
-
128
- result = robot .run (
129
- "." ,
130
- consolecolors = "ansi" ,
131
- listener = [Listener ()], # "RobotStackTracer",
132
- loglevel = "TRACE:INFO" ,
133
- # include="INCL",
134
- exclude = "EXCL" ,
135
- skip = "SKIP" ,
136
- removekeywords = "tag:REMOVE" ,
137
- flattenkeywords = "tag:FLAT" ,
138
- ** kwargs ,
139
- )
135
+ if robot_arguments :
136
+ robot_arguments ["listener" ] = [Listener ()] + robot_arguments .get ("listener" , [])
137
+ robot_arguments ["consolecolors" ] = "ansi"
138
+ result = robot .run (
139
+ "." ,
140
+ ** robot_arguments
141
+ )
142
+ else :
143
+ result = robot .run (
144
+ "." ,
145
+ consolecolors = "ansi" ,
146
+ listener = [Listener ()],
147
+ loglevel = "TRACE:INFO" ,
148
+ exclude = "EXCL" ,
149
+ skip = "SKIP" ,
150
+ removekeywords = "tag:REMOVE" ,
151
+ flattenkeywords = "tag:FLAT" ,
152
+ ** kwargs ,
153
+ )
140
154
js .console .log (f"result: { result } " )
141
155
except Exception as e :
142
156
js .console .log (f"Robot Run Exception: { e } " )
@@ -146,7 +160,7 @@ def write_file(file):
146
160
std_output = sys .__stdout__ .getvalue ()
147
161
sys .__stdout__ = org_stdout
148
162
sys .stdout = sys .__stdout__
149
- js . postMessage ( json . dumps ({ " std_output" : std_output }) )
163
+ log ( std_output )
150
164
151
165
with open ("/log.html" , "r" , encoding = "UTF-8" ) as f :
152
166
log_html = str (f .read ())
0 commit comments