@@ -4,11 +4,11 @@ Python Remote Server for Robot Framework
4
4
`Robot Framework `_ remote servers allow hosting test libraries on different
5
5
processes or machines than Robot Framework itself is running on. This project
6
6
implements a generic remote server using the Python _ programming language.
7
- See the general `remote library interface documentation `_ for more information
8
- about the remote interface as well as for a list of remote server
7
+ See the `remote library interface documentation `_ for more information about
8
+ the remote interface in general as well as for a list of remote server
9
9
implementations in other programming languages.
10
10
11
- This project is hosted in GitHub _ and downloads are available in PyPI _.
11
+ This project is hosted on GitHub _ and downloads are available on PyPI _.
12
12
13
13
.. _Robot Framework : http://robotframework.org
14
14
.. _remote library interface documentation : https://github.com/robotframework/RemoteInterface
@@ -34,7 +34,7 @@ versions 2.2-2.7.
34
34
Supported library APIs
35
35
----------------------
36
36
37
- Starting from Remote server version 1.1, Robot Framework's standard `static,
37
+ Starting from the remote server version 1.1, Robot Framework's `static,
38
38
hybrid and dynamic library APIs `__ are all supported. This includes setting
39
39
custom name and tags for keywords using the `robot.api.deco.keyword `__
40
40
decorator. Earlier versions support only the static and hybrid APIs and do
@@ -73,20 +73,14 @@ accepts the following configuration parameters when it is initialized:
73
73
===================== ================= ========================================
74
74
``library `` Test library instance or module to host. Mandatory argument.
75
75
``host `` ``'127.0.0.1' `` Address to listen. Use ``'0.0.0.0' `` to listen to all available interfaces.
76
- ``port `` ``8270 `` Port to listen. Use ``0 `` to select a free port automatically. Can be given as an integer or as a string.
76
+ ``port `` ``8270 `` Port to listen. Use ``0 `` to select a free port automatically. Can be given as an integer or as a string. The default port `` 8270 `` is ` registered by IANA `__ for remote server usage.
77
77
``port_file `` ``None `` File to write the port that is used. ``None `` (default) means no such file is written.
78
78
``allow_stop `` ``'DEPRECATED' `` DEPRECATED. User ``allow_remote_stop `` instead.
79
79
``serve `` ``True `` If ``True ``, start the server automatically and wait for it to be stopped. If ``False ``, server can be started using the ``serve `` method. New in version 1.1.
80
80
``allow_remote_stop `` ``True `` Allow/disallow stopping the server remotely using ``Stop Remote Server `` keyword and ``stop_remote_server `` XML-RPC method. New in version 1.1.
81
81
===================== ================= ========================================
82
82
83
- Address and port that are used are printed to the console where the server is
84
- started. Writing port to a file by using ``port_file `` argument is especially
85
- useful when the server selects a free port automatically. Other tools can then
86
- easily read the active port from the file. If the file is removed prior to
87
- starting the server, tools can also wait until the file exists to know that
88
- the server is up and running. Starting from version 1.1, the server removes
89
- the port file automatically when it is stopped.
83
+ __ https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml?search=8270
90
84
91
85
Starting remote server
92
86
----------------------
@@ -110,9 +104,9 @@ __ `Remote server configuration`_
110
104
.. sourcecode :: python
111
105
112
106
from robotremoteserver import RobotRemoteServer
113
- from mylibrary import MyLibrary
107
+ from examplelibrary import ExampleLibrary
114
108
115
- RobotRemoteServer(MyLibrary (), host='10.0.0.42', port=0,
109
+ RobotRemoteServer(ExampleLibrary (), host='10.0.0.42', port=0,
116
110
port_file='/tmp/remote-port.txt')
117
111
118
112
Starting from version 1.1, the server can be initialized without starting it by
@@ -122,46 +116,70 @@ equivalent to the example above:
122
116
123
117
.. sourcecode :: python
124
118
125
- server = RobotRemoteServer(MyLibrary(), host='10.0.0.42', port=0,
119
+ from robotremoteserver import RobotRemoteServer
120
+ from examplelibrary import ExampleLibrary
121
+
122
+ server = RobotRemoteServer(ExampleLibrary(), host='10.0.0.42', port=0,
126
123
port_file='/tmp/remote-port.txt', serve=False)
127
124
server.serve()
128
125
129
126
Starting server on background
130
127
-----------------------------
131
128
132
129
The main benefit of separately initializing and starting the server is that
133
- it makes it easier to start the server on a background thread. This is
134
- illustrated by the following example:
130
+ it makes it easier to start the server in a background thread. Servers started
131
+ in a thread work exactly like servers running in the main tread except that
132
+ `stopping the server `__ gracefully using ``Ctrl-C `` or signals is not
133
+ supported automatically. Users must thus register signal handlers separately
134
+ if needed.
135
+
136
+ Also this following example is functionally nearly equivalent to the earlier
137
+ examples except. The main difference is that not all same signals are handled.
135
138
136
139
.. sourcecode :: python
137
140
141
+ import signal
138
142
import threading
139
- import time
140
-
143
+ from examplelibrary import ExampleLibrary
141
144
from robotremoteserver import RobotRemoteServer
142
- from mylibrary import MyLibrary
143
145
144
- try:
145
- raw_input
146
- except NameError: # Python 3
147
- raw_input = input
148
-
149
- # Initialize server and start it in a thread.
150
- server = RobotRemoteServer(MyLibrary(), port=0, serve=False)
146
+ server = RobotRemoteServer(ExampleLibrary(), port=0, serve=False)
147
+ signal.signal(signal.SIGINT, lambda signum, frame: server.stop())
151
148
server_thread = threading.Thread(target=server.serve)
152
149
server_thread.start()
153
- # Wait for server to be activated and port to be bind.
154
- while server.server_port == 0:
155
- time.sleep(0.1)
156
- # Serve requests until user presses enter.
157
- raw_input('Press enter to stop the server.\n ')
158
- server.stop()
159
- server_thread.join()
160
-
161
- Servers started this way work mostly like servers started on the main thread.
162
- The main difference is that stopping the server gracefully using ``Ctrl-C ``
163
- or signals is not supported automatically. The user must register signal
164
- handlers separately if needed.
150
+ while server_thread.is_alive():
151
+ server_thread.join(0.1)
152
+
153
+ __ `Stopping remote server `_
154
+
155
+ Getting active server port
156
+ --------------------------
157
+
158
+ If the server uses the default port ``8270 `` or some other port is given
159
+ explicitly when `configuring the server `__, you obviously know which port
160
+ to use when connecting the server. When using the port ``0 ``, the server
161
+ selects a free port automatically, but there are various ways how to find
162
+ out the actual port:
163
+
164
+ - Address and port that are used are printed into the console where the server
165
+ is started.
166
+
167
+ - If ``port_file `` argument is used, the server writes the port into the
168
+ specified file where other tools can easily read it. Starting from the
169
+ remote server version 1.1, the server removes the port file automatically
170
+ when the server is stopped.
171
+
172
+ - Starting from the version 1.1, the server has ``activate `` method that can
173
+ be called to activate the server without starting it. This method returns
174
+ the port that the server binds and also sets it available via the attributes
175
+ discussed below.
176
+
177
+ - A started or actived server instance has ``server_address `` attribute that
178
+ contains the address and the port as a tuple. Starting from the version 1.1
179
+ there is also ``server_port `` attribute that contains just the port as
180
+ an integer.
181
+
182
+ __ `Remote server configuration`__
165
183
166
184
Stopping remote server
167
185
----------------------
@@ -179,18 +197,18 @@ The remote server can be gracefully stopped using several different methods:
179
197
``allow_remote_stop=False `` when `initializing the server `__.
180
198
181
199
- Using ``stop_remote_server `` function in the XML-RPC interface.
182
- Can be disabled with ``allow_remote_stop=False ``.
200
+ Can be disabled with the ``allow_remote_stop=False `` initialization parameter .
183
201
184
202
- Running ``python -m robotremoteserver stop [uri] `` which uses the
185
203
aforementioned ``stop_remote_server `` XML-RPC function internally.
186
- Can be disabled with ``allow_remote_stop=False ``.
204
+ Can be disabled with the ``allow_remote_stop=False `` initialization parameter .
187
205
188
206
- Using the ``stop_remote_server `` function provided by the
189
207
``robotremoteserver `` module similarly as when `testing is server running `_.
190
208
Uses the ``stop_remote_server `` XML-RPC function internally and
191
- can be disabled with ``allow_remote_stop=False ``.
209
+ can be disabled with the ``allow_remote_stop=False `` initialization parameter .
192
210
193
- - Calling ``stop `` method of the running server instance. Mainly useful when
211
+ - Calling the ``stop `` method of the running server instance. Mainly useful when
194
212
`running the server on background `__.
195
213
196
214
__ `Starting server on background `_
@@ -200,17 +218,17 @@ __ `Starting server on background`_
200
218
Testing is server running
201
219
-------------------------
202
220
203
- Starting from version 1.0.1 , the ``robotremoteserver `` module supports testing
204
- is a remote server running. This can be accomplished by running the module as
205
- a script with ``test `` argument and an optional URI::
221
+ Starting from the version 1.0.1, the ``robotremoteserver `` module supports
222
+ testing is a remote server running. This can be accomplished by running
223
+ the module as a script with ``test `` argument and an optional URI::
206
224
207
225
$ python -m robotremoteserver test
208
226
Remote server running at http://127.0.0.1:8270.
209
227
$ python -m robotremoteserver test http://10.0.0.42:57347
210
228
No remote server running at http://10.0.0.42:57347.
211
229
212
- Starting from version 1.1, ``robotremoteserver `` module contains function
213
- ``test_remote_server `` that can be used programmatically:
230
+ Starting from the version 1.1, the ``robotremoteserver `` module contains
231
+ function ``test_remote_server `` that can be used programmatically:
214
232
215
233
.. sourcecode :: python
216
234
0 commit comments