如何将java类导入到Robot框架之类的库中 [英] How to import java class, to Robot Framework like library
问题描述
我无法理解如何在Robot Framework中导入.jar文件。
以下是代码:
***设置***
图书馆MyLibrary
***测试用例***
我的测试
什么都不做
Hello world
和Java:
public class MyLibrary {
public void hello(String name){
System.out.println(Hello, + name +!);
}
public void doNothing(){
}
}
在.jar中提取后,我输入C:\Python27 \Lib \site-packages \ MyLibrary并创建了空 __ init__.py
文件。在我执行我的Robot文件后: pybot TestJavaLibrary.robot
我得到这个警告:
[WARN]导入的库MyLibrary不包含任何关键字。
============================================== ================================
TestJavaLibrary
========= ================================================== ===================
我的测试|失败|
找不到名称为Do Nothing的关键字。
如何使用这个jar,就像外部库一样?
我还从事过同样的项目,需要通过机器人框架调用Java类。以下是导入Java库的简短示例:
文件: myJavaLibrary.java
public class myJavaLibrary {
public void my_java_add(int i,int j,int k) {
if(i + j == k)
return;
System.out.println(无效总和);
断言错误;
}
}
使用命令:javac myJavaLibrary.java
这将在同一目录中创建一个.class文件:myJavaLibrary.class
在机器人文件中导入:
文件:test.robot.txt
***设置***
库myJavaLibrary.java
***测试用例***
用户定义的Java测试
我的Java添加5 7 12
您可能会注意到myavavaLibrary.java库已添加到设置部分,因为机器人文件与.class文件存在于同一目录中。您可以为其添加绝对路径。
您可能需要安装jython来运行机器人文件。
最后使用命令:
jython -m robot test.robot.txt。
最终输出可以在运行文件夹中的 log.html 文件中看到
对于JAR导入:
在环境变量中包含.jar文件的绝对路径:
变量名称:CLASSPATH
变量值:包含Jar的目录的绝对路径\ *;
在这种情况下,运行机器人文件的过程是相同的,并且不需要包含任何库。
<希望这有效。
参考: http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html
I can't understand how to import .jar file, in Robot Framework.
Here is the code:
*** Settings ***
Library MyLibrary
*** Test Cases ***
My Test
Do Nothing
Hello world
and Java:
public class MyLibrary {
public void hello(String name) {
System.out.println("Hello, " + name + "!");
}
public void doNothing() {
}
}
After Extracting in .jar, I put in C:\Python27\Lib\site-packages\MyLibrary and I created empty __init__.py
file. After I execute my Robot file with: pybot TestJavaLibrary.robot
I get this WARN:
[ WARN ] Imported library 'MyLibrary' contains no keywords.
==============================================================================
TestJavaLibrary
==============================================================================
My Test | FAIL |
No keyword with name 'Do Nothing' found.
How to use this jar, like external library?
I have also worked on the same kind of project which required Java class to be called via robot framework. Here is a short example of importing a Java library:
File : myJavaLibrary.java
public class myJavaLibrary{
public void my_java_add(int i, int j, int k) {
if(i+j == k)
return;
System.out.println("Invalid Sum");
assert false;
}
}
Use command : javac myJavaLibrary.java
This will create a .class file in the same directory : myJavaLibrary.class
Import this in robot file :
File: test.robot.txt
*** Settings ***
Library myJavaLibrary.java
*** Test Cases ***
User defined Java Test
My Java Add 5 7 12
You may notice that library myJavaLibrary.java is added in settings section, since robot file is present in the same directory as .class file. You may add the absolute path for the same.
You may need to install jython for running the robot file.
Finally use the command:
jython -m robot test.robot.txt.
Final output can be seen in log.html file in the run folder
For JAR import:
Include the absolute path to .jar file in your environmental variable:
Variable Name : CLASSPATH
Variable Value: "Absolute path to directory containing Jar"\*;
In this case the process is same for running robot file, and there is no need to include any library.
Hope this works.
Reference: http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html
这篇关于如何将java类导入到Robot框架之类的库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!