简体   繁体   中英

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 .

*** 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

and 3rd file called the test_suit and test_teardown means that file contain test_suit call only 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

eg sample.text

suite1.robot
suite2.robot
suite3.robot

Use -A , Argument file option

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:

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. 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

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. 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.

It is possible to include and exclude test cases by tag names with the --include (-i) and --exclude (-e) options, respectively. 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. 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.

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.

In robot framework user can only execute testcases, keywords cannot be executed directly. Keywords are the reusable building blocks.

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.

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