|
JavaIntegration
IntroductionStarting 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 JarRunning testsIt 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 librariesDue 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 rebotRebot 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 APICurrently, an API exists only for test execution. User Guide contains an example. Javadocs for individual release are found below: Extending the Robot Framework JarNOTE: 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 DependencyRobot 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>
|
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):
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.
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.
This is now issue 629
AutoItLibrary? can work with the JAR package or not?
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.
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.
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.
I removed the featured tag from JAR download until we figure out why we get these path errors on Windows machines.
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
Now fixed in release 2.5.3.
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 :)?
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):
obot\utils\importing$py.class", line 94, in importExample
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 ?
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.
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.
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.