简体   繁体   English

机器人框架添加关键字

[英]Robot Framework Adding Keywords

I am having an issue with picking up custom keywords for Java using the Annotation Library . 使用Annotation库为Java选择自定义关键字时遇到问题。 The issue I'm facing is that I am getting the following error when executing with jybot: 我面临的问题是,使用jybot执行时遇到以下错误:

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

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

No keyword with name 'Create an Empty Stack' found Jybot command used: jybot example.txt.Below is the actual test case and the libraries that are called for this test case: 未找到名称为“ Create a Empty Stack”的关键字,使用了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

Below is the library written to incorporate the keyword written to incorporate the Stack keywords: 以下是编写为包含关键字而编写的库,该关键字是为包含Stack关键字而编写的:

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);
            }
        }



    }

Add a class extends AnnotationLibrary and implement default constructor. 添加一个扩展AnnotationLibrary的类并实现默认构造函数。

public class DemoLibrary extends AnnotationLibrary {

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

Put your keywords class under package org.robotframework.example.keywords 将您的关键字类放在org.robotframework.example.keywordsorg.robotframework.example.keywords

In example.txt file put only; 在example.txt文件中仅放入;

Library           org.robotframework.example.DemoLibrary

Be sure that you have DemoLibrary at that path. 确保在该路径上有DemoLibrary。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Jython 在 Robot Framework 中使用自定义 Java 关键字/库 - Using custom Java keywords/library in Robot Framework using Jython 如何通过Java实现的关键字停止在Robot Framework中执行测试? - How to stop test execution in Robot Framework through keywords implemented with Java? Robot Framework - 向某些文本添加时间戳值 - Robot Framework - Adding Timestamp value to some text Java关键字的Java机器人框架:Selenium.open(..)以隐藏模式打开Firefox浏览器 - robot framework with java keywords : Selenium.open(..) opens Firefox browser in hidden mode 机器人框架:如何获取 selenium webdriver 的当前实例来编写自己的关键字? - Robot framework: how can I get current instance of selenium webdriver to write my own keywords? 如何使用 Annotation Library 访问我的 java 代码中的机器人框架关键字和变量? - How to use Annotation Library to access robot framework keywords and variables in my java code? Java机器人框架(Hi-Fi库):我可以使用String关键字吗? - Robot Framework with Java (Hi-Fi library): can I use String keywords? 机器人框架中的搜索上下文 - Search context in robot framework 关于在IntelliJ中执行机器人框架的.robot文件 - Regarding execution of .robot files for robot framework in IntelliJ 两次执行机器人框架测试套件 - Execute robot framework testsuite twice
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM