http://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Run%20Keyword%20If%20Any%20Critical%20Tests%20Failed
| &{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 |
没有评论:
发表评论