lib.element
- class dt4test.lib.element.Element[source]
-
- convert_to_binary(item, base=None, prefix=None, length=None)[source]
- 转成二进制Examples :convert_to_binary(‘10’) # Result is 1010convert_to_binary(‘F’, base=16, prefix=0b) # Result is 0b1111convert_to_binary(‘-2’,prefix=B ,length=4) # Result is -B0010
- convert_to_bytes(input, input_type='text')[source]
- 转换成字节(样例结果参见源码)Examples : (最后一列是返回值,显示异常参考源码):convert_to_bytes(‘hyvä) # hyväconvert_to_bytes(‘hyvä’) # hyväconvert_to_bytes(‘ÿ’) # ÿconvert_to_bytes(’ 82 70’,’int’) # RFconvert_to_bytes(‘0b10 0x10’,’int’) #convert_to_bytes(‘ff 00 07’,’hex’) # ÿconvert_to_bytes(‘52462121’,’hex’) # RF!!convert_to_bytes(‘0000 1000’,’bin’) #convert_to_bytes([1,2,12],’int’) #convert_to_bytes([1,2,12],’hex’) #
- convert_to_hex(item, base=None, prefix=None, length=None, lowercase=False)[source]
- 转成16进制Examples :convert_to_hex(255) # Result is FFconvert_to_hex(-10,length=2)# Result is -0x0Aconvert_to_hex(‘255’, prefix=’X’) # Result is Xff
- convert_to_integer(item, base=None)[source]
- 转成整形数Examples :convert_to_integer(100) # Result is 100convert_to_integer(‘FF AA’, 16) # Result is 65450convert_to_integer(‘100’,8) # Result is 64convert_to_integer(‘-100’,2) # Result is -4convert_to_integer(‘0b100’) # Result is 4convert_to_integer(‘-0x100’) # Result is -256
- convert_to_number(item, precision=None)[source]
- 字符串转成数字Examples :convert_to_number(42.512) # Result is 42.512convert_to_number(‘42.512’,’1’) # Result is 42.5convert_to_number(42.512,0) # Result is 43.0convert_to_number(42.512,-1 ) # Result is 40.0
- convert_to_octal(item, base=None, prefix=None, length=None)[source]
- 转成10进制Examples :convert_to_octal(‘10’) # Result is 12convert_to_octal(‘-F’, base=16, prefix=0) # Result is -017convert_to_octal(‘16’, prefix=oct, length=4) # Result is oct0020
- convert_to_string(item)[source]
- 转成字符串
Warning
Use Encode String To Bytes and Decode Bytes To String keywords in
Stringlibrary if you need to convert between Unicode and byte strings using different encodings. Use Convert To Bytes if you just want to create byte strings.
- decode_bytes_to_string(bytes, encoding, errors='strict')[source]
解码
bytes到 Unicode string 使用encoding.errorsargument controls what to do if decoding some bytes fails. All values accepted bydecodemethod in Python are valid, but in practice the following values are most useful:strict: fail if characters cannot be decoded (default)ignore: ignore characters that cannot be decodedreplace: replace characters that cannot be decoded with a replacement character
Examples:decode_bytes_to_string( bytes,’UTF-8’)decode_bytes_to_string(bytes,’ASCII’,errors=’ignore’)Use Encode String To Bytes if you need to convert Unicode strings to byte strings, and Convert To String in
BuiltInif you need to convert arbitrary objects to Unicode strings.
- encode_string_to_bytes(string, encoding, errors='strict')[source]
编码字符串 string 到 字节 使用 encodeing
errorsargument controls what to do if encoding some characters fails. All values accepted byencodemethod in Python are valid, but in practice the following values are most useful:strict: fail if characters cannot be encoded (default)ignore: ignore characters that cannot be encodedreplace: replace characters that cannot be encoded with a replacement character
Examples :encode_string_to_bytes(string,’UTF-8’)encode_string_to_bytes(string,’ASCII’,errors=’ignore’)Use Convert To Bytes in
BuiltInif you want to create bytes based on character or integer sequences. Use Decode Bytes To String if you need to convert byte strings to Unicode strings and Convert To String inBuiltInif you need to convert arbitrary objects to Unicode.
- generate_random_string(length=8, chars='[LETTERS][NUMBERS]', prefix='')[source]
生成指定长度的随机串,使用特定chars
lengthcan be given as a number, a string representation of a number, or as a range of numbers, such as5-10. When a range of values is given the range will be selected by random within the range.The population sequence
charscontains the characters to use when generating the random string. It can contain any characters, and it is possible to use special markers explained in the table below:| = Marker = | = Explanation = |[LOWER]| Lowercase ASCII characters fromatoz. |[UPPER]| Uppercase ASCII characters fromAtoZ. |[LETTERS]| Lowercase and uppercase ASCII characters. |[NUMBERS]| Numbers from 0 to 9. |prefix| String’s prefix |Examples :generate_random_string()generate_random_string(12, ‘[LOWER]’)generate_random_string(8,’01’)generate_random_string(4,’[NUMBERS]abcdef’)generate_random_string(‘5-10’)Giving
lengthas a range of values is new in Robot Framework 5.0.
- get_index_from_list(list_, value, start=0, end=None)[source]
得到列表中的索引
Returns the index of the first occurrence of the
valueon the list.The search can be narrowed to the selected sublist by the
startandendindexes having the same semantics as with Get Slice From List keyword. In case the value is not found, -1 is returned. The given list is never altered by this keyword.
- get_lines_containing_string(string, pattern, case_insensitive=False)[source]
从
string中取得包含 pattern` 的行The
patternis always considered to be a normal string, not a glob or regexp pattern. A line matches if thepatternis found anywhere on it.The match is case-sensitive by default, but giving
case_insensitivea true value makes it case-insensitive. The value is considered true if it is a non-empty string that is not equal tofalse,noneorno. If the value is not a string, its truth value is got directly in Python.Lines are returned as one string catenated back together with newlines. Possible trailing newline is never returned. The number of matching lines is automatically logged.
Examples :get_lines_containing_string(somestring,’FAIL’, case_insensitive=False)See Get Lines Matching Pattern and Get Lines Matching Regexp if you need more complex pattern matching.
- get_lines_matching_pattern(string, pattern, case_insensitive=False)[source]
从
string中取得匹配pattern的行.Thepatternis where:*| matches everything |?| matches any single character |[chars]| matches any character inside square brackets (e.g.[abc]matches eithera,borc) |[!chars]| matches any character not inside square brackets |A line matches only if it matches the
patternfully.The match is case-sensitive by default, but giving
case_insensitivea true value makes it case-insensitive. The value is considered true if it is a non-empty string that is not equal tofalse,noneorno. If the value is not a string, its truth value is got directly in Python.Lines are returned as one string catenated back together with newlines. Possible trailing newline is never returned. The number of matching lines is automatically logged.
Examples :get_lines_matching_pattern(result, ‘Wild???? example’)get_lines_matching_pattern(result, ‘FAIL: *’)
- get_lines_matching_regexp(string, pattern, partial_match=False)[source]
从
string中取得匹配正则pattern的行.By default lines match only if they match the pattern fully, but partial matching can be enabled by giving the
partial_matchargument a true value. The value is considered true if it is a non-empty string that is not equal tofalse,noneorno. If the value is not a string, its truth value is got directly in Python.If the pattern is empty, it matches only empty lines by default. When partial matching is enabled, empty pattern matches all lines.
Notice that to make the match case-insensitive, you need to prefix the pattern with case-insensitive flag
(?i).Lines are returned as one string concatenated back together with newlines. Possible trailing newline is never returned. The number of matching lines is automatically logged.
Examples :get_lines_matching_regexp(result,’Reg\w{3} example’)get_lines_matching_regexp(result,’Reg\w{3} example’,partial_match=True)get_lines_matching_regexp(result,’(?i)FAIL: .*’)
- get_regexp_matches(string, pattern, *groups)[source]
返回匹配的列表
Returns a list of all non-overlapping matches in the given string.
stringis the string to find matches from andpatternis the regular expression. See BuiltIn.Should Match Regexp for more information about Python regular expression syntax in general and how to use it in Robot Framework data in particular.If no groups are used, the returned list contains full matches. If one group is used, the list contains only contents of that group. If multiple groups are used, the list contains tuples that contain individual group contents. All groups can be given as indexes (starting from 1) and named groups also as names.
Examples :get_regexp_matches(‘the string’,’xxx’)get_regexp_matches(‘the string’,’t..’)get_regexp_matches(‘the string’,’t(..)’, 1)get_regexp_matches(‘the string’,’t(?P<name>..)’, ‘name’)get_regexp_matches(‘the string’, ‘t(.)(.)’,1,2)=>${no match} = []${matches} = [‘the’, ‘tri’]${one group} = [‘he’, ‘ri’]${named group} = [‘he’, ‘ri’]${two groups} = [(‘h’, ‘e’), (‘r’, ‘i’)]
- remove_string(string, *removables)[source]
删除串中的内容
Removes all
removablesfrom the givenstring.removablesare used as literal strings. Each removable will be matched to a temporary string from which preceding removables have been already removed. See second example below.Use Remove String Using Regexp if more powerful pattern matching is needed. If only a certain number of matches should be removed, Replace String or Replace String Using Regexp can be used.
A modified version of the string is returned and the original string is not altered.
Examples :remove_string(‘Robot Framework’,’work’)’ # Robot Frameremove_string(‘Robot Framework’,’o’,’bt’) # R Framewrk
- remove_string_using_regexp(string, *patterns)[source]
使用模式匹配删除
string中的内容This keyword is otherwise identical to Remove String, but the
patternsto search for are considered to be a regular expression. See Replace String Using Regexp for more information about the regular expression syntax. That keyword can also be used if there is a need to remove only a certain number of occurrences.
- replace_string(string, search_for, replace_with, count=-1)[source]
替换串
Replaces
search_forin the givenstringwithreplace_withforcounttimes.search_foris used as a literal string. See Replace String Using Regexp if more powerful pattern matching is needed. If you need to just remove a string see Remove String.If the optional argument
countis given, only that many occurrences from left are replaced. Negativecountmeans that all occurrences are replaced (default behaviour) and zero means that nothing is done.Examples :replace_string(‘Hello, world!’,’world’,’tellus’) # Hello, tellus!replace_string(‘Hello, world!’,’l’,’’,count=1) # Helo, world!