【问题标题】:RemoteServer - How to use Java Keyword in Robotframework?RemoteServer - 如何在 Robotframework 中使用 Java 关键字?
【发布时间】:2020-05-09 23:39:00
【问题描述】:

我正在尝试实现 JavaLibCore 以在机器人框架中使用 Java 方法。我按照本教程进行操作:https://blog.codecentric.de/en/2016/01/robot-framework-tutorial-2016-remote-server-keywords-in-java/

RemoteServer 使用的类如下:https://github.com/robotframework/jrobotremoteserver/blob/master/src/main/java/org/robotframework/remoteserver/RemoteServer.java

您能帮我找到解决以下错误的方法吗?非常感谢。

Java

关键字类

package keywords;
import org.robotframework.javalib.annotation.ArgumentNames;
import org.robotframework.javalib.annotation.RobotKeyword;
import org.robotframework.javalib.annotation.RobotKeywords;

@RobotKeywords
public class MyKeyword {

    @RobotKeyword("Print Message")
    @ArgumentNames({"message"})
    public void printMessage(String message) {
        System.out.println("My message is : " + message);
    }

}

主类

import org.robotframework.javalib.library.AnnotationLibrary;
import org.robotframework.remoteserver.RemoteServer;

public class KeywordRemoteLibrary extends AnnotationLibrary {

    public static void main(String[] args) {
        RemoteServer.configureLogging();
        RemoteServer server = new RemoteServer("localhost", 8271);
        server.putLibrary("/keywords", KeywordRemoteLibrary.class);
        try {
            server.start();
        }
        catch(Exception e) {
            e.printStackTrace();
        }
    }

}

控制台

17:11:26.290 [main] INFO  org.eclipse.jetty.util.log - Logging initialized @1006ms to org.robotframework.remoteserver.logging.Jetty2Log4J
17:11:26.361 [main] INFO  org.robotframework.remoteserver.RemoteServer - Mapped path /keywords to library java.lang.Class.
17:11:26.362 [main] INFO  org.robotframework.remoteserver.RemoteServer - Robot Framework remote server starting
17:11:26.364 [main] INFO  org.eclipse.jetty.server.Server - jetty-9.4.25.v20191220; built: 2019-12-20T17:00:00.294Z; git: a9729c7e7f33a459d2616a8f9e9ba8a90f432e95; jvm 11.0.2+9
17:11:26.435 [main] INFO  org.eclipse.jetty.server.handler.ContextHandler - Started o.e.j.s.ServletContextHandler@421bba99{/,null,AVAILABLE}
17:11:26.460 [main] INFO  org.eclipse.jetty.server.AbstractConnector - Started ServerConnector@379614be{HTTP/1.1,[http/1.1]}{127.0.0.1:8271}
17:11:26.461 [main] INFO  org.eclipse.jetty.server.Server - Started @1178ms
17:11:26.461 [main] INFO  org.robotframework.remoteserver.RemoteServer - Robot Framework remote server started on port 0.

机器人框架代码

*** Settings ***
Library    Remote    http://localhost:8271

*** Test Cases ***
First Test Case
    Print Message    test

但是我在 robotsframework 脚本上遇到错误:

http://localhost:8271”位置下的“远程”库未知。无法连接。

【问题讨论】:

  • 您使用的是哪个版本的 org.robotframework.remoteserver?
  • 谢谢,但这似乎是 RED 项目的一个问题,因为服务器已启动,所以它不是 RemoteServer 问题 (github.com/nokia/RED/issues/361)
  • 您能否为您的这个问题写一个答案,以便将来遇到此问题的其他人可以识别它。
  • 我当然会。

标签: java python robotframework


【解决方案1】:

请在下面找到我的解决方案:

public class KeywordRemoteLibrary extends AnnotationLibrary {

static List<String> includePatterns = new ArrayList<String>() {{
    add("keywords/*.class");
}};

public KeywordRemoteLibrary() {
    super(includePatterns);
}

public static void main(String[] args) {
    RemoteServer server = new RemoteServer("127.0.0.1", 8270);
    server.putLibrary("/RPC2", new KeywordRemoteLibrary());
    try {
        server.start();
    }
    catch(Exception e) {
        e.printStackTrace();
    }
}
}

【讨论】:

    【解决方案2】:

    试试这个代码:

    RemoteServer.configureLogging();
    RemoteServer server = new RemoteServer();
    server.putLibrary("/keywords", KeywordRemoteLibrary.class);
    server.setPort(8271);
    server.start();
    

    【讨论】:

      猜你喜欢
      • 2018-01-17
      • 2015-10-10
      • 1970-01-01
      • 2020-09-03
      • 2018-02-04
      • 2020-05-21
      • 2021-06-19
      • 2021-09-18
      • 2015-05-01
      相关资源
      最近更新 更多