简体   繁体   English

如何使用Robot框架为用Java编写的类运行测试用例?

[英]How do I run test cases for a class written in Java, using Robot framework?

I am trying to learn how to use Robot Framework. 我正在尝试学习如何使用机器人框架。 I created simple Java project, using Eclipse. 我使用Eclipse创建了一个简单的Java项目。 It contains one package - test and in this package there is only one class - MyKeywords . 它包含一个封装- test在这个包只有一个类- MyKeywords Here is the class content: 这是课程内容:

package test;

public class MyKeywords {

    public String sayHi(String name)
    {
            return "Hello " +name ;
    }

    public String sayHi()
    {
            return "Hello World!";
    }

    public String typeOf(Object param)
    {
            return param.getClass().getSimpleName();
    }
} 

Then I created simple .txt file, whic is supposed to contain the test cases. 然后,我创建了一个简单的.txt文件,其中应该包含测试用例。 Here is the my_suite.txt file: 这是my_suite.txt文件:

*** Settings ***
Library           test.MyKeywords

*** Test Cases ***
MyTestCase
    ${message}    say hi
    Log    ${message}

MyTestCase2
    ${message}    say hi    my_name
    Log    ${message}

MyTestCase3
    ${message}    type of    42
    Log    ${message}

Whenever, I try to paste the my_suite.txt file into the project directory, it goes under the bin directory. 每当我尝试将my_suite.txt文件粘贴到项目目录中时,它都位于bin目录下。 After that, when I run pybot my_suite.txt from the terminal (I am on Mac OS), I got the following message: 之后,当我从终端(在Mac OS上)运行pybot my_suite.txt时,出现以下消息:

[ ERROR ] Error in file '/Users/b18/Documents/workspace/Example/my_suite.txt': Importing test library 'test.MyKeywords' failed: Module 'test' does not contain 'MyKeywords'. [错误]文件'/Users/b18/Documents/workspace/Example/my_suite.txt'中的错误:导入测试库'test.MyKeywords'失败:模块'test'不包含'MyKeywords'。 ============================================================================== My Suite ================================================== ===========================我的套房

============================================================================== MyTestCase ================================================== =========================== MyTestCase
| | FAIL | 失败| No keyword with name 'say hi' found. 找不到名称为“ say hi”的关键字。 ------------------------------------------------------------------------------ MyTestCase2 -------------------------------------------------- ---------------------------- MyTestCase2
| | FAIL | 失败| No keyword with name 'say hi' found. 找不到名称为“ say hi”的关键字。 ------------------------------------------------------------------------------ MyTestCase3 -------------------------------------------------- ---------------------------- MyTestCase3
| | FAIL | 失败| No keyword with name 'type of' found. 找不到名称为“类型”的关键字。 ------------------------------------------------------------------------------ My Suite -------------------------------------------------- ----------------------------我的套房
| | FAIL | 失败| 3 critical tests, 0 passed, 3 failed 3 tests total, 0 passed, 3 failed ============================================================================== Output: /Users/b18/Documents/workspace/Example/output.xml Log: 3个关键测试,0个通过,3个失败总共3个测试,0个通过,3个失败================================= ===========================================输出:/用户/b18/Documents/workspace/Example/output.xml日志:
/Users/b18/Documents/workspace/Example/log.html Report: /Users/b18/Documents/workspace/Example/report.html /Users/b18/Documents/workspace/Example/log.html报告:/Users/b18/Documents/workspace/Example/report.html

Where is my mistake and what am I missing? 我的错误在哪里,我想念什么?

You're mixing languages here. 您在这里混合语言。

You are using Java keywords, with pybot (which is pure python - and doesn't support java). 您正在使用Java关键字和pybot(这是纯python-不支持Java)。

You need to use jybot instead (you can download the jar and run it with java) 您需要改为使用jybot(您可以下载jar并使用Java运行它)

Jybot is based on Jython - and supports python and java code. Jybot基于Jython-支持python和java代码。

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

相关问题 如何使用jsp运行测试用例(用junit 3.x和4.x编写)? - How can I run my test cases (which written in junit 3.x and 4.x) using jsp? 使用 java 的机器人框架 - 如何将测试状态设置为“警告” - Robot framework using java - How to set status of the test to “Warning” Selenium Java-如何登录一次并使用同一浏览器实例运行多个测试用例,而是为每个测试打开/关闭浏览器 - Selenium Java-How do I login once and run multiple test cases using the same instance of browser, instead open/close the browser for every single test 如何在 Robot Framework 中导入 Java 库,如果我想从中测试 Java 代码 - How to import Java Libraries in Robot Framework, If I am trying to test Java code from it QTP测试用例可以用Java编写吗? - Can QTP test cases be written in Java? 如何在java中调用kotlin类中编写的函数? - How do I call a function written in a kotlin class , in java? 如何在基于 Python 的 Robot 框架中包含 Java 测试库 - How to include Java test libraries in a Python based Robot framework 如何通过Java实现的关键字停止在Robot Framework中执行测试? - How to stop test execution in Robot Framework through keywords implemented with Java? 使用Java Robot类 - Using java Robot class 如何使用spring-boot框架运行测试用例 - How to run test cases with the spring-boot framework
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM