Roj*_*oja 0 eclipse robotframework
我的要求是使用RED eclipse编辑器在机器人框架中使用用户定义的java库.当尝试在机器人框架中指定库时,系统会出现错误,因为没有可用的库(显示为库名称的红色下划线).请纠正我的错误.我按照以下步骤,
CLASS PATH已更新至以下罐子,
a)jython.jar b)robotframework-3.0.2.jar c)myOwnJavaLibrary.jar(我在步骤3中创建的jar)d)jdk和jre路径
创建了RED Project并开始初始化关键词,如下所示,
a)图书馆Selenium2Library
b)图书馆org.robot.KCCKeywords.LogonToKCC
这是系统无法读取我自己的库的地方.我还提到了下面的博客并相应地调整了我的步骤.但是没有帮助我.引用多个博客和堆栈也让我感到困惑.最后我在这里.
使用代码中心博客:Robot Framework Tutorial - 以Java编写关键字库作为基础,使用RED的一些特定步骤代替RIDE.本演练将允许您设置Jython,使用Java创建一个简单的库并从Robot脚本运行它.
在Eclipse中安装Eclipse(NEON)和RED Feature之后,在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);
}
}
}
Run Code Online (Sandbox Code Playgroud)
请确保使用Windows Installer安装了Jython .在我的示例中,Jython安装在c:\ Jython中.与常规Python解释器机器人框架一样,仍然需要安装.假设您的计算机可以访问Internet,请在命令行中转到c:\Jython\bin\并运行该命令pip install robotframework.这将在Jython环境中安装Robot Framework.
现在在Eclipse中创建一个新的Robot Framework项目.请确保你有Window > Perspective > Open Perspective > Robot或Other > Robot.
在项目中,默认的Robot Framework是基于Python的,我们需要配置Jython Interpreter.在Eclipse中转到Window > Preferences然后Robot Framework > Installed Frameworks从树菜单中选择.单击Add并指向c:\Jython\bin\.单击"确定".
从Robot Project打开Red.XML并转到general选项卡.这是项目解释器的设置位置.如果它设置为Python(如下例所示),则单击use local settings for this project并检查Jython解释器.将设置保存到文件(CTRL-S).
使用Robot Framework项目设置,是时候将Java类导出到Jar文件.右键单击类文件,然后单击export.然后选择JAR file并单击next.单击Browse并设置JAR文件的位置和文件名.在这种情况下,我选择ExampleLibrary.jar了我的机器人项目的文件夹.按Finish完成导出.
返回Red.XML并单击Referenced Libraries然后继续单击Add Java library,选择导出的Jar文件(ExampleLibrary.jar)并按OK.这将继续加载jar并从Jar文件中读取关键字.保存文件(CTRL-S).这应该得到以下参考.
现在是时候创建一个Robot文件并使用该库.在引用的博客中,给出了以下使用java函数/关键字的示例脚本.
*** Settings ***
Library org.robot.sample.keywords.SampleKeywordLibrary
*** Test Cases ***
ExampleJava
Create An Empty Stack
Add An Element Java
Add An Element C++
Remove Last Element
The Last Element Should Be Java
Run Code Online (Sandbox Code Playgroud)
对于已加载的库,不应出现任何红线,否则右键单击库并单击quick-fix并自动发现库.
然后使用常规的Eclipse/RED Run菜单运行脚本.然后,这将成功运行脚本并输出以下内容:
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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2871 次 |
| 最近记录: |