I figure it out!!
=============env================
**********Sys Window 10
First of all,you need install jdk,jython,robot framework
(PS:jython do not need python2.7 or other python sdk.)
**********For intall
jdk I use a zip.
jython I use a installer jar 2.7.2b3,double click and use install all model.
robot I use master download master code zip, then use "jython setup.py install"
I did not add "CLASSPATH" to Windows System ENV "PATH",I'll say reason later.
I just added D:\Tools\jython2.7\bin To Windows System ENV "PATH".
D:\Tools\jython2.7\bin 的目录
2020/03/01 01:29 <DIR> .
2020/03/01 01:29 <DIR> ..
2020/03/01 01:29 417 chardetect-script.py
2020/03/01 01:29 74,752 chardetect.exe
2020/03/01 01:27 102,772 easy_install-2.7.exe
2020/03/01 01:27 102,772 easy_install.exe
2020/02/02 11:30 3,979,302 jython.exe
2020/02/02 11:30 282 jython_regrtest.bat
2020/03/01 01:28 102,754 pip.exe
2020/03/01 01:28 102,754 pip2.7.exe
2020/03/01 01:28 102,754 pip2.exe
2020/03/01 01:29 428 rebot-script.py
2020/03/01 01:29 74,752 rebot.exe
2020/03/01 01:29 428 robot-script.py
2020/03/01 01:29 74,752 robot.exe
We can find robot.exe,can't find jbot,because it's alread combine to robot at Robot Framework 3.2b2,you can check it from Robot Framework Github for more.
All right,our env is done.
check it!
**********SDK
C:\Users\65787>jython --version
Jython 2.7.2b3
C:\Users\65787>java -version
java version "1.8.0_231"
Java(TM) SE Runtime Environment (build 1.8.0_231-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.231-b11, mixed mode)
C:\Users\65787>robot --version
Robot Framework 3.2b2 (Jython 2.7.2b3 on java1.8.0_231)
**********IDE: eclipse + red editor
1.Download red editor from elipce markplace and install it.
2.configuration robotframework in eclipce perfermance-->robotframework --->installe framework -> dicover (if does not work ,can manual cofig path at D:\Tools\jython2.7\bin)
Lets's slove your problem.
===========prepar a java jar======================
0.prepar a jar or class/java file for robot framework!
this section I use a jar.
1.new a Maven project->robot-utils4j
2.new A HelloWorld class
package org.mfm.robot.utils4j;
public class HelloWorld {
public void hello(String name) {
System.out.println("Hello, " + name + "!");
}
public void doNothing() {
}
}
2.pom.xml
<groupId>org.mfm</groupId>
<artifactId>robot-utils4j</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>assembly</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
3.run mvn clean package
4.get a jar
robot-utils4j-1.0.0-jar-with-dependencies from target directory.
=============run Robot with java jar=================
1.new a Robot project
2.import Library at red.xml
add new library in Refrenceed Library view.
click robot-utils4j-1.0.0-jar-with-dependencies library.
search org.mfm.robot.utils4j.HelloWorld
and click it
Finally ,The result will Like This:
enter image description here
you'd better right click it mark as static libary.
3.new a JavaHello.robot Test Suite
JavaHello.robot
*** Settings ***
Library org.mfm.robot.utils4j.HelloWorld
*** Test Cases ***
My Test
Do Nothing
Hello world
4.run it you will get this result:
Command: jython.exe -J-Dpython.path=D:\Tools\jython2.7\Lib\site-packages -J-cp .;D:\AllWorkspace\lib\robot-utils4j-1.0.0-jar-with-dependencies.jar;D:\AllWorkspace\lib\/*.jar -m robot.run --listener C:\Users\65787\AppData\Local\Temp\RobotTempDir8138272493583159262\TestRunnerAgent.py:14246 --argumentfile C:\Users\65787\AppData\Local\Temp\RobotTempDir8138272493583159262\args_2df9cc70.arg D:\AllWorkspace\EWorkspace4Java\RobotDemo
Suite Executor: Robot Framework 3.2b2 (Jython 2.7.2b3 on java1.8.0_231)
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
==============================================================================
RobotDemo
==============================================================================
RobotDemo.JavaHello
==============================================================================
My Test | PASS |
------------------------------------------------------------------------------
RobotDemo.JavaHello | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================
RobotDemo | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================
Output: D:\AllWorkspace\EWorkspace4Java\RobotDemo\output.xml
Log: D:\AllWorkspace\EWorkspace4Java\RobotDemo\log.html
Report: D:\AllWorkspace\EWorkspace4Java\RobotDemo\report.html
Further more,I use redisson to connect a redis cluster in robot-utils4j-1.0.0-jar-with-dependencies.
1.code
The code of robot-utils4j:
package org.mfm.robot.utils4j;
import org.redisson.Redisson;
import org.redisson.api.RBucket;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
public class RedisClient {
private static RedissonClient instance = null;
/**
* 获取连接redis的Session
* @param clusterNodes "redis://127.0.0.1:7000", "redis://127.0.0.1:7001"
* @param password abc123
* @return
*/
public RedissonClient getRedissonClient(String clusterNodes,String password) {
Config config = new Config();
config.useClusterServers()
.setScanInterval(2000)
.setPassword(password)
.addNodeAddress(clusterNodes.split(","));
if(instance == null) {
instance = Redisson.create(config);
}
return instance;
}
public static void main(String[] args) {
RedisClient redisClient = new RedisClient();
RedissonClient redissonClient = redisClient.getRedissonClient("redis://172.16.2.132:7001, redis://172.16.2.133:7002,redis://172.16.2.134:7003", "keplerredis");
System.out.println(redissonClient+"连接成功。。。。");
}
public String getKey(String key) {
RBucket<String> rvalue = instance.getBucket(key);
System.out.println("获取key"+key+"的值"+rvalue.get());
return rvalue.get();
}
public void setKeyValue(String key,String value) {
RBucket<String> rvalue = instance.getBucket(key);
System.out.println("获取key"+key+"的值"+rvalue.get());
rvalue.set(value);
}
}
2.import Library at red.xml
add new library in Refrenceed Library view.
click robot-utils4j-1.0.0-jar-with-dependencies library.
search org.mfm.robot.utils4j.RedisClient
you'd better right click it mark as static libary.
3.create Robot TestSutie
*** Settings ***
Library org.mfm.robot.utils4j.RedisClient
*** Test Cases ***
My Test
${connectResult}= Get Redisson Client redis://172.16.2.132:7001, redis://172.16.2.133:7002,redis://172.16.2.134:7003 keplerredis
Log To Console ${connectResult}
Run it
==============================================================================
RobotDemo :: python.path
==============================================================================
RobotDemo.RobotDemo
==============================================================================
RobotDemo.RobotDemo.RedisDemoJava
==============================================================================
My Test org.redisson.Redisson@10bdfbcc
| PASS |
------------------------------------------------------------------------------
RobotDemo.RobotDemo.RedisDemoJava | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================
RobotDemo.RobotDemo | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================
RobotDemo :: python.path | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================