简体   繁体   English

如何仅在机器人框架中其他文件中的Testsuit中调用Testcase

[英]How to call only Testcase in Testsuit in other file in robot framework

suppose This file contain only testcase means this doesn't contain any test_suit or test_teardown . 假设此文件仅包含测试用例,则意味着该文件不包含任何test_suittest_teardown

*** Settings ***
Documentation     This suite also demonstrates using setups and teardowns in
...               different levels.
Resource          nw_res.txt
Library           network_library.BaseClass
Library           ${CURDIR}/../Helper/conf_parser.py
Library           ${CURDIR}/../Helper/utilities.py

*** Test Cases ***

TC001 : Check If User Is Able To Browse Data
    [Documentation]    This TC will check if user is able to browse data 
    after session is up or not
    [Tags]    build_verification sanity quick_regression
    Log To Console     Started Test Execution

    Log To Console     STEP 1 : Check Version    no_newline=false
    Check Build Version

we have also resource.txt 我们也有resource.txt

and 3rd file called the test_suit and test_teardown means that file contain test_suit call only testcase001,testcase002,testcase003 test_teardown 第三个文件称为test_suittest_teardown意味着该文件包含test_suit仅调用testcase001,testcase002,testcase003 test_teardown

and execute this file is this possible in robot framework if yes then how? 并在机器人框架中执行此文件,如果可以,那么如何?

Another way to run multiple suite is Argument file 运行多个套件的另一种方法是参数文件

Declare all the suites in a txt file 在txt文件中声明所有套件

eg sample.text 例如sample.text

suite1.robot
suite2.robot
suite3.robot

Use -A , Argument file option 使用-A参数文件选项

pybot -A sample.text

this will execute all the suites in sequence as described in text file 这将按照文本文件中的描述依次执行所有套件

Wrapping @pankaj and @Bryan answers with official docs: Have a look into robot docs about test execution: 用官方文档包装@pankaj和@Bryan答案:看一下有关测试执行的机器人文档:

Test cases are always executed within a test suite. 测试用例总是在测试套件中执行。 A test suite created from a test case file has tests directly, whereas suites created from directories have child test suites which either have tests or their own child suites. 从测试用例文件创建的测试套件直接具有测试,而从目录创建的套件具有子测试套件,这些子测试套件具有测试或自己的子套件。 By default all the tests in an executed suite are run, but it is possible to select tests using options --test, --suite, --include and --exclude. 默认情况下,将运行已执行套件中的所有测试,但是可以使用--test,-suite,-include和--exclude选项选择测试。 Suites containing no tests are ignored. 不包含任何测试的套件将被忽略。

As @Bryan said, robot will run testcases in testsuite file, if folder is selected,all inherited testcases and testsuites will be executed 正如@Bryan所说,robot将在testsuite文件中运行测试用例,如果选择了文件夹,则将执行所有继承的测试用例和测试用例

If you need to select testcases from testsuites to run,exclude some or execute based on tag, check this section 如果需要从测试套件中选择要运行的测试用例,排除某些测试用例或基于标记执行, 请选中此部分

Test suites and test cases can be selected by their names with the command line options --suite (-s) and --test (-t), respectively. 可以通过命令行选项--suite(-s)和--test(-t)分别选择测试套件和测试用例的名称。 Both of these options can be used several times to select several test suites or cases. 这两个选项都可以多次使用,以选择多个测试套件或案例。 Arguments to these options are case- and space-insensitive, and there can also be simple patterns matching multiple names. 这些选项的参数不区分大小写和空格,并且还可以存在与多个名称匹配的简单模式。 If both the --suite and --test options are used, only test cases in matching suites with matching names are selected. 如果同时使用--suite和--test选项,则仅选择名称匹配的匹配套件中的测试用例。

It is possible to include and exclude test cases by tag names with the --include (-i) and --exclude (-e) options, respectively. 可以分别使用--include(-i)和--exclude(-e)选项通过标记名称包含和排除测试用例。 If the --include option is used, only test cases having a matching tag are selected, and with the --exclude option test cases having a matching tag are not. 如果使用--include选项,则仅选择具有匹配标记的测试用例,而使用--exclude选项,则不选择具有匹配标记的测试用例。 If both are used, only tests with a tag matching the former option, and not with a tag matching the latter, are selected. 如果两者都使用,则仅选择标签与前一个选项匹配的测试,而不选择标签与后一个选项匹配的测试。

About argument file and syntax, here is appropriate part Arg files are useful if your command line gets too long or can be predefined and shared. 关于参数文件和语法, 这是适当的部分如果命令行太长或可以预定义和共享, Arg文件很有用。

Robot framework provides flexibility to provide setup/teardown at suite level. 机械手框架提供了在套件级别提供设置/拆卸的灵活性。

Best practice of robot-framework is club similar testcases under suite. 机器人框架的最佳实践是套件下的类似俱乐部的测试用例。 And keep keywords in separate file. 并将关键字保存在单独的文件中。

Try following below order to keep it simple. 请尝试按照以下步骤进行操作,以保持简单。

 1. Create suite with multiple testcases. (Ex testcase001, testcase002, testcase003) 
 2. Create Test-teardown keyword in different file.
 3. Under the suite-teardown call the keyword created in step-2. 

Alll testcases will be executed followed by suite teardown, this should solve your requirement. 将执行Alll测试用例,然后进行套件拆卸,这应该可以满足您的要求。

In robot framework user can only execute testcases, keywords cannot be executed directly. 在机器人框架中,用户只能执行测试用例,而不能直接执行关键字。 Keywords are the reusable building blocks. 关键字是可重用的构建块。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM