StringUtils Documentation
*** Settings ***
Library StringUtils
*** Test Cases ***
Example
[Documentation] Demonstrates using StringUtils
# add your keyword calls here
Introduction
String utilities library for Robot Framework.
This library provides comprehensive string operations including:
- String manipulation and transformation
- Pattern matching and validation
- Encoding and hashing
- Text formatting and templating
- Data extraction and parsing
Arguments
Return Type
strDocumentation
Capitalize the first letter of each word in a string.
Arguments:
text: Input string to capitalize
Returns: String with each word capitalized
Example:
*** Settings *** Library StringUtils *** Test Cases *** Capitalize Text Example ${result} Capitalize Words hello world Should Be Equal ${result} Hello World
Arguments
Return Type
strDocumentation
Remove whitespace from a string.
Arguments:
text: Input stringmode: Removal mode - "all" (remove all), "leading" (remove leading),
"trailing" (remove trailing), "both" (remove both ends)
Returns: String with whitespace removed
Example:
*** Settings *** Library StringUtils *** Test Cases *** Remove Whitespace Example ${result} Remove Whitespace " hello world " mode=both Should Be Equal ${result} hello world
Arguments
Return Type
List[int]Documentation
Extract all numbers from a string.
Arguments:
text: Input string containing numbers
Returns: List of extracted integers
Example:
*** Settings *** Library StringUtils *** Test Cases *** Extract Numbers Example ${numbers} Extract Numbers Price: $99.99, Quantity: 5 Should Contain ${numbers} ${99} Should Contain ${numbers} ${5}
Arguments
Return Type
List[str]Documentation
Extract all email addresses from a string.
Arguments:
text: Input string containing email addresses
Returns: List of extracted email addresses
Example:
*** Settings *** Library StringUtils *** Test Cases *** Extract Emails Example ${emails} Extract Emails Contact: john@example.com or jane@test.org Should Contain ${emails} john@example.com Should Contain ${emails} jane@test.org
Arguments
Return Type
boolDocumentation
Validate if a string is a valid URL.
Arguments:
url: URL string to validate
Returns: True if valid URL, False otherwise
Example:
*** Settings *** Library StringUtils *** Test Cases *** Validate URL Example ${valid} Validate Url https://example.com Should Be True ${valid}
Arguments
Return Type
strDocumentation
Mask sensitive data, showing only first few characters.
Arguments:
text: Text to maskvisible_chars: Number of characters to keep visible (default: 4)
Returns: Masked string
Example:
*** Settings *** Library StringUtils *** Test Cases *** Mask Sensitive Data Example ${masked} Mask Sensitive Data secret12345 visible_chars=3 Should Start With ${masked} sec Should Contain ${masked} *
Arguments
Return Type
strDocumentation
Generate hash of a string.
Arguments:
text: Text to hashalgorithm: Hash algorithm - "md5", "sha1", "sha256" (default)
Returns: Hexadecimal hash string
Example:
*** Settings *** Library StringUtils *** Test Cases *** Hash String Example ${hash} Hash String password123 algorithm=sha256 Should Not Be Empty ${hash} Length Should Be ${hash} ${64}
Arguments
Return Type
strDocumentation
Encode string to Base64.
Arguments:
text: Text to encode
Returns: Base64 encoded string
Example:
*** Settings *** Library StringUtils *** Test Cases *** Encode Base64 Example ${encoded} Encode Base64 Hello World Should Not Be Empty ${encoded}
Arguments
Return Type
strDocumentation
Decode Base64 string.
Arguments:
encoded_text: Base64 encoded string
Returns: Decoded string
Example:
*** Settings *** Library StringUtils *** Test Cases *** Decode Base64 Example ${decoded} Decode Base64 SGVsbG8gV29ybGQ= Should Be Equal ${decoded} Hello World
Arguments
Return Type
strDocumentation
Replace text matching a regex pattern.
Arguments:
text: Input textpattern: Regular expression patternreplacement: Replacement stringcase_sensitive: Whether pattern matching is case sensitive (default: True)
Returns: Text with replacements applied
Example:
*** Settings *** Library StringUtils *** Test Cases *** Replace Pattern Example ${result} Replace Pattern Hello 123 World \d+ NUMBER Should Be Equal ${result} Hello NUMBER World
Arguments
Return Type
List[str]Documentation
Split string into a list.
Arguments:
text: Text to splitseparator: Separator string (default: whitespace)max_split: Maximum number of splits (default: -1 for unlimited)
Returns: List of strings
Example:
*** Settings *** Library StringUtils *** Test Cases *** Split String Example ${parts} Split String apple,banana,cherry separator=, Should Contain ${parts} apple Should Contain ${parts} banana Should Contain ${parts} cherry
Arguments
Return Type
strDocumentation
Join list of strings with a separator.
Arguments:
strings: List of strings to joinseparator: Separator string (default: space)
Returns: Joined string
Example:
*** Settings *** Library StringUtils *** Test Cases *** Join Strings Example @{items} Create List apple banana cherry ${result} Join Strings ${items} separator=, Should Be Equal ${result} apple,banana,cherry
Arguments
Return Type
strDocumentation
Format a string template with variables.
Arguments:
template: Template string with {variable} placeholderskwargs: Variable name-value pairs
Returns: Formatted string
Example:
*** Settings *** Library StringUtils *** Test Cases *** Format Template Example ${result} Format Template Hello {name}, you are {age} years old ... name=John age=30 Should Be Equal ${result} Hello John, you are 30 years old
Arguments
Return Type
intDocumentation
Count occurrences of a substring in text.
Arguments:
text: Text to search insubstring: Substring to countcase_sensitive: Whether search is case sensitive (default: True)
Returns: Number of occurrences
Example:
*** Settings *** Library StringUtils *** Test Cases *** Count Occurrences Example ${count} Count Occurrences hello hello world hello Should Be Equal As Integers ${count} ${2}
Arguments
Return Type
strDocumentation
Truncate string to maximum length.
Arguments:
text: Text to truncatemax_length: Maximum lengthsuffix: Suffix to append if truncated (default: "...")
Returns: Truncated string
Example:
*** Settings *** Library StringUtils *** Test Cases *** Truncate String Example ${result} Truncate String This is a very long text 10 Should Be Equal ${result} This is a...
Arguments
Return Type
strDocumentation
Pad string to specified width.
Arguments:
text: Text to padwidth: Target widthpadding: Padding character (default: space)align: Alignment - "left", "right", or "center" (default: left)
Returns: Padded string
Example:
*** Settings *** Library StringUtils *** Test Cases *** Pad String Example ${result} Pad String hello 10 align=right Should Be Equal ${result} ${SPACE * 5}hello
Arguments
Return Type
strDocumentation
Reverse a string.
Arguments:
text: Text to reverse
Returns: Reversed string
Example:
*** Settings *** Library StringUtils *** Test Cases *** Reverse String Example ${result} Reverse String hello Should Be Equal ${result} olleh
Arguments
Return Type
strDocumentation
Remove duplicate words/parts from a string.
Arguments:
text: Text to processseparator: Separator to split by (default: space)
Returns: String with duplicates removed
Example:
*** Settings *** Library StringUtils *** Test Cases *** Remove Duplicates Example ${result} Remove Duplicates apple banana apple cherry Should Be Equal ${result} apple banana cherry
Arguments
Return Type
boolDocumentation
Validate phone number format.
Arguments:
phone: Phone number stringcountry: Country code for validation (default: US)
Returns: True if valid format, False otherwise
Example:
*** Settings *** Library StringUtils *** Test Cases *** Validate Phone Number Example ${valid} Validate Phone Number +1-555-123-4567 Should Be True ${valid}
Arguments
Return Type
Optional[Dict[str, Any]]Documentation
Extract and parse JSON object from text.
Arguments:
text: Text containing JSON
Returns: Parsed JSON dictionary or None if not found
Example:
*** Settings *** Library StringUtils *** Test Cases *** Extract JSON From Text Example ${json} Extract Json From Text Data: {"name": "John", "age": 30} Should Be Equal ${json}[name] John Should Be Equal As Integers ${json}[age] ${30}
Arguments
Return Type
strDocumentation
Generate a random string.
Arguments:
length: Length of string (default: 10)include_uppercase: Include uppercase letters (default: True)include_lowercase: Include lowercase letters (default: True)include_digits: Include digits (default: True)include_special: Include special characters (default: False)
Returns: Random string
Example:
*** Settings *** Library StringUtils *** Test Cases *** Generate Random String Example ${random} Generate Random String length=16 include_special=True Length Should Be ${random} ${16} Should Match Regexp ${random} .+
Need Help?
Found an issue or have a feature request for this library? Let the maintainers know by opening a new GitHub issue. Please include environment details and relevant log output to help us reproduce the problem.