5

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.

luator
  • 4,769
  • 3
  • 30
  • 51
fdgenie
  • 61
  • 1
  • 6
  • what exactly have you tried so far and where is it that you are hitting snags in understanding? – Chris Jul 21 '15 at 12:23
  • So far i tried Java libcore , Remote Server and this guide: https://blog.codecentric.de/en/2012/06/robot-framework-tutorial-writing-keyword-libraries-in-java/ I think my problem is in setting the right classpath but i am not sure. – fdgenie Jul 21 '15 at 12:25

1 Answers1

4

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/

Uri Shtand
  • 1,717
  • 11
  • 14
  • So, i created a new library. When you say "Compile your classes - ideally to a jar" you mean export the class in .jar? If yes then i did that. Unfortunately i cant work with MVN Robot Framework plugin because i need to work with RIDE. Can you explain the second option with the Jybot run in a batch file and add CLASSPATH definition to it? Sorry but i am really noob. Thanks for your answer – fdgenie Jul 23 '15 at 10:45
  • Why do you need to work with RIDE? RIDE is mainly for python robot framework... Installation and usage for jython with RIDE is extremely hard. Instead - if you do java, use intelliJ or Eclipse with Robot plugins – Uri Shtand Jul 26 '15 at 11:09
  • My boss told me i need to work with RIDE and not Eclipse :/ So, you think what i am asking cant happen or its too hard too happen? – fdgenie Jul 27 '15 at 06:23
  • Edited the answer. Added link to an example that uses ride with jython and jar libraries. Just follow it. – Uri Shtand Jul 28 '15 at 08:35
  • Is there any way to use a Java library without Jython? I know that some RF libraries have issue w/ Jython so I would like to avoid it. Is it possible? – Wlad Aug 13 '20 at 18:14