【问题标题】:Robot Framework Adding Keywords机器人框架添加关键字
【发布时间】:2015-10-14 10:00:45
【问题描述】:

我在使用Annotation Library 为 Java 挑选自定义关键字时遇到问题。我面临的问题是使用 jybot 执行时出现以下错误:

导入的库 'org.robotframework.javalib.library.ClassPathLibrary' 不包含关键字

导入的库 'org.robotframework.javalib.library.AnnotationLibrary' 不包含关键字

找不到名为“创建空堆栈”的关键字 使用的 Jybot 命令:jybot example.txt。下面是实际的测试用例和为此测试用例调用的库:

*** Settings ***
Library    org.robotframework.javalib.library.ClassPathLibrary     org/robotframework/example/keyword/**.class
Library    org.robotframework.javalib.library.AnnotationLibrary    org/robotframework/example/keyword/**.class


*** Test Cases ***

Stack Example
      Create an Empty Stack
      Add an Element Java
      Add an Element C++
      Remove last Element
      The last Element should be

以下是为合并关键字而编写的库:

package org.robotframework.example.keyword;

import org.robotframework.javalib.annotation.RobotKeyword;
import org.robotframework.javalib.annotation.RobotKeywords;
import org.robotframework.javalib.library.AnnotationLibrary;

/**
 * 
 */

    /**
     * 
     */
    @RobotKeywords

    public class StackKeyword extends AnnotationLibrary {
        /** 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";

        public StackKeyword() {
            super("org/robotframework/example/keyword/**/*.class");
        }
        //</editor-fold>
        /** The Functionality to be tested */
        private java.util.Stack<String> testStack;

        /**
         * Keyword-method to create an empty stack.
         */
        @RobotKeyword
        public void createAnEmptyStack() {
            testStack = new java.util.Stack<String>();
        }


        /**
         * Keyword-method to add an element to the stack.
         * @param element The element
         */
        @RobotKeyword
        public void addAnElement(String element) {
            testStack.push(element);
        }

        /**
         * Keyword-method to remove the last element from the stack.
         */
        @RobotKeyword
        public void removeLastElement() {
            testStack.pop();
        }

        /**
         * Keyword-method to search for an element position.
         * @param element The element
         * @param pos The expected position
         */
        @RobotKeyword
        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
         */
        @RobotKeyword
        public void theLastElementShouldBe(String result) throws Exception {
            String element = testStack.pop();
            if (!result.equals(element)) {
                throw new Exception("Wrong element: " + element);
            }
        }



    }

【问题讨论】:

    标签: java python annotations keyword robotframework


    【解决方案1】:

    添加一个类扩展AnnotationLibrary并实现默认构造函数。

    public class DemoLibrary extends AnnotationLibrary {
    
        public DemoLibrary () {
            super("org/robotframework/example/**/*.class");
        }
    }
    

    把你的关键字类放在包org.robotframework.example.keywords

    仅放在example.txt文件中;

    Library           org.robotframework.example.DemoLibrary
    

    确保您在该路径上有 DemoLibrary。

    【讨论】:

      猜你喜欢
      • 2013-11-08
      • 2019-06-11
      • 2017-12-19
      • 2021-08-15
      • 2015-11-07
      • 2018-02-25
      • 2020-11-06
      • 2016-01-03
      • 2015-07-31
      相关资源
      最近更新 更多