首页 > 编程问答 >机器人框架添加关键字

机器人框架添加关键字

时间:2024-07-23 12:32:01浏览次数:19  
标签:python java robotframework

我在使用 注释库 为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

下面是为合并关键字而编写的库,为合并 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);
            }
        }



    }

你的问题在于,你在 Robot Framework 测试文件中导入了 StackKeyword 类本身,而 AnnotationLibrary 需要导入的是包含已注释关键字的

修改你的 Robot Framework 测试文件,像这样导入库:

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

注意,我们在第二个 Library 导入中使用了 org.robotframework.example.keyword ,而不是 org.robotframework.example.keyword.StackKeyword 。这会告诉 AnnotationLibrary org.robotframework.example.keyword 包中查找已注释的关键字,它会在 StackKeyword 类中找到它们。

进行此更改后,你的关键字应该可以被 Robot Framework 识别,并且测试应该能够运行而不会出现错误。

标签:python,java,robotframework
From: 31598517

相关文章

  • java学习day01
    一.java安装1.1安装java1.81.2java内创建文件夹jdk和jre分别安装java的jdk和jre1.3环境变量JAVA_HOMEE:\work\java\jdk(自己电脑的文件位置)CLASSPATH.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar;Path内增加%JAVA_HOME%\bin(上移到最上方)二.java2.1......
  • java学习day02
    一.数据类型1.1本质数据存储形式,存储空间大小1.2存储整数存储:1.3分类基本数据类型数值型整型byte字节8bit-128~127short短整型16bit-32768~32767int整型32bit-2,147,483,648~2,147,483,647long长整型64bit浮点型float单浮点32bitdouble双浮......
  • 三种语言实现快速选择(C++/Python/Java)
    题目给定一个长度为......
  • 【前端】JavaScript入门及实战91-95
    文章目录91DOM92事件93文档的加载94DOM查询(1)95图片切换的练习91DOM<!DOCTYPEhtml><html><head><title></title><metacharset="utf-8"><style></style></head><body> <buttonid="btn&quo......
  • 【前端】JavaScript入门及实战86-90
    文章目录86正则表达式87字符串和正则相关的方法88正则表达式语法(1)89正则表达式语法(2)90邮件的正则86正则表达式<!DOCTYPEhtml><html><head><title></title><metacharset="utf-8"><scripttype="text/javascript"> /* 使用字面量来创建正......
  • 【前端】JavaScript入门及实战96-100
    文章目录96DOM查询(2)97DOM查询(3)98全选练习(1)99全选练习(2)100全选练习(3)96DOM查询(2)<!DOCTYPEhtml><html><head><title></title><metacharset="utf-8"> <scripttype="text/javascript"> window.onload=......
  • 如何让SublimeText支持Python 3的注释?
    我测试了SublimeText2和3,两者都有错误:如果您测试此代码,您会注意到:之后的所有代码都不会正确突出显示语法。deffoo(a,b)->str:#Nothinggetsproperlycoloredfromhere#Abunchofcode…return"bar"我发现了一些链接,解释了如何......
  • 如何用可变长度注释Python列表
    如何为可变长度或None的Python列表编写注释?当我这样写时,它会返回一个错误。defsome_function(params:list[str,...])#thisgiveserror:`TypeError:'type'objectisnotsubscriptable`defsome_function(params:List[str,...])#thisalsogiveserro......
  • Python 协议和 Django 模型
    假设我有一个简单的协议A和一个未能实现该协议的类B:fromtypingimportProtocolclassA(Protocol):deffoo(self)->str:...classB:pass当下面的代码进行类型检查时,Mypy将正确地抱怨x:A=B()mypy.error:Incompatibletypes......
  • IDEA解决java注释顶格、xml注释右对齐+无空格问题
    先配置java中注释格式: 然后是配置xml中的注释格式:还是CodeStyle,从java往下滑动到xml......