pybot/robot命令行参数说明

作者: Rethink | 来源:发表于2018-12-19 10:36 被阅读1次

    Robot Framework Version: 3.0.4 (Python 3.7.0 on win32)
    Usage: robot [options] data_sources
    or: python -m robot [options] data_sources
    or: python path/to/robot [options] data_sources
    or: java -jar robotframework.jar [options] data_sources


    Options

     -F --extension value     Parse only files with this extension when executing
                              a directory. Has no effect when running individual
                              files or when using resource files. If more than one
                              extension is needed, separate them with a colon.
                              Examples: `--extension robot`, `-F robot:txt`
                              New in RF 3.0.1.          
    

    执行用例时,只解析指定扩展名的文件类型。在运行单独文件或使用资源文件时无效。如果需要多个扩展,需要用冒号分隔,如:"-F robot:txt"

     -G --settag tag *       Sets given tag(s) to all executed test cases.
    

    给所有执行的用例执行tag,如:"robot -G tag1 -G tag2 helloRobot", 执行完成后,在测试报告中可以看到所设置的tag
    注意:通过-G参数给case添加的tag是临时的,只在本次运行时生效。

    -t --test name *         Select test cases to run by name or long name. Name
                              is case and space insensitive and it can also be a
                              simple pattern where `*` matches anything and `?`
                              matches any char. If using `*` and `?` in the console
                              is problematic see --escape and --argumentfile.
    根据用例名称来选择要运行的用例,空格和大小写不敏感。名称也可以是一个简单的正则表达式:"*" 匹配任意内容,"?"匹配单个字符。例:robot -t *te?t* helloRobot
    ------------------------------------------------
     -s --suite name *        Select test suites to run by name. When this option
                              is used with --test, --include or --exclude, only
                              test cases in matching suites and also matching other
                              filtering criteria are selected. Name can be a simple
                              pattern similarly as with --test and it can contain
                              parent name separated with a dot. For example
                              `-s X.Y` selects suite `Y` only if its parent is `X`.
     根据用例集名称来选择要运行的用例集。当此参数和--test,--include或--exclude一同使用时,只有满足全部筛选条件的用例才会被执行。
     名称同样可以是一个简单的正则表达式(和--test类似),另外还可以使用"."来表示层级关系,如:-s X.Y,表示仅执行X下的Y子集的用例。
     ------------------------------------------------
     -i --include tag *       Select test cases to run by tag. Similarly as name
                              with --test, tag is case and space insensitive and it
                              is possible to use patterns with `*` and `?` as
                              wildcards. Tags and patterns can also be combined
                              together with `AND`, `OR`, and `NOT` operators.
                              Examples: --include foo --include bar*
                                        --include fooANDbar*
    选择并执行指定tag的用例。空格和大小写不敏感。同样可以使用简单的正则表达式:"*" 匹配任意字符,"?"匹配单个字符。
    --include fooANDbar* 这种写法在我本地测试是会报错,原因待研究,如有多个tag,建议分开写:-i foo -i bar*
    ------------------------------------------------
     -e --exclude tag *       Select test cases not to run by tag. These tests are
                              not run even if included with --include. Tags are
                              matched using the rules explained with --include.
    -e参数的作用和-i相反,它是选择并执行非指定tag的用例。用法和-i完全相同。
    
    -R --rerunfailed output  Select failed tests from an earlier output file to be
                              re-executed. Equivalent to selecting same tests
                              individually using --test option.
    -R参数非常有用,它的作用是从output file中选择失败的用例重跑。
    但是有个问题,如果上一次运行时用例全部成功,此时加上-R参数再去运行用例时会报错: failed: All tests passed ,这导致我没办法在jenkins job中使用这个参数。
    ------------------------------------------------
     -S --rerunfailedsuites output  Select failed suite from an earlier output file
                              to be re-executed. New in RF 3.0.1.
    -S参数和-R参数的作用类似,它的作用是从output file中选择失败的用例集重跑。
    
     -c --critical tag *      Tests having given tag are considered critical. If no
                              critical tags are set, all tags are critical. Tags
                              can be given as a pattern like with --include.
     -n --noncritical tag *   Tests with given tag are not critical even if they
                              have a tag set with --critical. Tag can be a pattern.
    这两个参数是用来表示tag的重要程度,一般只在测试报告中会展示。
    如果不使用-c tag,默认所有运行的tag都是critical tag。
    如下:robot -c T1 -n T2 helloRobot
    
    -v --variable name:value *  Set variables in the test data. Only scalar
                              variables with string value are supported and name is
                              given without `${}`. See --escape for how to use
                              special characters and --variablefile for a more
                              powerful variable setting mechanism.
                              Examples:
                              --variable str:Hello       =>  ${str} = `Hello`
                              -v hi:Hi_World -E space:_  =>  ${hi} = `Hi World`
                              -v x: -v y:42              =>  ${x} = ``, ${y} = `42`
     -V --variablefile path *  Python or YAML file file to read variables from.
                              Possible arguments to the variable file can be given
                              after the path using colon or semicolon as separator.
                              Examples: --variablefile path/vars.yaml
                                        --variablefile environment.py:testing
     -v`用来设置变量,而`-V`用来引入变量文件,这两个参数很有用,如`-V`结合变量文件可以用来切换用例的运行环境(生产环境OR测试环境)
    

    RF变量文件具体的用法,参照我之前的文章:Robot Framework - Variable file

    -d --outputdir dir       Where to create output files. The default is the
                              directory where tests are run from and the given path
                              is considered relative to that unless it is absolute.
                              
     -o --output file         XML output file. Given path, similarly as paths given
                              to --log, --report, --xunit, and --debugfile, is
                              relative to --outputdir unless given as an absolute
                              path. Other output files are created based on XML
                              output files after the test execution and XML outputs
                              can also be further processed with Rebot tool. Can be
                              disabled by giving a special value `NONE`. In this
                              case, also log and report are automatically disabled.
                              Default: output.xml
                              
     -l --log file            HTML log file. Can be disabled by giving a special
                              value `NONE`. Default: log.html
                              Examples: `--log mylog.html`, `-l NONE`
                              
     -r --report file         HTML report file. Can be disabled with `NONE`
                              similarly as --log. Default: report.html
                              
     -x --xunit file          xUnit compatible result file. Not created unless this
                              option is specified.
        --xunitskipnoncritical  Mark non-critical tests on xUnit output as skipped.
        
     -b --debugfile file      Debug file written during execution. Not created
                              unless this option is specified.
    

    -d参数用来设置RF输出文件的路径,输出文件包含:log.html, report.html 和 output.xml等。-o-l-r`参数用来分别设置 output.xml、log.html和 report.html的输出路径和文件名称。

    如果使用参数修改了RF输出文件的输出目录,在Jenkins中也必须要进行设置,否则插件找不到output.xml文件,也就无法解析结果了。关于Jenkins的更多详细信息请参考:从零搭建Robot Framework+Jenkins持续集成环境


    -x用来生成xUnit兼容的结果文件,-b 用来生成用例执行过程中写入的调试文件,如果未设置这两个参数,则对应文件默认不会生成,如:robot -x E:\test.xml -b E:\debug.html helloRobot
    -T --timestampoutputs    When this option is used, timestamp in a format
                              `YYYYMMDD-hhmmss` is added to all generated output
                              files between their basename and extension. For
                              example `-T -o output.xml -r report.html -l none`
                              creates files like `output-20070503-154410.xml` and
                              `report-20070503-154410.html`.
    使用`-T` 参数后,所生成的输出文件名称中将会附加指定格式的时间戳。
    --logtitle title      Title for the generated test log. The default title
                              is `<Name Of The Suite> Test Log`. Underscores in
                              the title are converted into spaces in all titles.
     设置输出文件log.html中的title和h1标签的值
                              
    --reporttitle title   Title for the generated test report. The default
                              title is `<Name Of The Suite> Test Report`.
    设置输出文件report.html中的title和h1标签的值
                              
    --reportbackground colors  Background colors to use in the report file.
                              Either `all_passed:critical_passed:failed` or
                              `passed:failed`. Both color names and codes work.
                              Examples: --reportbackground green:yellow:red
                                        --reportbackground #00E:#E00
    设置输出文件report.html的背景色,格式为:all_passed:critical_passed:failed 或 passed:failed
    

    例如:

    robot --logtitle Rethink简书 --reporttitle Rethink简书 --reportbackground pink:red helloRobot
    
    pink

    以上就是所有常用参数的说明,其他更多可用参数,请使用robot --help > robot_help.txt 查看.
    To be continued...

    相关文章

      网友评论

        本文标题:pybot/robot命令行参数说明

        本文链接:https://www.haomeiwen.com/subject/vxvehqtx.html