I am having an issue with picking up custom keywords for Java using the Annotation Library . The issue I'm facing is that I am getting the following error when executing with jybot:
Imported library 'org.robotframework.javalib.library.ClassPathLibrary' contains no keywords
Imported library 'org.robotframework.javalib.library.AnnotationLibrary' contains no keywords
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:
*** 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:
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.
public class DemoLibrary extends AnnotationLibrary {
public DemoLibrary () {
super("org/robotframework/example/**/*.class");
}
}
Put your keywords class under package org.robotframework.example.keywords
In example.txt file put only;
Library org.robotframework.example.DemoLibrary
Be sure that you have DemoLibrary at that path.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.