RobotFramework源码入口及测试

1、下载RobotFramework源码 https://github.com/robotframework/robotframework

2、入口文件为src/robot 目录下的run.py文件

3、打开run.py文件可看到:

if __name__ == '__main__':
    run_cli(sys.argv[1:])

4、跟踪到run_cli方法,代码如下。可以看到注释,根据注释中的例子我们来写一个测试用例:

def run_cli(arguments=None, exit=True):
    """Command line execution entry point for running tests.

    :param arguments: Command line options and arguments as a list of strings.
        Starting from RF 3.1, defaults to ``sys.argv[1:]`` if not given.
    :param exit: If ``True``, call ``sys.exit`` with the return code denoting
        execution status, otherwise just return the rc. New in RF 3.0.1.

    Entry point used when running tests from the command line, but can also
    be used by custom scripts that execute tests. Especially useful if the
    script itself needs to accept same arguments as accepted by Robot Framework,
    because the script can just pass them forward directly along with the
    possible default values it sets itself.

    Example::

        from robot import run_cli

        # Run tests and return the return code.
        rc = run_cli(['--name', 'Example', 'tests.robot'], exit=False)

        # Run tests and exit to the system automatically.
        run_cli(['--name', 'Example', 'tests.robot'])

    See also the :func:`run` function that allows setting options as keyword
    arguments like ``name="Example"`` and generally has a richer API for
    programmatic test execution.
    """
    if arguments is None:
        arguments = sys.argv[1:]
    return RobotFramework().execute_cli(arguments, exit=exit)

5、在utest包中新建一个测试用例:此处我命名为testcase.py.代码如下,其中D:\\RF\\TestProject\\TestSuit.txt为用例存储路径:

import unittest
from robot import run_cli


class TestCase(unittest.TestCase):

    def runTest(self):
        rc = run_cli(['--name', 'Example', 'D:\\RF\\TestProject\\TestSuit.txt'], exit=False)


if __name__ == "__main__":
    unittest.main()

6、TestSuit.txt内容如下:

*** Test Cases ***
Testcase
    Log    Hello

7、执行新建的testcase.py文件即可跟踪源码。

以上用例均通过测试。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
Robot Framework自动化测试修炼宝典是一本非常适合学习Robot Framework的资料,其中包含了很多实用的例子、技巧和注意事项。它的源码.zip文件包含了完整的Robot Framework测试工程,其中包括了测试用例的编写、自动化测试脚本的实现、以及测试结果的生成和报告。 该工程主要由以下几个部分组成: 1. 测试用例 测试用例是Robot Framework的基本元素,它描述了要对被测试对象执行的测试步骤和预期结果。在该工程中,测试用例保存在tests目录下,每个测试用例以.robot为后缀,其中包含了关键字、变量、测试步骤和预期结果等信息。这些信息描述了测试对象、测试场景和结果验证等方面的内容,可以通过该工程执行对应的自动化测试脚本。 2. 自动化测试脚本 自动化测试脚本是测试用例的具体实现,它使用Robot Framework提供的关键字或扩展的关键字来操作被测对象,将测试用例转化为可执行的自动化测试脚本。在该工程中,自动化测试脚本保存在keywords目录下,每个自动化测试脚本以.py为后缀。这些脚本通过调用Selenium WebDriver或其他自动化组件来执行测试用例中描述的操作,并验证测试结果是否符合预期。 3. 测试报告 测试报告用于记录测试执行的详细信息、测试结果、警告和错误等情况,方便人员对测试结果进行分析和改进。在该工程中,测试报告保存在reports目录下,使用JUnitXML格式,可以通过阅读测试报告来了解测试执行的情况。此外,在该工程中也引入了Allure Framework来提高测试报告的可读性和可靠性,通过安装Allure并使用robotframework-allure报告生成器,可以生成非常好的测试报告。 总体而言,Robot Framework自动化测试修炼宝典的源码.zip是非常值得学习和探究的,它使学习自动化测试和Robot Framework更加直观、实用和深入。同时,该工程也为初学者提供了学习Robot Framework的绝佳案例和实践机会,很好地将理论知识和实际操作相结合。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值