How to implement a java library in Robot Framework

前端 未结 1 1046
轻奢々
轻奢々 2021-01-03 11:27

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.

相关标签:
1条回答
  • 2021-01-03 11:56

    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/

    0 讨论(0)
提交回复
热议问题