参考: https://github.com/robotframework/robotframework/issues/2601
I am pretty happy with the extended variable syntax. But I agree that it's quite painful to remember which way to write the square brackets in the variables. I think supporting |
参考: https://github.com/robotframework/robotframework/issues/2601
I am pretty happy with the extended variable syntax. But I agree that it's quite painful to remember which way to write the square brackets in the variables. I think supporting |
https://blog.csdn.net/weixin_41407477/article/details/82626977
tag可以是自己定义,而且可以一个测试用例可以打多个tags
-i --include tag * Select test cases to run by tag.
所有包含tag的测试用例都会被执行
-e --exclude tag * Select test cases not to run by tag.
所有包含tag的测试用例都不会被执行
pybot -i smoke -e tbd xxx.robot上面这段命令,会执行包含smoke的但不包含tbd的测试用例
Robot results publisher started... -Parsing output xml: Done! -Copying log files to build dir: Failed!
在对应的目录可以看到生成的报告,但是在jenkins无法访问,这个是统计过程出现问题引起的吗?
Pauses the test executed for the given time.
time may be either a number or a time string. Time strings are in a format such as 1 day 2 hours 3 minutes 4 seconds 5milliseconds or 1d 2h 3m 4s 5ms, and they are fully explained in an appendix of Robot Framework User Guide. Optional reason can be used to explain why sleeping is necessary. Both the time slept and the reason are logged.
Examples:
| Sleep | 42 | |
| Sleep | 1.5 | |
| Sleep | 2 minutes 10 seconds | |
| Sleep | 10s | Wait for a reply |
| 变量 | 描述 | 使用范围 |
|---|---|---|
| ${TEST NAME} | 当前测试用例的名称 | 测试用例内 |
| @{TEST TAGS} | 当前测试用的Tags | 测试用例内 |
| ${TEST DOCUMENTATION} | 当前测试用例的文档 | 测试用例内 |
| ${TEST STATUS} | 当前测试用例的测试结果,PASS或FAIL | Test teardown |
| ${TEST MESSAGE} | 当前测试用的的测试结果信息 | Test teatdown |
| ${PREV TEST NAME} | 上一条测试用例的名称,如果没有则值为空 | 任意 |
| ${PREV TEST STATUS} | 上一条测试用例的结果,如果没有则值为空 | 任意 |
| ${PREV TEST MESSAGE} | 上一条测试用例的结果信息,如果没有则值为空 | 任意 |
| ${SUITE NAME} | 当前测试集的全称 | 任意 |
| ${SUITE SOURCE} | 当前测试集的绝对路径 | 任意 |
| ${SUITE DOCUMENTATION} | 当前测试集的描述,可以通过Set Suite Documentation 修改 | 任意 |
| &{SUITE METADATA} | 当前测试集的METADATA,可以通过Set Suite Metadata修改 | 任意 |
| ${SUITE STATUS} | 当前测试集的测试状态 | Suite teardown |
| ${SUITE MESSAGE} | 当前测试集的测试状态信息 | Suite teardown |
| ${KEYWORD STATUS} | 当前关键字的状态 | Keyword teardown |
| ${KEYWORD MESSAGE} | 当前关键字的状态信息 | Keyword teardown |
| ${LOG LEVEL} | 当前的日志级别 | 任意 |
| ${OUTPUT FILE} | output文件的绝对路径 | 任意 |
| ${LOG FILE} | log文件的绝对路径,如果没有则为None | 任意 |
| ${REPORT FILE} | report文件的绝对路径,如果没有则为None | 任意 |
| ${DEBUG FILE} | debug文件的绝对路径,如果没有则为None | 任意 |
| ${OUTPUT DIR} | output文件夹的绝对路径 | 任意 |
t.robot.txt
17 BuiltIn.log ${tu}
18 BuiltIn.log ${tl}
19 ${c_tu}= Convert To List ${tu}
20 BuiltIn.log ${c_tu}
21 BuiltIn.log ${c_tu}[0]
22 # BuiltIn.log ${ngtdp_server}
23 # BuiltIn.log ${dic_web}
定義 t.py
1 tu = ('fail', {'ip': 'pass'})
2 tl = ['fail', {'ip': 'pass'}]
robot --listener path/to/PauseExecution.py tests.robot
"""Listener that stops execution if a test fails."""
ROBOT_LISTENER_API_VERSION = 3
def end_test(data, result):
if not result.passed:
print('Test "%s" failed: %s' % (result.name, result.message))
raw_input('Press enter to continue.') #这个检测可以发现测试停止了,
#说明listener 和robot是使用一个线程的,不是两个,这个要注意,但是listener中错误应是
#被封装了,在robot运行中是不会看到listener的错误的:),留心不报错的代码执行问题。
ROBOT_LISTENER_API_VERSION = 3
def start_suite(suite, result):
suite.tests.create(name='New test')
def start_test(test, result):
test.keywords.create(name='Log', args=['Keyword added by listener!'])
| 15:36:49.003 | FAIL | No keyword with name '&{&{config_map}[${env_config}]}[tdp_ip]' found. |
1 *** Settings ***
2 Variables mapping_tdp.py
3 *** Test Cases ***
4 testII
5 ${env_config} Set Variable dev
6 Log &{config_map}[${env_config}]
7 &{deva} Set Variable &{config_map}[${env_config}]
8 Log ${deva}
9 Log &{deva}[tdp_ip]
.py, 对Java库则是 .class 或 .java, 不过.class文件必须存在. 如果Python库是一个文件夹, 该路径最后必须有一个斜杠结尾(/).*** Settings ***
Library PythonLibrary.py
Library /absolute/path/JavaLibrary.java
Library relative/path/PythonDirLib/ possible arguments
Library ${RESOURCES}/Example.class
| &{clist}= Create Dictionary key=key1 value=value1
logname ${clist} Log ${clist} PS: 注意一点 字典定义时使用&, 打印引用时使用$ | Create Dictionary | *items |
Creates and returns a dictionary based on the given items.
Items are typically given using the key=value syntax same way as &{dictionary} variables are created in the Variable table. Both keys and values can contain variables, and possible equal sign in key can be escaped with a backslash like escaped\=key=value. It is also possible to get items from existing dictionaries by simply using them like &{dict}. Alternatively items can be specified so that keys and values are given separately. This and the key=value syntax can even be combined, but separately given items must be first. If same key is used multiple times, the last value has precedence. The returned dictionary is ordered, and values with strings as keys can also be accessed using a convenient dot-access syntax like ${dict.key}. Examples: &{dict} = Create Dictionary key=value foo=bar # key=value syntax Should Be True ${dict} == {'key': 'value', 'foo': 'bar'} &{dict2} = Create Dictionary key value foo bar # separate key and value Should Be Equal ${dict} ${dict2} &{dict} = Create Dictionary ${1}=${2} &{dict} foo=new # using variables Should Be True ${dict} == {1: 2, 'key': 'value', 'foo': 'new'} Should Be Equal ${dict.key} value # dot-access This keyword was changed in Robot Framework 2.9 in many ways: Moved from Collections library to BuiltIn. Support also non-string keys in key=value syntax. Returned dictionary is ordered and dot-accessible. Old syntax to give keys and values separately was deprecated, but deprecation was later removed in RF 3.0.1. |
| @{items}= Create List a b c | Create List | *items |
Returns a list containing given items.
The returned list can be assigned both to ${scalar} and @{list} variables. Examples: @{list} = Create List a b c ${scalar} = Create List a b c ${ints} = Create List ${1} ${2} ${3} |
| ${py}= Evaluate random.randint(0, sys.maxint) modules=random, sys
Log ${py} PS: 可以直接执行python模块和方法,不错很好用 | Evaluate | expression,modules=None,namespace=None |
Evaluates the given expression in Python and returns the results.
expression is evaluated in Python as explained in Evaluating expressions. modules argument can be used to specify a comma separated list of Python modules to be imported and added to the evaluation namespace. namespace argument can be used to pass a custom evaluation namespace as a dictionary. Possible modules are added to this namespace. This is a new feature in Robot Framework 2.8.4. Variables used like ${variable} are replaced in the expression before evaluation. Variables are also available in the evaluation namespace and can be accessed using special syntax $variable. This is a new feature in Robot Framework 2.9 and it is explained more thoroughly in Evaluating expressions. Examples (expecting ${result} is 3.14): ${status} = Evaluate 0 < ${result} < 10 # Would also work with string '3.14' ${status} = Evaluate 0 < $result < 10 # Using variable itself, not string representation ${random} = Evaluate random.randint(0, sys.maxint) modules=random, sys ${ns} = Create Dictionary x=${4} y=${2} ${result} = Evaluate x*10 + y namespace=${ns} => ${status} = True ${random} = ${result} = 42 |
| :FOR ${it} IN @{items}
\ Run Keyword If '${it}'=='a' Exit For Loop \ Log ${it} | Exit For Loop |
Stops executing the enclosing for loop.
Exits the enclosing for loop and continues execution after it. Can be used directly in a for loop or in a keyword that the loop uses. Example: :FOR ${var} IN @{VALUES} Run Keyword If '${var}' == 'EXIT' Exit For Loop Do Something ${var} See Exit For Loop If to conditionally exit a for loop without using Run Keyword If or other wrapper keywords. | |
| :FOR ${it} IN @{items}
\ Exit For Loop If '${it}'=='b' \ Log ${it} | Exit For Loop If | condition |
Stops executing the enclosing for loop if the condition is true.
A wrapper for Exit For Loop to exit a for loop based on the given condition. The condition is evaluated using the same semantics as with Should Be True keyword. Example: :FOR ${var} IN @{VALUES} Exit For Loop If '${var}' == 'EXIT' Do Something ${var} New in Robot Framework 2.8. |
| Fail test fail | Fail | msg=None, *tags |
Fails the test with the given message and optionally alters its tags.
The error message is specified using the msg argument. It is possible to use HTML in the given error message, similarly as with any other keyword accepting an error message, by prefixing the error with *HTML*. It is possible to modify tags of the current test case by passing tags after the message. Tags starting with a hyphen (e.g. -regression) are removed and others added. Tags are modified using Set Tags and Remove Tags internally, and the semantics setting and removing them are the same as with these keywords. Examples: Fail Test not ready # Fails with the given message. Fail *HTML*Test not ready # Fails using HTML in the message. Fail Test not ready not-ready # Fails and adds 'not-ready' tag. Fail OS not supported -regression # Removes tag 'regression'. Fail My message tag -t* # Removes all tags starting with 't' except the newly added 'tag'. See Fatal Error if you need to stop the whole test execution. Support for modifying tags was added in Robot Framework 2.7.4 and HTML message support in 2.8. |
| Fatal Error test faial Error | Fatal Error | msg=None | |
| ${count}= Get Count 2aa3 a | Get Count | item1, item2 |
Returns and logs how many times item2 is found from item1.
This keyword works with Python strings and lists and all objects that either have count method or can be converted to Python lists. Example: ${count} = Get Count ${some item} interesting value Should Be True 5 < ${count} < 10 |
| ${num}= Get Length aaadddsdfadsd | Get Length | item |
Returns and logs the length of the given item as an integer.
The item can be anything that has a length, for example, a string, a list, or a mapping. The keyword first tries to get the length with the Python function len, which calls the item's __len__ method internally. If that fails, the keyword tries to call the item's possible length and size methods directly. The final attempt is trying to get the value of the item's length attribute. If all these attempts are unsuccessful, the keyword fails. Examples: ${length} = Get Length Hello, world! Should Be Equal As Integers ${length} 13 @{list} = Create List Hello, world! ${length} = Get Length ${list} Should Be Equal As Integers ${length} 2 See also Length Should Be, Should Be Empty and Should Not Be Empty. |
| &{all libs}= Get library instance all=True
Log Many &{all libs} ? PS:还是不太明白这个方法返回的内容,是全部的内置导入的类吗? 以上代码打印结果如下: KEYWORD BuiltIn . Log Many &{all libs} Documentation: Logs the given messages as separate entries using the INFO level. Start / End / Elapsed: 20171026 12:30:55.955 / 20171026 12:30:55.957 / 00:00:00.002 12:30:55.956 INFO Reserved= 12:30:55.956 INFO Demo= 12:30:55.956 INFO OperatingSystem= 12:30:55.957 INFO BuiltIn= 12:30:55.957 INFO Easter= | Get Library Instance | name=None, all=False |
Returns the currently active instance of the specified test library.
This keyword makes it easy for test libraries to interact with other test libraries that have state. This is illustrated by the Python example below: from robot.libraries.BuiltIn import BuiltIn def title_should_start_with(expected): seleniumlib = BuiltIn().get_library_instance('SeleniumLibrary') title = seleniumlib.get_title() if not title.startswith(expected): raise AssertionError("Title '%s' did not start with '%s'" % (title, expected)) It is also possible to use this keyword in the test data and pass the returned library instance to another keyword. If a library is imported with a custom name, the name used to get the instance must be that name and not the original library name. If the optional argument all is given a true value, then a dictionary mapping all library names to instances will be returned. This feature is new in Robot Framework 2.9.2. Example: &{all libs} = Get library instance all=True |
| ${time} = Get Time
${secs} = Get Time epoch ${year} = Get Time return year ${yyyy} ${mm} ${dd} = Get Time year,month,day @{time} = Get Time year month day hour min sec ${y} ${s} = Get Time seconds and year Log Many ${time} ${secs} ${year} ${yyyy} ${mm} ${dd} @{time} ${y} ${s} | Get Time | format=timestamp,time_=NOW |
【popexizhi: 之前是 robotframework 3.1.1
看这个应该是3.2 的新功能了:)
】
Changing the meaning of
@{var}[x]and&{var}[x]is backwards compatible and requires graceful deprecation. My proposal is to do it like this:In RF 3.0.3 add the support for using
${var}[x]and also${var}[nested][x]with variables containing lists and dictionaries. Don't change@{var}[x]and&{var}[x]syntax.In RF 3.1 deprecate using
@{var}[x]and&{var}[x]. Issue a warning if the syntax is used but don't change the functionality yet.In RF 3.2 change
@{var}[x]and&{var}[x]to mean using variable${var}[x]as a list or dictionary, respectively.