[英]How to add a Java custom library to Robot Framework RIDE
I want to create and import a java custom library into RIDE. 我想创建一个Java自定义库并将其导入RIDE。
Create the Java file based on the below link 根据以下链接创建Java文件
(source for creation of test library : http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#creating-test-libraries ) (用于创建测试库的资源: http : //robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#creating-test-libraries )
Here below is the java Library Code: 以下是Java库代码:
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
创建了JAR文件,并将其放置在路径
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并设置了环境变量
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
打开RIDE,并用关键字
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" 我尝试将Java编译到类文件中,并将其放在“〜\\ 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 万一遇到jython或Jybot的路径问题,请将
jybot.bat
放在路径"C:\\Python27\\Scripts"
文件夹中,然后将jybot.bat
内容更改为绝对值,即
@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. 您必须在运行RIDE之前将库添加到CLASSPATH。 For example:
例如:
set CLASSPATH=%CLASSPATH%;D:\Python27\Lib\site-packages\MyLibrary.jar
ride.py
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.