简体   繁体   中英

How to add a Java custom library to Robot Framework RIDE

I want to create and import a java custom library into RIDE.

Create the Java file based on the below link
(source for creation of test library : http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#creating-test-libraries )

Here below is the java Library Code:

public class MyLibrary{

    public static final String ROBOT_LIBRARY_SCOPE = "GLOBAL";
    public static final String ROBOT_LIBRARY_VERSION = "1.0";
    public static final String ROBOT_LIBRARY_DOC_FORMAT = "HTML";

    private int counter = 0;

    public void count() {
        counter += 1;
        System.out.println(counter);
    }

    public void clearCounter() {
        counter = 0;
    }    
}

Created the JAR file and placed in the path D:\\Python27\\Lib\\site-packages

Installed the Jython and set the environment vairables, JYTHON_HOME=D:\\jython2.7.0; JYTHONPATH = D:\\jython2.7.0\\bin JYTHON_HOME=D:\\jython2.7.0; JYTHONPATH = D:\\jython2.7.0\\bin

Open RIDE and attached the library with the keyword Library MyLibrary

It displayed the text in red. (Meaning it is not a recognized library).

I tried compiling the java into class file and placing it under "~\\jython2.7rc1\\Lib\\site-packages\\MyLibrary.class"

When I run the below test it worked perfectly for me:

*** Settings ***
Library     MyLibrary

*** Test Cases ***
sample
   count 

Just in case you face issues with path of jython or Jybot, place jybot.bat in the path "C:\\Python27\\Scripts" folder and change the jybot.bat content to absolute value ie

@echo off 
C:\jython2.7.0\bin\jython "C:\Python27\Lib\site-packages\robot\run.py" %*

This will resolve the path issues if any!

You must add your library to CLASSPATH before running RIDE. For example:

set CLASSPATH=%CLASSPATH%;D:\Python27\Lib\site-packages\MyLibrary.jar
ride.py

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM