fdgenie
fdgenie

Reputation: 61

How to implement a java library in Robot Framework

How can I create a library in Eclipse and then import it in Robot FrameWork?

I am searching a lot now and none of the guides out to help me out.

Upvotes: 5

Views: 9138

Answers (1)

Uri Shtand
Uri Shtand

Reputation: 1737

You need to do the following:

  • Create your java library

  • Add it to the classpath when running robot framework jython edition

Creating your java library:

  • Define a new java class. At this point try not to use a constructor yet (although it is possible to support constructors with fields)

  • Define the ROBOT_LIBRARY_SCOPE static String variable in the class.

    public static final String ROBOT_LIBRARY_SCOPE = "GLOBAL";

  • Define public methods (not static) that will be used as the keywords

Adding your library to the class path

  • Compile your classes - ideally to a jar

  • Add the jar to the class path when running jython. The easiest way to do this is with the MVN Robot Framework plugin. Another option is to wrap the jybot run in a batch file and add CLASSPATH definition to it. There are other options as well (gradle or ant for example).

Using your library in your code

  • You need to import your library using the full package path

    import library org.robot.sample.keywords.MyLibrary

https://blog.codecentric.de/en/2012/06/robot-framework-tutorial-writing-keyword-libraries-in-java/

You can see the full example of how to add a jar when using ride in this article

https://blog.codecentric.de/en/2012/04/robot-framework-tutorial-a-complete-example/

Upvotes: 4

Related Questions