[Robot Framework] pybot/robot 命令行参数说明

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的用例。空格和大小写不敏感。同样可以使用简单的正则表达式:"*" 匹配任意字符,"?"匹配单个字符。
多个Tags之间用 AND、OR 和 NOT 关键字连接,如:-i P1ANDP2-i NOTPaid

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

--logtitle 用于设置输出文件log.html中的title和h1标签的值

--reporttitle title   Title for the generated test report. The default
                        title is `<Name Of The Suite> Test Report`.

--reporttitle 用于设置输出文件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

--reportbackground 用于设置输出文件report.html的背景色,例如:

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

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

[To be continued...]

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 159,458评论 4 363
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,454评论 1 294
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 109,171评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,062评论 0 207
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,440评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,661评论 1 219
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,906评论 2 313
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,609评论 0 200
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,379评论 1 246
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,600评论 2 246
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,085评论 1 261
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,409评论 2 254
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,072评论 3 237
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,088评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,860评论 0 195
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,704评论 2 276
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,608评论 2 270

推荐阅读更多精彩内容