robot framerk -String
时间: 2018-08-15来源:OSCHINA
前景提要
「深度学习福利」大神带你进阶工程师,立即查看>>>
String
Library version: 3.0.4
Library scope: global
Named arguments: supported

Introduction
A test library for string manipulation and verification.
String is Robot Framework's standard library for manipulating strings (e.g. Replace String Using Regexp , Split To Lines ) and verifying their contents (e.g. Should Be String ).
Following keywords from BuiltIn library can also be used with strings: Catenate Get Length Length Should Be Should (Not) Be Empty Should (Not) Be Equal (As Strings/Integers/Numbers) Should (Not) Match (Regexp) Should (Not) Contain Should (Not) Start With Should (Not) End With Convert To String Convert To Bytes
Shortcuts
Convert To Lowercase · Convert To Uppercase · Decode Bytes To String · Encode String To Bytes · Fetch From Left · Fetch From Right · Generate Random String · Get Line · Get Line Count · Get Lines Containing String · Get Lines Matching Pattern · Get Lines Matching Regexp · Get Regexp Matches · Get Substring · Remove String · Remove String Using Regexp · Replace String · Replace String Using Regexp · Should Be Byte String · Should Be Lowercase · Should Be String · Should Be Titlecase · Should Be Unicode String · Should Be Uppercase · Should Not Be String · Split String · Split String From Right · Split String To Characters · Split To Lines · Strip String
Keywords
Keyword Arguments Documentation
Convert To Lowercase string Converts string to lowercase.
Examples:
${str1} = Convert To Lowercase ABC
${str2} = Convert To Lowercase 1A2c3D
Should Be Equal Should Be Equal
${str1} ${str2}
abc 1a2c3d

New in Robot Framework 2.8.6.
Convert To Uppercase string Converts string to uppercase.
Examples:
${str1} = Convert To Uppercase abc
${str2} = Convert To Uppercase 1a2C3d
Should Be Equal Should Be Equal
${str1} ${str2}
ABC 1A2C3D

New in Robot Framework 2.8.6.
Decode Bytes To String bytes, encoding,errors=strict Decodes the given bytes to a Unicode string using the given encoding .
errors argument controls what to do if decoding some bytes fails. All values accepted by decode method 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 decoded replace : replace characters that cannot be decoded with a replacement character
Examples:

${string} = ${string} =
Decode Bytes To String Decode Bytes To String
${bytes} ${bytes}
UTF-8 ASCII
errors=ignore

Use Encode String To Bytes if you need to convert Unicode strings to byte strings, and Convert To String in BuiltIn if you need to convert arbitrary objects to Unicode strings.
Encode String To Bytes string, encoding,errors=strict Encodes the given Unicode string to bytes using the given encoding .
errors argument controls what to do if encoding some characters fails. All values accepted by encode method 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 encoded replace : replace characters that cannot be encoded with a replacement character
Examples:

${bytes} = ${bytes} =
Encode String To Bytes Encode String To Bytes
${string} ${string}
UTF-8 ASCII
errors=ignore

Use Convert To Bytes in BuiltIn if 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 in BuiltIn if you need to convert arbitrary objects to Unicode.
Fetch From Left string, marker Returns contents of the string before the first occurrence of marker .
If the marker is not found, whole string is returned.
See also Fetch From Right , Split String and Split String From Right .
Fetch From Right string, marker Returns contents of the string after the last occurrence of marker .
If the marker is not found, whole string is returned.
See also Fetch From Left , Split String and Split String From Right .
Generate Random String length=8, chars=[LETTERS][NUMBERS] Generates a string with a desired length from the given chars .
The population sequence chars contains 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 from a to z .
[UPPER] Uppercase ASCII characters from A to Z .
[LETTERS] [NUMBERS]
Lowercase and uppercase ASCII characters. Numbers from 0 to 9.

Examples:
${ret} = Generate Random String
${low} = ${bin} = ${hex} =
Generate Random String Generate Random String Generate Random String
12 8 4
[LOWER] 01 [NUMBERS]abcdef

Get Line string, line_number Returns the specified line from the given string .
Line numbering starts from 0 and it is possible to use negative indices to refer to lines from the end. The line is returned without the newline character.
Examples:

${first} = ${2nd last} =
Get Line Get Line
${string} ${string}
0 -2

Use Split To Lines if all lines are needed.
Get Line Count string Returns and logs the number of lines in the given string.
Get Lines Containing String string, pattern,case_insensitive=False Returns lines of the given string that contain the pattern .
The pattern is always considered to be a normal string, not a glob or regexp pattern. A line matches if the pattern is found anywhere on it.
The match is case-sensitive by default, but giving case_insensitive a true value makes it case-insensitive. The value is considered true if it is a non-empty string that is not equal to false , none or no . If the value is not a string, its truth value is got directly in Python. Considering none false is new in RF 3.0.3.
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:

${lines} = ${ret} =
Get Lines Containing String Get Lines Containing String
${result} ${ret}
An example FAIL
case-insensitive

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 Returns lines of the given string that match the pattern .
The pattern is a glob pattern where:
* matches everything
? matches any single character
[chars] [!chars]
matches any character inside square brackets (e.g. [abc] matches either a , b or c ) matches any character not inside square brackets

A line matches only if it matches the pattern fully.
The match is case-sensitive by default, but giving case_insensitive a true value makes it case-insensitive. The value is considered true if it is a non-empty string that is not equal to false , none or no . If the value is not a string, its truth value is got directly in Python. Considering none false is new in RF 3.0.3.
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:

${lines} = ${ret} =
Get Lines Matching Pattern Get Lines Matching Pattern
${result} ${ret}
Wild???? example FAIL: *
case_insensitive=true

See Get Lines Matching Regexp if you need more complex patterns and Get Lines Containing String if searching literal strings is enough.
Get Lines Matching Regexp string, pattern,partial_match=False Returns lines of the given string that match the regexp pattern .
See BuiltIn.Should Match Regexp for more information about Python regular expression syntax in general and how to use it in Robot Framework test data in particular.
By default lines match only if they match the pattern fully, but partial matching can be enabled by giving the partial_match argument a true value. The value is considered true if it is a non-empty string that is not equal to false , none or no . If the value is not a string, its truth value is got directly in Python. Considering none false is new in RF 3.0.3.
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:

${lines} = ${lines} = ${ret} =
Get Lines Matching Regexp Get Lines Matching Regexp Get Lines Matching Regexp
${result} ${result} ${ret}
Reg\\w{3} example Reg\\w{3} example (?i)FAIL: .*
partial_match=true

See Get Lines Matching Pattern and Get Lines Containing String if you do not need full regular expression powers (and complexity).
partial_match argument is new in Robot Framework 2.9. In earlier versions exact match was always required.
Get Regexp Matches string, pattern,*groups Returns a list of all non-overlapping matches in the given string.
string is the string to find matches from and pattern is 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 test 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:

${no match} = ${matches} = ${one group} = ${named group} = ${two groups} =
Get Regexp Matches Get Regexp Matches Get Regexp Matches Get Regexp Matches Get Regexp Matches
the string the string the string the string the string
xxx t.. t(..) t(?P<name>..) t(.)(.)
1 name 1
2

=> ${no match} = [] ${matches} = ['the', 'tri'] ${one group} = ['he', 'ri'] ${named group} = ['he', 'ri'] ${two groups} = [('h', 'e'), ('r', 'i')]
New in Robot Framework 2.9.
Get Substring string, start,end=None Returns a substring from start index to end index.
The start index is inclusive and end is exclusive. Indexing starts from 0, and it is possible to use negative indices to refer to characters from the end.
Examples:
${ignore first} = Get Substring ${string} 1
${ignore last} = ${5th to 10th} = ${first two} = ${last two} =
Get Substring Get Substring Get Substring Get Substring
${string} ${string} ${string} ${string}
4 -2
-1 10 1

Remove String string, *removables Removes all removables from the given string .
removables are 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:

${str} = Should Be Equal ${str} = Should Be Equal
Remove String ${str} Remove String ${str}
Robot Framework Robot Frame Robot Framework R Framewrk
work o
bt

New in Robot Framework 2.8.2.
Remove String Using Regexp string, *patterns Removes patterns from the given string .
This keyword is otherwise identical to Remove String , but the patterns to 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.
New in Robot Framework 2.8.2.
Replace String string, search_for,replace_with,count=-1 Replaces search_for in the given string with replace_with .
search_for is 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 count is given, only that many occurrences from left are replaced. Negative count means that all occurrences are replaced (default behaviour) and zero means that nothing is done.
A modified version of the string is returned and the original string is not altered.
Examples:

${str} = Should Be Equal ${str} = Should Be Equal
Replace String ${str} Replace String ${str}
Hello, world! Hello, tellus! Hello, world! Helo, world!
world l
tellus ${EMPTY}
count=1

Replace String Using Regexp string, pattern,replace_with,count=-1 Replaces pattern in the given string with replace_with .
This keyword is otherwise identical to Replace String , but the pattern to search for is considered to be a 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 test data in particular.
If you need to just remove a string see Remove String Using Regexp .
Examples:

${str} = ${str} =
Replace String Using Regexp Replace String Using Regexp
${str} ${str}
20\\d\\d-\\d\\d-\\d\\d (Hello|Hi)
<DATE> ${EMPTY}
count=1

Should Be Byte String item, msg=None Fails if the given item is not a byte string.
Use Should Be Unicode String if you want to verify the item is a Unicode string, or Should Be String if both Unicode and byte strings are fine. See Should Be String for more details about Unicode strings and byte strings.
The default error message can be overridden with the optional msg argument.
Should Be Lowercase string, msg=None Fails if the given string is not in lowercase.
For example, 'string' and 'with specials!' would pass, and 'String' , '' and ' ' would fail.
The default error message can be overridden with the optional msg argument.
See also Should Be Uppercase and Should Be Titlecase .
Should Be String item, msg=None Fails if the given item is not a string.
With Python 2, except with IronPython, this keyword passes regardless is the item a Unicode string or a byte string. Use Should Be Unicode String or Should Be Byte String if you want to restrict the string type. Notice that with Python 2, except with IronPython, 'string' creates a byte string and u'unicode' must be used to create a Unicode string.
With Python 3 and IronPython, this keyword passes if the string is a Unicode string but fails if it is bytes. Notice that with both Python 3 and IronPython, 'string' creates a Unicode string, and b'bytes' must be used to create a byte string.
The default error message can be overridden with the optional msg argument.
Should Be Titlecase string, msg=None Fails if given string is not title.
string is a titlecased string if there is at least one character in it, uppercase characters only follow uncased characters and lowercase characters only cased ones.
For example, 'This Is Title' would pass, and 'Word In UPPER' , 'Word In lower' , '' and ' ' would fail.
The default error message can be overridden with the optional msg argument.
See also Should Be Uppercase and Should Be Lowercase .
Should Be Unicode String item, msg=None Fails if the given item is not a Unicode string.
Use Should Be Byte String if you want to verify the item is a byte string, or Should Be String if both Unicode and byte strings are fine. See Should Be String for more details about Unicode strings and byte strings.
The default error message can be overridden with the optional msg argument.
Should Be Uppercase string, msg=None Fails if the given string is not in uppercase.
For example, 'STRING' and 'WITH SPECIALS!' would pass, and 'String' , '' and ' ' would fail.
The default error message can be overridden with the optional msg argument.
See also Should Be Titlecase and Should Be Lowercase .
Should Not Be String item, msg=None Fails if the given item is a string.
See Should Be String for more details about Unicode strings and byte strings.
The default error message can be overridden with the optional msg argument.
Split String string,separator=None,max_split=-1 Splits the string using separator as a delimiter string.
If a separator is not given, any whitespace string is a separator. In that case also possible consecutive whitespace as well as leading and trailing whitespace is ignored.
Split words are returned as a list. If the optional max_split is given, at most max_split splits are done, and the returned list will have maximum max_split + 1 elements.
Examples:

@{words} = @{words} = ${pre}
Split String Split String ${post} =
${string} ${string} Split String
,${SPACE} ${string}
::
1

See Split String From Right if you want to start splitting from right, and Fetch From Left and Fetch From Right if you only want to get first/last part of the string.
Split String From Right string,separator=None,max_split=-1 Splits the string using separator starting from right.
Same as Split String , but splitting is started from right. This has an effect only when max_split is given.
Examples:

${first} ${rest}
${rest} = ${last} =
Split String Split String From Right
${string} ${string}
- -
1 1

Split String To Characters string Splits the given string to characters.
Example:

@{characters} =
Split String To Characters
${string}

Split To Lines Strip String
string, start=0,end=None string, mode=both,characters=None
Splits the given string to lines.
It is possible to get only a selection of lines from start to end so that start index is inclusive and end is exclusive. Line numbering starts from 0, and it is possible to use negative indices to refer to lines from the end.
Lines are returned without the newlines. The number of returned lines is automatically logged.
Examples:
@{lines} = Split To Lines ${manylines}
@{ignore first} = Split To Lines ${manylines} 1
@{ignore last} = @{5th to 10th} = @{first two} = @{last two} =
Split To Lines Split To Lines Split To Lines Split To Lines
${manylines} ${manylines} ${manylines} ${manylines}
4 -2
-1 10 1

Use Get Line if you only need to get a single line. Remove leading and/or trailing whitespaces from the given string.
mode is either left to remove leading characters, right to remove trailing characters, both (default) to remove the characters from both sides of the string or none to return the unmodified string.
If the optional characters is given, it must be a string and the characters in the string will be stripped in the string. Please note, that this is not a substring to be removed but a list of characters, see the example below.
Examples:
${stripped}= Strip String ${SPACE}Hello${SPACE}
Should Be Equal ${stripped} Hello
${stripped}= Strip String ${SPACE}Hello${SPACE} mode=left
Should Be Equal ${stripped}= Should Be Equal
${stripped} Strip String ${stripped}
Hello${SPACE} aabaHelloeee Hello
characters=abe

New in Robot Framework 3.0.

Altogether 30 keywords.
Generated by Libdoc on 2018-04-25 23:41:29.

图书馆版本: 3.0.4
图书馆范围: 全球
命名参数: 支持的

介绍
用于字符串操作和验证的测试库。
String 是Robot Framework的标准库,用于操作字符串(例如, 使用Regexp替换字符串 , 拆分为行 )并验证其内容(例如, 应该是字符串 )。
来自 BuiltIn 库的以下关键字也可以与字符串一起使用: 链状 得到长度 应该是长度 应该(不)是空的 应该(不)是平等的(如字符串/整数/数字) 应该(不)匹配(Regexp) 应该(不)包含 应该(不)开始 应该(不)结束 转换为字符串 转换为字节
快捷键
转换为小写 · 转换为大写 · 解码字节字符串 · 编码字符串的字节 · 取左起 · 取从右 · 生成随机字符串 · 找线 · 获取行计数 · 包含字符串获取行 · 获取线路匹配模式 · 得到正确的行匹配正则表达式 · 获取正则表达式匹配 · 获取子字符串 · 删除字符串 · 使用正则表达式删除字符串 · 替换字符串 · 使用正则表达式替换字符串 · 应该是字节字符串 · 应该是小写 · 应该是字符串 · 应该是标题 · 应该是Unicode字符串 · 应该全部是大写 · 不应该是字符串 · 分割字符串 · 分割字符串从右 · 分割字符串的字符 · 斯普利特行 · 地带字符串
关键词
关键词 参数 文档
转换为小写 串 将字符串转换为小写。
例子:
$ {str1} = 转换为小写 ABC
$ {str2} = 转换为小写 1A2c3D
应该是平等的 应该是平等的
$ {} STR1 $ {} STR2
ABC 1a2c3d

Robot Framework 2.8.6中的新功能。
转换为大写 串 将字符串转换为大写。
例子:
$ {str1} = 转换为大写 ABC
$ {str2} = 转换为大写 1a2C3d
应该是平等的 应该是平等的
$ {} STR1 $ {} STR2
ABC 1A2C3D

Robot Framework 2.8.6中的新功能。
将字节解码为字符串 bytes , encoding , errors = strict 使用给定的解码将给定 bytes 的Unicode字符串解码 encoding 。
errors 如果解码某些字节失败,参数控制该怎么做。 decode Python中方法接受的所有值都是有效的,但实际上以下值最有用: strict :如果无法解码字符,则失败(默认) ignore :忽略无法解码的字符 replace :替换无法使用替换字符解码的字符
例子:

$ {string} = $ {string} =
将字节解码为字符串 将字节解码为字符串
$ {}字节 $ {}字节
UTF-8 ASCII
错误=忽略

如果需要将Unicode字符串转换为字节字符串,请使用 Encode String To Bytes; 如果需要将任意对象 转换为 Unicode字符串,请使用 Convert To String in BuiltIn 。
将字符串编码为字节 字符串 , 编码 , 错误=严格 string 使用给定的代码将给定的Unicode编码为字节 encoding 。
errors 参数控制在编码某些字符失败时如何处理。 encode Python中方法接受的所有值都是有效的,但实际上以下值最有用: strict :如果无法编码字符,则失败(默认) ignore :忽略无法编码的字符 replace :替换无法使用替换字符编码的字符
例子:

$ {bytes} = $ {bytes} =
将字符串编码为字节 将字符串编码为字节
$ {}字符串 $ {}字符串
UTF-8 ASCII
错误=忽略

Use Convert To Bytes in BuiltIn if 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 in BuiltIn if you need to convert arbitrary objects to Unicode.
Fetch From Left string , marker Returns contents of the string before the first occurrence of marker .
If the marker is not found, whole string is returned.
See also Fetch From Right , Split String and Split String From Right .
Fetch From Right string , marker Returns contents of the string after the last occurrence of marker .
If the marker is not found, whole string is returned.
See also Fetch From Left , Split String and Split String From Right .
Generate Random String length=8 , chars=[LETTERS][NUMBERS] Generates a string with a desired length from the given chars .
The population sequence chars contains 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 from a to z .
[UPPER] Uppercase ASCII characters from A to Z .
[LETTERS] [NUMBERS]
Lowercase and uppercase ASCII characters. Numbers from 0 to 9.

Examples:
${ret} = Generate Random String
${low} = ${bin} = ${hex} =
Generate Random String Generate Random String Generate Random String
12 8 4
[LOWER] 01 [NUMBERS]abcdef

Get Line string , line_number Returns the specified line from the given string .
Line numbering starts from 0 and it is possible to use negative indices to refer to lines from the end. The line is returned without the newline character.
Examples:

${first} = ${2nd last} =
Get Line Get Line
${string} ${string}
0 -2

Use Split To Lines if all lines are needed.
Get Line Count string Returns and logs the number of lines in the given string.
Get Lines Containing String string , pattern , case_insensitive=False Returns lines of the given string that contain the pattern .
The pattern is always considered to be a normal string, not a glob or regexp pattern. A line matches if the pattern is found anywhere on it.
The match is case-sensitive by default, but giving case_insensitive a true value makes it case-insensitive. The value is considered true if it is a non-empty string that is not equal to false , none or no . If the value is not a string, its truth value is got directly in Python. Considering none false is new in RF 3.0.3.
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:

${lines} = ${ret} =
Get Lines Containing String Get Lines Containing String
${result} ${ret}
An example FAIL
case-insensitive

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 Returns lines of the given string that match the pattern .
The pattern is a glob pattern where:
* matches everything
? matches any single character
[chars] [!chars]
matches any character inside square brackets (e.g. [abc] matches either a , b or c ) matches any character not inside square brackets

A line matches only if it matches the pattern fully.
The match is case-sensitive by default, but giving case_insensitive a true value makes it case-insensitive. The value is considered true if it is a non-empty string that is not equal to false , none or no . If the value is not a string, its truth value is got directly in Python. Considering none false is new in RF 3.0.3.
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:

${lines} = ${ret} =
Get Lines Matching Pattern Get Lines Matching Pattern
${result} ${ret}
Wild???? example FAIL: *
case_insensitive=true

See Get Lines Matching Regexp if you need more complex patterns and Get Lines Containing String if searching literal strings is enough.
Get Lines Matching Regexp string , pattern , partial_match=False Returns lines of the given string that match the regexp pattern .
See BuiltIn.Should Match Regexp for more information about Python regular expression syntax in general and how to use it in Robot Framework test data in particular.
By default lines match only if they match the pattern fully, but partial matching can be enabled by giving the partial_match argument a true value. The value is considered true if it is a non-empty string that is not equal to false , none or no . If the value is not a string, its truth value is got directly in Python. Considering none false is new in RF 3.0.3.
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:

${lines} = ${lines} = ${ret} =
Get Lines Matching Regexp Get Lines Matching Regexp Get Lines Matching Regexp
${result} ${result} ${ret}
Reg\\w{3} example Reg\\w{3} example (?i)FAIL: .*
partial_match=true

See Get Lines Matching Pattern and Get Lines Containing String if you do not need full regular expression powers (and complexity).
partial_match argument is new in Robot Framework 2.9. In earlier versions exact match was always required.
Get Regexp Matches string , pattern , *groups Returns a list of all non-overlapping matches in the given string.
string is the string to find matches from and pattern is 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 test 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:

${no match} = ${matches} = ${one group} = ${named group} = ${two groups} =
Get Regexp Matches Get Regexp Matches Get Regexp Matches Get Regexp Matches Get Regexp Matches
the string the string the string the string the string
xxx t.. t(..) t(?P<name>..) t(.)(.)
1 name 1
2

=> ${no match} = [] ${matches} = ['the', 'tri'] ${one group} = ['he', 'ri'] ${named group} = ['he', 'ri'] ${two groups} = [('h', 'e'), ('r', 'i')]
New in Robot Framework 2.9.
Get Substring string , start , end=None Returns a substring from start index to end index.
The start index is inclusive and end is exclusive. Indexing starts from 0, and it is possible to use negative indices to refer to characters from the end.
Examples:
${ignore first} = Get Substring ${string} 1
${ignore last} = ${5th to 10th} = ${first two} = ${last two} =
Get Substring Get Substring Get Substring Get Substring
${string} ${string} ${string} ${string}
4 -2
-1 10 1

Remove String string , *removables Removes all removables from the given string .
removables are 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:

${str} = Should Be Equal ${str} = Should Be Equal
Remove String ${str} Remove String ${str}
Robot Framework Robot Frame Robot Framework R Framewrk
work o
bt

New in Robot Framework 2.8.2.
Remove String Using Regexp string , *patterns Removes patterns from the given string .
This keyword is otherwise identical to Remove String , but the patterns to 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.
New in Robot Framework 2.8.2.
Replace String string , search_for , replace_with , count=-1 Replaces search_for in the given string with replace_with .
search_for is 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 count is given, only that many occurrences from left are replaced. Negative count means that all occurrences are replaced (default behaviour) and zero means that nothing is done.
A modified version of the string is returned and the original string is not altered.
Examples:

${str} = Should Be Equal ${str} = Should Be Equal
Replace String ${str} Replace String ${str}
Hello, world! Hello, tellus! Hello, world! Helo, world!
world l
tellus ${EMPTY}
count=1

Replace String Using Regexp string , pattern , replace_with , count=-1 Replaces pattern in the given string with replace_with .
This keyword is otherwise identical to Replace String , but the pattern to search for is considered to be a 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 test data in particular.
If you need to just remove a string see Remove String Using Regexp .
Examples:

${str} = ${str} =
Replace String Using Regexp Replace String Using Regexp
${str} ${str}
20\\d\\d-\\d\\d-\\d\\d (Hello|Hi)
<DATE> ${EMPTY}
count=1

Should Be Byte String item , msg=None Fails if the given item is not a byte string.
Use Should Be Unicode String if you want to verify the item is a Unicode string, or Should Be String if both Unicode and byte strings are fine. See Should Be String for more details about Unicode strings and byte strings.
The default error message can be overridden with the optional msg argument.
Should Be Lowercase string , msg=None Fails if the given string is not in lowercase.
For example, 'string' and 'with specials!' would pass, and 'String' , '' and ' ' would fail.
The default error message can be overridden with the optional msg argument.
See also Should Be Uppercase and Should Be Titlecase .
Should Be String item , msg=None Fails if the given item is not a string.
With Python 2, except with IronPython, this keyword passes regardless is the item a Unicode string or a byte string. Use Should Be Unicode String or Should Be Byte String if you want to restrict the string type. Notice that with Python 2, except with IronPython, 'string' creates a byte string and u'unicode' must be used to create a Unicode string.
With Python 3 and IronPython, this keyword passes if the string is a Unicode string but fails if it is bytes. Notice that with both Python 3 and IronPython, 'string' creates a Unicode string, and b'bytes' must be used to create a byte string.
The default error message can be overridden with the optional msg argument.
Should Be Titlecase string , msg=None Fails if given string is not title.
string is a titlecased string if there is at least one character in it, uppercase characters only follow uncased characters and lowercase characters only cased ones.
For example, 'This Is Title' would pass, and 'Word In UPPER' , 'Word In lower' , '' and ' ' would fail.
The default error message can be overridden with the optional msg argument.
See also Should Be Uppercase and Should Be Lowercase .
Should Be Unicode String item , msg=None Fails if the given item is not a Unicode string.
Use Should Be Byte String if you want to verify the item is a byte string, or Should Be String if both Unicode and byte strings are fine. See Should Be String for more details about Unicode strings and byte strings.
The default error message can be overridden with the optional msg argument.
Should Be Uppercase string , msg=None Fails if the given string is not in uppercase.
For example, 'STRING' and 'WITH SPECIALS!' would pass, and 'String' , '' and ' ' would fail.
The default error message can be overridden with the optional msg argument.
See also Should Be Titlecase and Should Be Lowercase .
Should Not Be String item , msg=None Fails if the given item is a string.
See Should Be String for more details about Unicode strings and byte strings.
The default error message can be overridden with the optional msg argument.
Split String string , separator=None , max_split=-1 Splits the string using separator as a delimiter string.
If a separator is not given, any whitespace string is a separator. In that case also possible consecutive whitespace as well as leading and trailing whitespace is ignored.
Split words are returned as a list. If the optional max_split is given, at most max_split splits are done, and the returned list will have maximum max_split + 1 elements.
Examples:

@{words} = @{words} = ${pre}
Split String Split String ${post} =
${string} ${string} Split String
,${SPACE} ${string}
::
1

See Split String From Right if you want to start splitting from right, and Fetch From Left and Fetch From Right if you only want to get first/last part of the string.
Split String From Right string , separator=None , max_split=-1 Splits the string using separator starting from right.
Same as Split String , but splitting is started from right. This has an effect only when max_split is given.
Examples:

${first} ${rest}
${rest} = ${last} =
Split String Split String From Right
${string} ${string}
- -
1 1

Split String To Characters string Splits the given string to characters.
Example:

@{characters} =
Split String To Characters
${string}

Split To Lines 带状线
string , start=0 , end=None string , mode = both , characters = None
Splits the given string to lines.
It is possible to get only a selection of lines from start to end so that start index is inclusive and end is exclusive. Line numbering starts from 0, and it is possible to use negative indices to refer to lines from the end.
Lines are returned without the newlines. The number of returned lines is automatically logged.
Examples:
@{lines} = Split To Lines ${manylines}
@ {忽略第一} = 拆分为线 $ {} manylines 1
@ {ignore last} = @ {5th to 10th} = @ {前两个} = @ {last two} =
拆分为线 拆分为线 拆分为线 拆分为线
$ {} manylines $ {} manylines $ {} manylines $ {} manylines
4 -2
-1 10 1

如果您只需要获得一行,请使用 获取 行。 从给定字符串中删除前导和/或尾随空格。
mode 要么 left 删除前导字符, right 要删除尾随字符, both (默认)删除字符串两边的字符或 none 返回未修改的字符串。
如果 characters 给出了可选项,则它必须是字符串,并且字符串中的字符将在字符串中被删除。请注意,这不是要删除的子字符串,而是字符列表,请参阅下面的示例。
例子:
$ {剥离} = 带状线 $ {空白}你好$ {空白}
应该是平等的 $ {}剥离 你好
$ {剥离} = 带状线 $ {空白}你好$ {空白} 模式=左
应该是平等的 $ {剥离} = 应该是平等的
$ {}剥离 带状线 $ {}剥离
尊敬的$ {空白} aabaHelloeee 你好
字符数=阿部

Robot Framework 3.0中的新功能。

共有30个关键字。
由 Libdoc 于2018-04-25 23:41:29 生成。

科技资讯:

科技学院:

科技百科:

科技书籍:

网站大全:

软件大全:

热门排行