html tool

2017年10月25日星期三

robotframe 内嵌关键字的用法补遗VI



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 cCreate 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模块和方法,不错很好用
Evaluateexpression,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 Ifcondition
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 failFailmsg=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 Errormsg=None
${count}= Get Count 2aa3 aGet Countitem1, 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 aaadddsdfadsdGet Lengthitem
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 Instancename=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 Timeformat=timestamp,time_=NOW
Returns the given time in the requested format.
NOTE: DateTime library added in Robot Framework 2.8.5 contains much more flexible keywords for getting the current date and time and for date and time handling in general.
How time is returned is determined based on the given format string as follows. Note that all checks are case-insensitive.
1) If format contains the word epoch, the time is returned in seconds after the UNIX epoch (1970-01-01 00:00:00 UTC). The return value is always an integer.
2) If format contains any of the words year, month, day, hour, min, or sec, only the selected parts are returned. The order of the returned parts is always the one in the previous sentence and the order of words in format is not significant. The parts are returned as zero-padded strings (e.g. May -> 05).
3) Otherwise (and by default) the time is returned as a timestamp string in the format 2006-02-24 15:08:31.
By default this keyword returns the current local time, but that can be altered using time argument as explained below. Note that all checks involving strings are case-insensitive.
1) If time is a number, or a string that can be converted to a number, it is interpreted as seconds since the UNIX epoch. This documentation was originally written about 1177654467 seconds after the epoch.
2) If time is a timestamp, that time will be used. Valid timestamp formats are YYYY-MM-DD hh:mm:ss and YYYYMMDD hhmmss.
3) If time is equal to NOW (default), the current local time is used. This time is got using Python's time.time() function.
4) If time is equal to UTC, the current time in UTC is used. This time is got using time.time() + time.altzone in Python.
5) If time is in the format like NOW - 1 day or UTC + 1 hour 30 min, the current local/UTC time plus/minus the time specified with the time string is used. The time string format is described in an appendix of Robot Framework User Guide.
Examples (expecting the current local time is 2006-03-29 15:06:21):
${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
=>
${time} = '2006-03-29 15:06:21'
${secs} = 1143637581
${year} = '2006'
${yyyy} = '2006', ${mm} = '03', ${dd} = '29'
@{time} = ['2006', '03', '29', '15', '06', '21']
${y} = '2006'
${s} = '21'
Examples (expecting the current local time is 2006-03-29 15:06:21 and UTC time is 2006-03-29 12:06:21):
${time} = Get Time 1177654467 # Time given as epoch seconds ${secs} = Get Time sec 2007-04-27 09:14:27 # Time given as a timestamp ${year} = Get Time year NOW # The local time of execution @{time} = Get Time hour min sec NOW + 1h 2min 3s # 1h 2min 3s added to the local time @{utc} = Get Time hour min sec UTC # The UTC time of execution ${hour} = Get Time hour UTC - 1 hour # 1h subtracted from the UTC time
=>
${time} = '2007-04-27 09:14:27'
${secs} = 27
${year} = '2006'
@{time} = ['16', '08', '24']
@{utc} = ['12', '06', '21']
${hour} = '11'
Support for UTC time was added in Robot Framework 2.7.5 but it did not work correctly until 2.7.7.

没有评论:

发表评论