在RED robot framework eclipse编辑器中指定用户定义的java库时会出错

在RED robot framework eclipse编辑器中指定用户定义的java库时会出错,eclipse,robotframework,Eclipse,Robotframework,我的需求是使用红色eclipse编辑器在robot框架中使用用户定义的java库。尝试在robot框架中指定库时,系统会出现错误,因为没有可用的库(库名称用红色下划线显示)。请纠正我所犯的错误。我遵循了以下步骤 用红色编辑器更新了Eclipse(EclipseNeon(V4.6),红色机器人编辑器v0.7.5) 在同一个eclipse中创建了一个类文件作为项目。(包名:org.robot.kcceywords,类名:LogonToKCC) 将类文件转换为“.JAR”类型,并将其存储在jython

我的需求是使用红色eclipse编辑器在robot框架中使用用户定义的java库。尝试在robot框架中指定库时,系统会出现错误,因为没有可用的库(库名称用红色下划线显示)。请纠正我所犯的错误。我遵循了以下步骤

  • 用红色编辑器更新了Eclipse(EclipseNeon(V4.6),红色机器人编辑器v0.7.5)
  • 在同一个eclipse中创建了一个类文件作为项目。(包名:org.robot.kcceywords,类名:LogonToKCC)
  • 将类文件转换为“.JAR”类型,并将其存储在jython文件夹中(C:\jython2.7.0\Lib\site packages\KCCLibraries)
  • 使用launch4j-3.8-win32将RED与Maven插件集成(使用)
  • 集成了RED与机器人框架和Jython。(使用)
  • 更新了以下JAR的类路径

    a) jython.jar b) robotframework-3.0.2.jar c) myOwnJavaLibrary.jar(我在步骤3中创建的jar) d) jdk和jre路径

  • 也验证了red.xml中的相同类路径
  • 创建红色项目并开始初始化关键字,如下所示

    a) Selenium2图书馆

    b) 图书馆org.robot.kcceywords.LogonToKCC

  • 这里是系统无法读取我自己的库的地方。 我也参考了下面的博客,并相应地调整了我的步骤。但是没有帮助我。提到多个博客和书堆也让我感到困惑。我终于来了


    使用codecentric博客:作为基础,使用一些特定的红色步骤代替骑行。本演练将允许您设置Jython,用Java创建一个简单的库,并从Robot脚本运行它

    在Eclipse中安装Eclipse(NEON)和红色特性之后,在Eclipse中创建一个新的Java项目。完成后,继续创建具有以下内容的新Java类

    package org.robot.sample.keywords;
    
    import java.util.Stack;
    
    /**
     * This is an example for a Keyword Library for the Robot Framework.
     * @author thomas.jaspers
     */
    public class SampleKeywordLibrary {
    
        /** This means the same instance of this class is used throughout
         *  the lifecycle of a Robot Framework test execution.
         */
        public static final String ROBOT_LIBRARY_SCOPE = "GLOBAL";    
    
        //</editor-fold>
        /** The Functionality to be tested */
        private Stack<String> testStack;
    
        /**
         * Keyword-method to create an empty stack.
         */
        public void createAnEmptyStack() {
            testStack = new Stack<String>();
        }
    
    
        /**
         * Keyword-method to add an element to the stack.
         * @param element The element
         */
        public void addAnElement(String element) {
            testStack.push(element);
        }
    
        /**
         * Keyword-method to remove the last element from the stack.
         */
        public void removeLastElement() {
            testStack.pop();
        }
    
        /**
         * Keyword-method to search for an element position.
         * @param element The element
         * @param pos The expected position
         */
        public void elementShouldBeAtPosition(String element, int pos) 
                throws Exception {
            if (testStack.search(element) != pos) {
                throw new Exception("Wrong position: " + testStack.search(element));
            }
        }
    
        /**
         * Keyword-method to check the last element in the stack.
         * @param result Expected resulting element
         */
        public void theLastElementShouldBe(String result) throws Exception {
            String element = testStack.pop();
            if (!result.equals(element)) {
                throw new Exception("Wrong element: " + element);
            }
        }
    }
    
    对于已加载的库,不应显示红线,否则右键单击库并单击“快速修复”,然后自动发现库

    然后使用常规的Eclipse/redrun菜单运行脚本。这将成功运行脚本并输出以下内容:

    Command: C:\jython2.7.0\bin\jython.exe -J-Dpython.path=C:\jython2.7.0\Lib\site-packages -J-cp .;C:\Eclipse\Workspace\ExamplJava\ExampleLibrary.jar -m robot.run --listener C:\Users\User\AppData\Local\Temp\RobotTempDir8926065561484828569\TestRunnerAgent.py:57292:False -s ExamplJava.ExampleJava C:\Eclipse\Workspace\ExamplJava
    Suite Executor: Robot Framework 3.0.2 (Jython 2.7.0 on java1.8.0_60)
    ==============================================================================
    ExamplJava                                                                    
    ==============================================================================
    ExamplJava.ExampleJava                                                        
    ==============================================================================
    ExampleJava                                                           | PASS |
    ------------------------------------------------------------------------------
    ExamplJava.ExampleJava                                                | PASS |
    1 critical test, 1 passed, 0 failed
    1 test total, 1 passed, 0 failed
    ==============================================================================
    ExamplJava                                                            | PASS |
    1 critical test, 1 passed, 0 failed
    1 test total, 1 passed, 0 failed
    ==============================================================================
    Output:  C:\Eclipse\Workspace\ExamplJava\output.xml
    Log:     C:\Eclipse\Workspace\ExamplJava\log.html
    Report:  C:\Eclipse\Workspace\ExamplJava\report.html
    

    使用codecentricblog:作为基础,使用RED代替RIDE的一些特定步骤。本演练将允许您设置Jython,用Java创建一个简单的库,并从Robot脚本运行它

    在Eclipse中安装Eclipse(NEON)和红色特性之后,在Eclipse中创建一个新的Java项目。完成后,继续创建具有以下内容的新Java类

    package org.robot.sample.keywords;
    
    import java.util.Stack;
    
    /**
     * This is an example for a Keyword Library for the Robot Framework.
     * @author thomas.jaspers
     */
    public class SampleKeywordLibrary {
    
        /** This means the same instance of this class is used throughout
         *  the lifecycle of a Robot Framework test execution.
         */
        public static final String ROBOT_LIBRARY_SCOPE = "GLOBAL";    
    
        //</editor-fold>
        /** The Functionality to be tested */
        private Stack<String> testStack;
    
        /**
         * Keyword-method to create an empty stack.
         */
        public void createAnEmptyStack() {
            testStack = new Stack<String>();
        }
    
    
        /**
         * Keyword-method to add an element to the stack.
         * @param element The element
         */
        public void addAnElement(String element) {
            testStack.push(element);
        }
    
        /**
         * Keyword-method to remove the last element from the stack.
         */
        public void removeLastElement() {
            testStack.pop();
        }
    
        /**
         * Keyword-method to search for an element position.
         * @param element The element
         * @param pos The expected position
         */
        public void elementShouldBeAtPosition(String element, int pos) 
                throws Exception {
            if (testStack.search(element) != pos) {
                throw new Exception("Wrong position: " + testStack.search(element));
            }
        }
    
        /**
         * Keyword-method to check the last element in the stack.
         * @param result Expected resulting element
         */
        public void theLastElementShouldBe(String result) throws Exception {
            String element = testStack.pop();
            if (!result.equals(element)) {
                throw new Exception("Wrong element: " + element);
            }
        }
    }
    
    对于已加载的库,不应显示红线,否则右键单击库并单击“快速修复”,然后自动发现库

    然后使用常规的Eclipse/redrun菜单运行脚本。这将成功运行脚本并输出以下内容:

    Command: C:\jython2.7.0\bin\jython.exe -J-Dpython.path=C:\jython2.7.0\Lib\site-packages -J-cp .;C:\Eclipse\Workspace\ExamplJava\ExampleLibrary.jar -m robot.run --listener C:\Users\User\AppData\Local\Temp\RobotTempDir8926065561484828569\TestRunnerAgent.py:57292:False -s ExamplJava.ExampleJava C:\Eclipse\Workspace\ExamplJava
    Suite Executor: Robot Framework 3.0.2 (Jython 2.7.0 on java1.8.0_60)
    ==============================================================================
    ExamplJava                                                                    
    ==============================================================================
    ExamplJava.ExampleJava                                                        
    ==============================================================================
    ExampleJava                                                           | PASS |
    ------------------------------------------------------------------------------
    ExamplJava.ExampleJava                                                | PASS |
    1 critical test, 1 passed, 0 failed
    1 test total, 1 passed, 0 failed
    ==============================================================================
    ExamplJava                                                            | PASS |
    1 critical test, 1 passed, 0 failed
    1 test total, 1 passed, 0 failed
    ==============================================================================
    Output:  C:\Eclipse\Workspace\ExamplJava\output.xml
    Log:     C:\Eclipse\Workspace\ExamplJava\log.html
    Report:  C:\Eclipse\Workspace\ExamplJava\report.html
    

    最后,我跟随下面的内容,开始了一次机器人框架的伟大旅程

    1   Installed Java, Eclipse, RED Eclipse plugin.
       a) Java(JDK 1.8.0/JRE 1.8.0)
       b) Eclipse Neon (v 4.6)
       c) RED - Robot Eclipse Editor v0.7.5.2(Eclipse Plugin)
    2   Downloaded and Installed Python 2.7.12 using windows. A folder created automatically after installation in C:\python27
    3   "Installed Robot Framework using pip command in Command Prompt.
         Command:     C:\python27\scripts>pip install robotframework"
    4   Downloaded and installed Jython 2.7.0 using windows. A folder created automatically after installation in C:\jython2.7.0
    5   "Installed Robot Framework using pip command in Command Prompt.
         Command:     C:\jython2.7.0\bin>pip install robotframework"
    6   "Installed Selenium2Library using pip command in Command Prompt.
         Command:     C:\jython2.7.0\bin>pip install robotframework-selenium2library"
    7   "Set the below,
        a) Goto Window-Preferences-Robot Framework-Installed Framework
        b) Map Robot framework with Jython Interpreter
        I used c:\jython2.7.0\bin"
    8   Created JavaProject and export it into a jar file. Right click on the class name, click on export-Java-Jarfile. Select the path name where the new jar file to be put including the new file name.jar. Click Ok.
    9   Open RED.xml Click Add Java Library and select the newly created jar file.
    10  "Set up this before proceeding with robot framework 
        goto Windows - Perspective - Open Perspective-Other-Robot"
    11  Create a robot suite, import library selenium2library & user defined library, Write Test cases.
    

    最后,我跟随下面的内容,开始了一次机器人框架的伟大旅程

    1   Installed Java, Eclipse, RED Eclipse plugin.
       a) Java(JDK 1.8.0/JRE 1.8.0)
       b) Eclipse Neon (v 4.6)
       c) RED - Robot Eclipse Editor v0.7.5.2(Eclipse Plugin)
    2   Downloaded and Installed Python 2.7.12 using windows. A folder created automatically after installation in C:\python27
    3   "Installed Robot Framework using pip command in Command Prompt.
         Command:     C:\python27\scripts>pip install robotframework"
    4   Downloaded and installed Jython 2.7.0 using windows. A folder created automatically after installation in C:\jython2.7.0
    5   "Installed Robot Framework using pip command in Command Prompt.
         Command:     C:\jython2.7.0\bin>pip install robotframework"
    6   "Installed Selenium2Library using pip command in Command Prompt.
         Command:     C:\jython2.7.0\bin>pip install robotframework-selenium2library"
    7   "Set the below,
        a) Goto Window-Preferences-Robot Framework-Installed Framework
        b) Map Robot framework with Jython Interpreter
        I used c:\jython2.7.0\bin"
    8   Created JavaProject and export it into a jar file. Right click on the class name, click on export-Java-Jarfile. Select the path name where the new jar file to be put including the new file name.jar. Click Ok.
    9   Open RED.xml Click Add Java Library and select the newly created jar file.
    10  "Set up this before proceeding with robot framework 
        goto Windows - Perspective - Open Perspective-Other-Robot"
    11  Create a robot suite, import library selenium2library & user defined library, Write Test cases.
    

    非常感谢Kootstra!这起作用了。我现在能够成功地添加库,没有任何红线。我犯的错误是将myOwnLibrary.jar添加到类路径中,而不是将其放在“AddJavaLibrary”选项中。我破坏了我所有的设置,只是按照你的步骤,使我成功地集成。谢谢但不幸的是,我无法执行它。它的错误如下,未知选项:J-Dpython.path=C:\jython2.7.0\Lib\site包用法:jython[option]。。。[-c cmd |-m mod | file |-][arg]。。。有关详细信息,请尝试“jython-h”。我还使用错误中指定路径的环境变量进行了验证。还有什么原因呢?该示例适用于Jython安装。如果您遵循这些步骤,那么您将能够运行java代码。但是,如果使用Launch4j生成的jython.exe,将生成收到的错误。这似乎是一个特定于红色的问题,因为它会生成
    命令:C:\Launch\jython.exe-J-cp。;C:\Eclipse\Jython\ExampleLibrary.jar。。。套件执行者:Robot Framework 3.0.2(java1.8.0_71上的Jython 2.7.0)未知选项:J-cp
    我将用红色提出一个问题,因为Launch4J生成的exe文件不支持
    -J-cp
    参数。我遵循了今天为Jython集成设置的上述步骤,早些时候我集成了lauch4j,似乎是这两个都被设置好了。现在,我已经完全清除了lauch4j,并试图按照上述步骤继续进行。在Eclipse编辑器中,现在无法识别Selenium2库及其关键字。它以红线显示。通过从python文件夹复制Selenium2库重新尝试,但这对我没有帮助。我现在该怎么做才能让它被认可呢?我终于做到了。这都是因为你的宝贵回应。谢谢。我卸载了与robot框架的测试自动化相关的所有区域,并使用您的对话遵循了步骤。成功了。下面是我所做的一个简单介绍。非常感谢Kootstra!这起作用了。我现在能够成功地添加库,没有任何红线。我犯的错误是将myOwnLibrary.jar添加到类路径中,而不是将其放在“AddJavaLibrary”选项中。我破坏了我所有的设置,只是按照你的步骤,使我成功地集成。谢谢但不幸的是,我无法执行它。它的错误如下,未知选项:J-Dpython.path=C:\jython2.7.0\Lib\site包用法:jython[option]。。。[-c cmd |-m mod | file |-][arg]。。。有关详细信息,请尝试“jython-h”。我还使用错误中指定路径的环境变量进行了验证。还有什么原因呢?该示例适用于Jython安装。如果您遵循这些步骤,那么您将能够运行java代码。霍维夫