Package: robotremoteserver
Robot Frameworkremote servers allow hosting test libraries on different
processes or machines than Robot Framework itself is running on. This project
implements a generic remote server using thePythonprogramming language.
See theremote library interface documentationfor more information about
the remote interface in general as well as for a list of remote server
implementations in other programming languages.This project is hosted onGitHuband downloads are available onPyPI.Supported Python versionsSupported library APIsInstallationRemote server configurationStarting remote serverStarting server on backgroundGetting active server portStopping remote serverTesting is server runningListing keywords and viewing documentationExampleSupported Python versionsThis remote server is implemented withPythonand supports alsoJython(JVM),IronPython(.NET) andPyPy. Remote server version 1.1 supports Python 2.6,
2.7 and 3.3-3.9. Remote server version 1.1.1 supports Python 3.10 and 3.11
as well.Supported library APIsStarting from the remote server version 1.1, Robot Framework’sstatic,
hybrid and dynamic library APIsare all supported. This includes setting
custom name and tags for keywords using therobot.api.deco.keyword.
Earlier remote server versions support only the static and hybrid
APIs and do not support the keyword decorator at all.For most parts these APIs work exactly like when using with Robot Framework
normally. The main limitation is that logging usingrobot.api.loggeror
Python’sloggingmoduleis currently not supported.InstallationThe easiest installation approach is usingpip:pip install robotremoteserverAlternatively you can download the source distribution fromPyPI, extract it
and install the remote server using:python setup.py installRemote server configurationThe remote server is implemented as a classRobotRemoteServerand it
accepts the following configuration parameters when it is initialized:ArgumentDefaultExplanationlibraryTest library instance or module to host. Mandatory argument.host'127.0.0.1'Address to listen. Use'0.0.0.0'to listen to all available IPv4 interfaces.port8270Port to listen. Use0to select a free port automatically. Can be given as an integer or as a string. The default port8270isregistered by IANAfor remote server usage.port_fileNoneFile to write the port that is used.None(default) means no such file is written.allow_stop'DEPRECATED'Deprecated since version 1.1. Useallow_remote_stopinstead.serveTrueIfTrue, start the server automatically and wait for it to be stopped. IfFalse, server can be started using theservemethod. New in version 1.1.allow_remote_stopTrueAllow/disallow stopping the server remotely usingStop Remote Serverkeyword andstop_remote_serverXML-RPC method. New in version 1.1.Starting remote serverThe remote server can be started simply by creating an instance of the server
and passing a test library instance or module to it:fromrobotremoteserverimportRobotRemoteServerfrommylibraryimportMyLibraryRobotRemoteServer(MyLibrary())By default the server listens to address 127.0.0.1 and port 8270. Asdiscussed
above, the remote server accepts various configuration parameters. Some of
them are used by this example:fromrobotremoteserverimportRobotRemoteServerfromexamplelibraryimportExampleLibraryRobotRemoteServer(ExampleLibrary(),host='10.0.0.42',port=0,port_file='/tmp/remote-port.txt')Starting from version 1.1, the server can be initialized without starting it by
using the argumentserve=False. The server can then started afterwards by
calling itsservemethod explicitly. This example is functionally
equivalent to the example above:fromrobotremoteserverimportRobotRemoteServerfromexamplelibraryimportExampleLibraryserver=RobotRemoteServer(ExampleLibrary(),host='10.0.0.42',port=0,port_file='/tmp/remote-port.txt',serve=False)server.serve()Starting server on backgroundThe main benefit of separately initializing and starting the server is that
it makes it easier to start the server in a background thread. Servers started
in a thread work exactly like servers running in the main tread except thatstopping the servergracefully usingCtrl-Cor signals is not
supported automatically. Users must thus register signal handlers separately
if needed.Also this following example is functionally nearly equivalent to the earlier
examples except. The main difference is that not all same signals are handled.importsignalimportthreadingfromexamplelibraryimportExampleLibraryfromrobotremoteserverimportRobotRemoteServerserver=RobotRemoteServer(ExampleLibrary(),port=0,serve=False)signal.signal(signal.SIGINT,lambdasignum,frame:server.stop())server_thread=threading.Thread(target=server.serve)server_thread.start()whileserver_thread.is_alive():server_thread.join(0.1)Getting active server portIf the server uses the default port8270or some other port is given
explicitly whenconfiguring the server, you obviously know which port
to use when connecting the server. When using the port0, the server
selects a free port automatically, but there are various ways how to find
out the actual port:Address and port that are used are printed into the console where the server
is started.Ifport_fileargument is used, the server writes the port into the
specified file where other tools can easily read it. Starting from the
remote server version 1.1, the server removes the port file automatically
when the server is stopped.Starting from the version 1.1, the server hasactivatemethod that can
be called to activate the server without starting it. This method returns
the port that the server binds and also sets it available via the attributes
discussed below.A started or actived server instance hasserver_addressattribute that
contains the address and the port as a tuple. Starting from the version 1.1
there is alsoserver_portattribute that contains just the port as
an integer.Stopping remote serverThe remote server can be gracefully stopped using several different methods:HittingCtrl-Con the console where the server is running. Not supported
automatically if the server isstarted on a background thread.Sending the processSIGINT,SIGTERM, orSIGHUPsignal. Does not
work on Windows and not supported if the server is started on a background
thread.Using the``Stop Remote Server`` keyword. Can be disabled by usingallow_remote_stop=Falsewheninitializing the server.Using thestop_remote_serverfunction in the XML-RPC interface.
Can be disabled with theallow_remote_stop=Falseinitialization parameter.Runningpython-mrobotremoteserver stop [uri]which uses the
aforementionedstop_remote_serverXML-RPC function internally.
Can be disabled with theallow_remote_stop=Falseinitialization parameter.Using thestop_remote_serverfunction provided by therobotremoteservermodule similarly as whentesting is server running.
Uses thestop_remote_serverXML-RPC function internally and
can be disabled with theallow_remote_stop=Falseinitialization parameter.Calling thestopmethod of the running server instance. Mainly useful whenrunning the server on background.Testing is server runningStarting from the version 1.0.1, therobotremoteservermodule supports
testing is a remote server running. This can be accomplished by running
the module as a script withtestargument and an optional URI:$ python -m robotremoteserver test
Remote server running at http://127.0.0.1:8270.
$ python -m robotremoteserver test http://10.0.0.42:57347
No remote server running at http://10.0.0.42:57347.Starting from the version 1.1, therobotremoteservermodule contains
functiontest_remote_serverthat can be used programmatically:fromrobotremoteserverimporttest_remote_serveriftest_remote_server('http://localhost:8270'):print('Remote server running!')Therobotremoteservermodule can be also used to stop a remote server by
usingstopargument on the command line or by using thestop_remote_serverfunction programmatically. Testing and stopping should
work also with other Robot Framework remote server implementations.Listing keywords and viewing documentationUsing the built-inLibdoctool you can list the keywords available on the server:$ python -m robot.libdoc Remote::http://127.0.0.1:8270 list
Count Items In Directory
Stop Remote Server
Strings Should Be EqualIt is also possible to show the documentation on the command line by using
argumentshow. HTML documentation can be created by providing name of
an output file:$ python -m robot.libdoc Remote::http://127.0.0.1:8270 MyLibrary.html
/path/to/MyLibrary.htmlExampleThe remote server project contains anexamplethat can be studied and also
executed once the library is installed. You can get the example by cloning
the project onGitHub, and it is also included in the source distribution
available onPyPI.