My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
JavaIntegration  
Describes various ways to use Robot Framework from and with Java and such things.
Featured
en, ja
Updated Mar 16, 2011 by janne.t.harkonen@gmail.com

Introduction

Starting from Robot Framework 2.5.2, RF is distributed also as a jar file. This jar file allows execution of Robot Framework without having Python installed, but it also contains a programmatic entry point for using RF within Java code.

The latest jar distribution is available from the download page.

Using the Robot Framework Jar

Running tests

It is possible to execute tests using the jar file with command like these:

  java -jar robotframework-2.5.3.jar --help
  java -jar robotframework-2.5.3.jar mytests.txt
  java -jar robotframework-2.5.3.jar --variable name:value mytests.txt

Using additional Java libraries

Due to the fact that java -jar does not read CLASSPATH environment variable, or offer any other way to alter the class path at startup, Robot Framework has to be started a bit differently when class path has to be altered.

For example, here's how the SwingLibrary demo can be executed using the Robot Framework jar:

java -cp lib/swinglibrary-0.14.jar:lib/registration-0.1.jar:robotframework-2.5.3.jar org.robotframework.RobotFramework example.html

It is also possible to insert additional jar files to class path using the Xbootclasspath option. In this case, robotframework.jar does not need to be in class path.

Here's the above example using Xbootclasspath:

java -Xbootclasspath/a:lib/swinglibrary-0.14.jar:lib/registration-0.1.jar -jar  robotframework-2.5.3.jar  example.html 

Using rebot

Rebot can be used like this:

  java -jar robotframework-2.5.3.jar rebot --help
  java -jar robotframework-2.5.3.jar rebot output.xml
  java -jar robotframework-2.5.3.jar rebot --name Combined outputs/*.xml

Using the Programmatic API

Currently, an API exists only for test execution. User Guide contains an example.

Javadocs for individual release are found below:

Extending the Robot Framework Jar

NOTE: robotframework-2.5.3.jar contains (accidentally) two MANIFEST.MF files, which causes jar command to fail. robotframework-2.5.3.jar can be extended using zip command.

Adding additional test libraries or support code to the Robot Framework jar is quite starightforward using the jar command distributed with JDK. Python code must be placed in Lib directory inside the jar and Java code can be placed directly to the root of the jar, according to package structure.

For example, to add Python package mytestlib to the jar, first copy the mytestlib directory under a directory called Lib, then run command:

jar uf /path/to/robotframework-2.5.4.jar Lib

in the directory where Lib is located.

To add compiled java classes to the jar, you must have a directory structure corresponding to the Java package structure and add that recursively to the zip.

For example, to add class MyLib.class, in package org.test, the file must be in org/test/MyLib.class and you can execute:

jar uf /path/to/robotframework-2.5.4.jar org

Robot Framework as Maven Dependency

Robot Framework jar is also available in the Maven central repository, and you can add it as a dependency with the following snippet:

    <dependency>
        <groupId>org.robotframework</groupId>
        <artifactId>robotframework</artifactId>
        <version>2.5.3</version>
    </dependency>
Comment by jeffny...@gmail.com, Aug 28, 2010

For what it's worth, there may be a problem with this running on Windows. When I try it on Linux (Ubuntu 10.4), it works fine. But when I try to run the following command on Windows 7:

java -jar robotframework-2.5.2.jar --help

I get the following error:

Exception in thread "main" Traceback (most recent call last):

File "<string>", line 1, in <module> File "C:\Crypto\AppDev?\Lattice\robotframework-2.5.2.jar\Lib\robot\init$py.class", line 23, in <module> File "C:\Crypto\AppDev?\Lattice\robotframework-2.5.2.jar\Lib\robot\output\init$py.class", line 16, in <module> File "C:\Crypto\AppDev?\Lattice\robotframework-2.5.2.jar\Lib\robot\output\output$py.class", line 18, in <module> File "C:\Crypto\AppDev?\Lattice\robotframework-2.5.2.jar\Lib\robot\common\init$py.class", line 16, in <module> File "C:\Crypto\AppDev?\Lattice\robotframework-2.5.2.jar\Lib\robot\common\model$py.class", line 15, in <module> File "c:\python26\lib\random.py", line 43, in <module>
from warnings import warn as warn
File "c:\python26\lib\warnings.py", line 394, in <module>
bytes_warning = sys.flags.bytes_warning
AttributeError?: 'systemstate' object has no attribute 'flags'

I do have a PYTHONPATH environment variable set that is pointing to my Lib directory within my Python installation directory. I'm not sure if I need to add anything else to it. Again, this definitely works on Ubuntu. I'm using Python 2.6.5 on both Ubuntu and Windows.

Comment by project member jussi.ao...@gmail.com, Aug 28, 2010

Interesting. Thank you for the report!

It seems that the robot imports the random.py from your local python 2.6 installation instead of from inside the JAR package, where the correct version for jython is.

If you remove the PYTHONPATH environment variable, you most likely can then run the jar also on Windows.

I will take a closer look at this at the beginning of next week.

Comment by project member jussi.ao...@gmail.com, Aug 28, 2010

This is now  issue 629 

Comment by zhizhong...@gmail.com, Aug 29, 2010

AutoItLibrary? can work with the JAR package or not?

Comment by katiyar....@gmail.com, Aug 29, 2010

haven't had time to use it (getting the same error as jeffnyman on WIN)

Does jar include Selenium Library too? or just the RF ?

Point of asking is, If we want to run a Test Suite from a Machine where RF is not present, this JAR will be a great help if it can include selenium as well. we will have completely independent scripts that can run from any m/c having java.

Comment by project member pekka.klarck, Aug 30, 2010

zhizhong.huang, my understanding is that AutoItLibrary? doesn't run on Jython so using it with the JAR distribution isn't possible. There has recently been promising work in the Jython project to support running C based Python modules so at least theoretically adding Jython support to the AutoItLibrary? is possible. You may want to start a discussion about that on the robotframework-users mailing list or submit an enhancement request to AutoItLibrary?'s tracker.

Comment by project member pekka.klarck, Aug 30, 2010

katiyar.prashant1, the JAR contains only Jython and Robot Framework itself. Bundling SeleniumLibrary? into it is an interesting idea and would definitely ease installation especially if that's the only external library you need. There are some problems with this approach, though:

1) SeleniumLibrary? contains selenium-server.jar and including that into the RF JAR distribution would nearly double the already big package size. Would it be OK to download the server JAR separately?

2) If we bundle external libraries to the RF JAR, we need to create new package every time when new RF or library releases are done. This creates some extra work especially if we wanted to bundle also other libs than the SeleniumLibrary?. That would ease installation so much that the extra work could be worth it, though.

An alternative idea is creating separate SeleniumLibrary?.jar package that can be used with robotframework.jar. This package could contain both the Selenium Server and the Python code of the library.

Comment by project member jussi.ao...@gmail.com, Aug 30, 2010

I removed the featured tag from JAR download until we figure out why we get these path errors on Windows machines.

Comment by project member jussi.ao...@gmail.com, Aug 30, 2010

Okay, we found the problem. Path names inside JAR-files are case sensitive in Windows and this caused problems.

This will be fixed as soon as possible, hopefully already tomorrow.

More details and further discussion in  issue 629 

Comment by project member jussi.ao...@gmail.com, Aug 31, 2010

Now fixed in release 2.5.3.

Comment by katiyar....@gmail.com, Sep 1, 2010

pekka,

I understand the size limitation for bundling the jar(already 10 MB).. instead of creating new package every time RF is released. I think alternate approach is a better idea.

Having a SeleniumLibrary?.Jar package that include Sever jar and pyhon code of library and make it work with robotframework.jar

How much effort are we looking at for this approach ?

I wish i could be some help there. i can test whether jar is working perfectly fine :)?

Comment by oted...@gmail.com, Sep 9, 2010

I'm unable to run tests on windows using the jar file. Running the SwingLibrary? demo as specified with the command: java -Xbootclasspath/a:lib/swinglibrary-0.14.jar:lib/registration-0.1.jar -jar robotframework-2.5.3.jar example.html

Generates the following error(s):

ERROR Invalid syntax in file 'c:\oj\robotframework\swinglibrary-example\exam ple.html' in table 'Setting': Importing test library 'SwingLibrary?' failed: Impo rtError: No module named SwingLibrary? PYTHONPATH: ['C:\\OJ\\RobotFramework?\\swinglibrary-example\\robotframework-2.5.3 .jar\\Lib\\robot\\libraries', 'C:\\OJ\\RobotFramework?\\swinglibrary-example\\Lib ', 'C:\\OJ\\RobotFramework?\\swinglibrary-example\\robotframework-2.5.3.jar\\Lib' , 'classpath', 'pyclasspath/', '.'] CLASSPATH: robotframework-2.5.3.jar Traceback (most recent call last):

File "C:\OJ\RobotFramework?\swinglibrary-example\robotframework-2.5.3.jar\Lib\r
obot\utils\importing$py.class", line 94, in import

Example

Data Is Registered Correctly | FAIL | Setup of the parent suite failed.


Example | FAIL | Suite setup failed: No keyword with name 'Start Application' found.

1 critical test, 0 passed, 1 failed 1 test total, 0 passed, 1 failed

Any Ideas ?

Comment by project member pekka.klarck, Sep 9, 2010

katiyar.prashant1, I submitted an issue to SeleniumLibrary?'s tracker about the standalone JAR. I'm not sure what's the best approach to create it nor when it will be implemented. Here's the issue: http://code.google.com/p/robotframework-seleniumlibrary/issues/detail?id=132

otednes, you probably need to use ';' (and not ':') as the classpath separator and possibly also '\' (and not '/') as the path separator on Windows.

Comment by oted...@gmail.com, Sep 9, 2010
pekka.klarck, I allready used '\' (forgot changing when pasting from this page), BUT I hadn't tried with ';' instead of ':' as stated in the excample. Now It works. Thank you !
Comment by teodes...@gmail.com, Sep 13, 2010
Using additional Java libraries Due to the fact that java -jar does not read CLASSPATH environment variable, or offer any other way to alter the class path at startup, other Java libraries need to be inserted to the class path using the Xbootclasspath option.

For example, here's how the SwingLibrary? demo can be executed using the Robot Framework jar:

java -Xbootclasspath/a:lib/swinglibrary-0.14.jar:lib/registration-0.1.jar -jar robotframework-2.5.3.jar example.html

Why not just put robotframework.jar in the classpath, and then invoke org.robotframework.RobotFramework???

java -cp lib/swinglibrary-0.14.jar:lib/registration-0.1.jar -jar:robotframework-2.5.3.jar org.robotframework.RobotFramework?? example.html

Helps those of us who have enormous CLASSPATHs set via env var.

Comment by project member pekka.klarck, Sep 22, 2010

teodesian, thanks for pointing it out that you can also invoke org.robotframework.RobotFramework. That definitely is a good idea if you have a big CLASSPAT. This should be mentioned also in the actual documentation.


Sign in to add a comment
Powered by Google Project Hosting