Setup and execution of tests using Remote library interface

1,811 views
Skip to first unread message

Lev

unread,
Mar 4, 2016, 4:12:02 PM3/4/16
to robotframework-users
Hello,

For some tests I create keywords in Java, when running tests using Robot framework in Python.
My understanding that solution for that is Remote library interface.
I've reviewed different docs and articles, but still it is not clear how to setup and execute tests using Remote library interface.
I would appreciate, if somebody share tutorial, examples, any material that wouls clarify things.

Thanks!

Kevin O.

unread,
Mar 4, 2016, 5:43:55 PM3/4/16
to robotframework-users
If you run Robot Framework under Jython, then you do not need to utilize the remote library interface.
Robot Framework can load Java libraries in this setup.
There is a standalone JAR to run with Jython, but keep in mind that if you run a JAR, Java will ignore CLASSPATH. More on that here.
Alternatively, you can use Jython separately and not use the JAR - see install RF via PIP on Jython.

If you want to execute in CPython and not utilize Jython, then I recommend using jrobotremoteserver.

First place to start is the Getting Started page.
 
I created an example project for those using Maven and AnnotationLibrary. It supposed to be all-in-one including unit testing and acceptance testing.
Unfortunately I never updated it - here's the changes I remember needing to make:
Update jrobotremoteserver version.
Update RF Maven version.
On more recent versions of RF Maven plugin, the default test location is different. The example uses the old location (src/test/resources/robotframework/tests/).
The methods used to add the library were deprecated.

Kevin

Lev

unread,
Mar 5, 2016, 12:07:10 PM3/5/16
to robotframework-users

Hi Kevin,

Thanks you for reply.

I will execute RF in Python, so I’ve downloaded jrobotremoteserver standalone source (zip) from https://github.com/ombre42/jrobotremoteserver/releases

It includes jrobotremoteserver and the Remote Library example.

Next I did the following (I know that I did something wrong, so correct me, please):

1.Before including my libraries and jrobotremoteserver   in CLASSPATH I want to run the command 
java org.robotframework.remoteserver.RemoteServer –help
from the dir where RemoteServer.java is. But first, probably, I should compile RemoteServer.java. I am getting multiple errors at compilation related to missing packages

2.Afterwards I will need to include in CLASSPATH libraries and jrobotremoteserver.

Should it be  CLASSPATH= C:\jrobotremoteserver-jrobotremoteserver-standalone-3.0; C:\jrobotremoteserver-jrobotremoteserver-standalone-3.0\examples\AnnotationLibrary ?

3. And then I am not sure how to modify the command 
java org.robotframework.remoteserver.RemoteServer --library org.example.MyLibrary:/ port 8270

Thanks for your patience.

Lev

Kevin O.

unread,
Mar 7, 2016, 3:29:39 PM3/7/16
to robotframework-users
The project is a Maven project. To build it, use Maven. Maven takes care of dependencies.
But you don't need to build the project. If you download the standalone jar file instead of the source, all of the dependencies are included.
Also I would forget the example library for now - its for people already familiar with Maven-based Java projects.

Say you have a simple library like this:

C:\mylibrary]MyLibrary.java

public class MyLibrary {
    public void helloWorld() {
        System.out.println("hello world!");
    }
}

compile it:
javac c:\mylibrary\MyLibrary.java

add the jar and the directory containing your library's class file:
set CLASSPATH=C:\mylibrary\;C:\jrobotremoteserver-3.0-standalone.jar

start the server:
java org.robotframework.remoteserver.RemoteServer --library MyLibrary:/ --port 8270

You should be able to use the library then.

Lev

unread,
Mar 7, 2016, 9:21:03 PM3/7/16
to robotframework-users
It works, thanks Kevin! Remote server is running and, when executing pybot on test case created, it passes.
One question left...

I've created a java program SampleKeywords.java that produces RF keyword:

import org.robotframework.javalib.annotation.ArgumentNames;
import org.robotframework.javalib.annotation.RobotKeyword;
import org.robotframework.javalib.annotation.RobotKeywords;

@RobotKeywords
public class SampleKeywords {

    @RobotKeyword("Print Message")
    @ArgumentNames({"message"})
    public void printMessage(String message) {
        System.out.println(message);
    }
}

And wrote a test case remoteLib.txt:

*** Settings ***
Library    Remote     http://localhost:8270/

*** Test Cases ***
Call Remote Keyword
    Print Message    "Test_XYZ"

Now, When running 'pybot remoteLib.txt', I expect to see a string "Test_XYZ" printed in the terminal. 
But it is not printed... Why?

Here is the output:
C:\myLibrary>pybot remoteLib.txt
==============================================================================
remoteLib
==============================================================================
Call Remote Keyword                                                   | PASS |
------------------------------------------------------------------------------
remoteLib                                                             | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed

On Friday, March 4, 2016 at 4:12:02 PM UTC-5, Lev wrote:

Kevin O.

unread,
Mar 8, 2016, 10:04:42 AM3/8/16
to robotframework-users
I am glad you got it working. Text output to stdout does not appear on the console whether the library is remote or not.
If you look at the log for that execution and expand your Print Message keyword, you should see the output.
For local libraries, they can use the logging api which has a parameter also_console to also log to the console for INFO level events.
This functionality is not available to remote libraries.
To output to the console you could output a warning. Try this:

    Print Message    *WARN* Test_XYZ




Kevin


Lev

unread,
Mar 8, 2016, 7:24:53 PM3/8/16
to robotframework-users
It works for me, string is printed, thanks Kevin. Here is the output:
C:\myLibrary>pybot remoteLib.txt
==============================================================================
remoteLib
==============================================================================
[ WARN ] Test_XYZ
Call Remote Keyword                                                   | PASS |
------------------------------------------------------------------------------
remoteLib                                                             | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed

On Friday, March 4, 2016 at 4:12:02 PM UTC-5, Lev wrote:

Jackie Chen

unread,
Apr 23, 2016, 3:24:27 AM4/23/16
to robotframework-users
Hi Lev & Kevin, 

Thank you for the information. I have few questions.

- Do you have sample code that the remote library exposes keywords from more than 1 java class? 
- How to let it compile java code automatically when i revise class?
- Basing on the above suggestions, how robot execution ends when a test/keyword starts server? Should I write another application to start server separately from the robot test?


Thanks a lot in advance.

Kevin O.

unread,
May 2, 2016, 5:24:43 PM5/2/16
to robotframework-users
The remote library server allows a library to come from one class. If you want to use more than one class, you need a way for methods in different classes to be exposed through one class. The easiest way to do that is with JavalibCore's AnnotationLibrary.
The only way I know of to have to code automatically compile is to use a continuous integration server like Jenkins and check in your changes into a SCM that the CI server is monitoring. Work to setup, but nice once its done.
I'm not sure whether its best to start the remote server inside Robot Framework or not. It would certainly be convenient for RF to start it in a setup, but I have only controlled the server from outside of RF.

I created an example project for developing a remote Java library. It is out of date though and requires changes to work with newer versions of dependencies.

Reply all
Reply to author
Forward
0 new messages