java中frame的导入,如何将java类导入到Robot框架之类的库中

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值