Generic automation framework for acceptance testing and robotic process automation (RPA)
—
Robot Framework includes a comprehensive set of standard test libraries that provide keywords for common testing tasks. These libraries are available without explicit imports and cover system operations, data manipulation, time handling, and test control flow.
Core keywords available in all test suites without explicit import. Provides fundamental functionality for test control, variable handling, and basic operations.
class BuiltIn:
"""
Robot Framework's core library providing fundamental keywords.
Always available without explicit import.
"""
# Variable operations
def set_variable(self, name, *values): ...
def set_global_variable(self, name, *values): ...
def set_suite_variable(self, name, *values): ...
def set_test_variable(self, name, *values): ...
def get_variable_value(self, name, default=None): ...
def variable_should_exist(self, name, msg=None): ...
def variable_should_not_exist(self, name, msg=None): ...
# Test control
def pass_execution(self, message="", *tags): ...
def fail(self, msg=None, *tags): ...
def fatal_error(self, msg=None): ...
def skip_if(self, condition, msg=""): ...
def continue_for_loop_if(self, condition): ...
def exit_for_loop_if(self, condition): ...
# Assertions
def should_be_equal(self, first, second, msg=None, values=True): ...
def should_not_be_equal(self, first, second, msg=None, values=True): ...
def should_contain(self, item1, item2, msg=None, values=True): ...
def should_not_contain(self, item1, item2, msg=None, values=True): ...
def should_be_true(self, condition, msg=None): ...
def should_be_empty(self, item, msg=None): ...
def should_not_be_empty(self, item, msg=None): ...
# Keyword operations
def run_keyword(self, name, *args): ...
def run_keyword_and_return_status(self, name, *args): ...
def run_keyword_and_ignore_error(self, name, *args): ...
def run_keyword_if(self, condition, name, *args): ...
def run_keywords(self, *keywords): ...
# Logging and output
def log(self, message, level="INFO", html=False, console=False): ...
def log_many(self, *messages): ...
def comment(self, *messages): ...
def set_log_level(self, level): ...
# Imports
def import_library(self, name, *args): ...
def import_resource(self, path): ...
def import_variables(self, path, *args): ...
# Time operations
def sleep(self, time_, reason=None): ...
# Conversions
def convert_to_string(self, item): ...
def convert_to_integer(self, item, base=None): ...
def convert_to_number(self, item): ...
def convert_to_boolean(self, item): ...Usage Examples:
# These keywords are used directly in Robot Framework test files:
# *** Test Cases ***
# Variable Operations Example
# Set Test Variable ${name} Robot Framework
# ${value}= Get Variable Value ${name}
# Should Be Equal ${value} Robot Framework
# Variable Should Exist ${name}
# Test Control Example
# Run Keyword If ${condition} Log Condition was true
# ${status}= Run Keyword And Return Status Some Keyword
# Run Keyword And Ignore Error Might Fail Keyword
# Assertion Example
# Should Be Equal ${actual} ${expected}
# Should Contain ${text} substring
# Should Be True ${number} > 0Keywords for working with Python lists and dictionaries, providing comprehensive collection manipulation capabilities.
class Collections:
"""Keywords for handling lists and dictionaries."""
# List operations
def append_to_list(self, list_, *values): ...
def insert_into_list(self, list_, index, value): ...
def remove_from_list(self, list_, index): ...
def remove_values_from_list(self, list_, *values): ...
def reverse_list(self, list_): ...
def sort_list(self, list_): ...
def copy_list(self, list_): ...
def count_values_in_list(self, list_, value, start=0, end=None): ...
def get_from_list(self, list_, index): ...
def get_index_from_list(self, list_, value, start=0, end=None): ...
def get_length(self, item): ...
def get_slice_from_list(self, list_, start=0, end=None): ...
def list_should_contain_value(self, list_, value, msg=None): ...
def list_should_not_contain_value(self, list_, value, msg=None): ...
def lists_should_be_equal(self, list1, list2, msg=None): ...
# Dictionary operations
def set_to_dictionary(self, dictionary, *key_value_pairs): ...
def remove_from_dictionary(self, dictionary, *keys): ...
def get_from_dictionary(self, dictionary, key): ...
def get_dictionary_keys(self, dictionary): ...
def get_dictionary_values(self, dictionary): ...
def get_dictionary_items(self, dictionary): ...
def copy_dictionary(self, dictionary): ...
def dictionary_should_contain_key(self, dictionary, key, msg=None): ...
def dictionary_should_not_contain_key(self, dictionary, key, msg=None): ...
def dictionary_should_contain_value(self, dictionary, value, msg=None): ...
def dictionaries_should_be_equal(self, dict1, dict2, msg=None): ...
# Combined operations
def keep_in_dictionary(self, dictionary, *keys): ...
def pop_from_dictionary(self, dictionary, key, default=None): ...String manipulation and text processing keywords.
class String:
"""Keywords for string manipulation and text processing."""
# Basic string operations
def get_length(self, item): ...
def should_be_string(self, item, msg=None): ...
def should_not_be_string(self, item, msg=None): ...
def should_be_lowercase(self, string, msg=None): ...
def should_be_uppercase(self, string, msg=None): ...
def should_be_titlecase(self, string, msg=None): ...
# String modification
def convert_to_lowercase(self, string): ...
def convert_to_uppercase(self, string): ...
def convert_to_title_case(self, string): ...
def strip_string(self, string, characters=None, mode="both"): ...
def split_string(self, string, separator=None, max_split=-1): ...
def split_string_from_right(self, string, separator=None, max_split=-1): ...
def join_strings(self, *strings): ...
def replace_string(self, string, search_for, replace_with, count=-1): ...
def replace_string_using_regexp(self, string, pattern, replace_with, count=-1): ...
# String searching and matching
def get_substring(self, string, start, end=None): ...
def should_contain_string(self, str1, str2, msg=None, ignore_case=False): ...
def should_not_contain_string(self, str1, str2, msg=None, ignore_case=False): ...
def should_start_with(self, str1, str2, msg=None, ignore_case=False): ...
def should_end_with(self, str1, str2, msg=None, ignore_case=False): ...
def should_match_regexp(self, string, pattern, msg=None, partial=False): ...
def should_not_match_regexp(self, string, pattern, msg=None, partial=False): ...
# Regular expressions
def get_regexp_matches(self, string, pattern, *groups): ...
def get_lines_containing_string(self, string, pattern, case_insensitive=False): ...
def get_lines_matching_pattern(self, string, pattern, case_insensitive=False): ...
def get_lines_matching_regexp(self, string, pattern, partial=False): ...Keywords for operating system and file system operations.
class OperatingSystem:
"""Keywords for operating system and file system operations."""
# File operations
def create_file(self, path, content="", encoding="UTF-8"): ...
def file_should_exist(self, path, msg=None): ...
def file_should_not_exist(self, path, msg=None): ...
def file_should_be_empty(self, path, msg=None): ...
def file_should_not_be_empty(self, path, msg=None): ...
def get_file(self, path, encoding="UTF-8", encoding_errors="strict"): ...
def get_file_size(self, path): ...
def get_binary_file(self, path): ...
def append_to_file(self, path, content, encoding="UTF-8"): ...
def copy_file(self, source, destination): ...
def move_file(self, source, destination): ...
def remove_file(self, path): ...
def touch(self, path): ...
# Directory operations
def create_directory(self, path): ...
def directory_should_exist(self, path, msg=None): ...
def directory_should_not_exist(self, path, msg=None): ...
def directory_should_be_empty(self, path, msg=None): ...
def directory_should_not_be_empty(self, path, msg=None): ...
def copy_directory(self, source, destination): ...
def move_directory(self, source, destination): ...
def remove_directory(self, path, recursive=False): ...
def empty_directory(self, path): ...
def list_directory(self, path, pattern=None, absolute=False): ...
def list_files_in_directory(self, path, pattern=None, absolute=False): ...
def list_directories_in_directory(self, path, pattern=None, absolute=False): ...
def count_items_in_directory(self, path, pattern=None): ...
def count_files_in_directory(self, path, pattern=None): ...
def count_directories_in_directory(self, path, pattern=None): ...
# Path operations
def join_path(self, base, *parts): ...
def join_paths(self, base, *paths): ...
def normalize_path(self, path): ...
def split_path(self, path): ...
def split_extension(self, path): ...
def get_file_name(self, path): ...
def get_path_without_extension(self, path): ...
def should_exist(self, path, msg=None): ...
def should_not_exist(self, path, msg=None): ...
# Environment variables
def get_environment_variable(self, name, default=None): ...
def set_environment_variable(self, name, value): ...
def append_to_environment_variable(self, name, *values): ...
def remove_environment_variable(self, name): ...
def environment_variable_should_be_set(self, name, msg=None): ...
def environment_variable_should_not_be_set(self, name, msg=None): ...
def get_environment_variables(self): ...
def log_environment_variables(self, level="INFO"): ...
# Process operations
def run(self, command): ...
def run_and_return_rc(self, command): ...
def run_and_return_rc_and_output(self, command): ...Keywords for running external processes and managing subprocesses.
class Process:
"""Keywords for running processes and managing subprocesses."""
# Process execution
def start_process(self, command, *arguments, **configuration): ...
def run_process(self, command, *arguments, **configuration): ...
def is_process_running(self, handle=None): ...
def wait_for_process(self, handle=None, timeout="1 minute", on_timeout="continue"): ...
def terminate_process(self, handle=None, kill=False): ...
def terminate_all_processes(self, kill=False): ...
def get_process_id(self, handle=None): ...
def get_process_object(self, handle=None): ...
def get_process_result(self, handle=None, rc=False, stdout=False, stderr=False): ...
def switch_process(self, handle): ...
def split_command_line(self, args, posix=None): ...
def join_command_line(self, *args): ...
# Process results
def process_should_be_stopped(self, handle=None, error_message="Process is running."): ...
def process_should_be_running(self, handle=None, error_message="Process is not running."): ...Keywords for handling dates, times, and time-based operations.
class DateTime:
"""Keywords for handling date and time."""
# Current time
def get_current_date(self, time_zone="local", increment=0, result_format="timestamp", exclude_millis=False): ...
def get_time(self, format="timestamp", time_="NOW"): ...
# Date manipulation
def add_time_to_date(self, date, time, result_format=None, exclude_millis=False, date_format=None): ...
def subtract_time_from_date(self, date, time, result_format=None, exclude_millis=False, date_format=None): ...
def subtract_date_from_date(self, date1, date2, result_format="number", exclude_millis=False, date1_format=None, date2_format=None): ...
# Date conversion
def convert_date(self, date, result_format="timestamp", exclude_millis=False, date_format=None): ...
def convert_time(self, time, result_format="number", exclude_millis=False): ...
# Date formatting
def get_time_zone(self, as_string=True): ...Keywords for user interaction through dialog boxes (requires tkinter).
class Dialogs:
"""Keywords for user interaction via dialogs."""
def execute_manual_step(self, message, default_error=""): ...
def get_value_from_user(self, message, default_value="", hidden=False): ...
def get_selection_from_user(self, message, *values): ...
def pause_execution(self, message="Test execution paused. Press OK to continue."): ...Keywords for taking screenshots during test execution.
class Screenshot:
"""Keywords for taking screenshots."""
def take_screenshot(self, name="screenshot", width="800px"): ...
def take_screenshot_without_embedding(self, name="screenshot"): ...
def set_screenshot_directory(self, path): ...Keywords for parsing, modifying, and validating XML documents.
class XML:
"""Keywords for XML parsing and manipulation."""
# Parsing and saving
def parse_xml(self, source, keep_clark_notation=False): ...
def get_element(self, source, xpath="."): ...
def get_elements(self, source, xpath): ...
def get_child_elements(self, source, tag=None): ...
def save_xml(self, source, path, encoding="UTF-8"): ...
# Element operations
def get_element_text(self, source, xpath=".", normalize_whitespace=False): ...
def get_element_attribute(self, source, name, xpath=".", default=None): ...
def get_elements_texts(self, source, xpath, normalize_whitespace=False): ...
def element_text_should_be(self, source, expected, xpath=".", normalize_whitespace=False, message=None): ...
def element_text_should_match(self, source, pattern, xpath=".", normalize_whitespace=False, message=None): ...
def element_attribute_should_be(self, source, name, expected, xpath=".", message=None): ...
def element_attribute_should_match(self, source, name, pattern, xpath=".", message=None): ...
# Modification
def add_element(self, source, element, index=None, xpath="."): ...
def remove_element(self, source, xpath="", remove_tail=False): ...
def clear_element(self, source, xpath=".", clear_tail=False): ...
def copy_element(self, source, xpath="."): ...
def set_element_text(self, source, text=None, tail=None, xpath="."): ...
def set_element_attribute(self, source, name, value, xpath="."): ...
def remove_element_attribute(self, source, name, xpath="."): ...
def set_element_tag(self, source, tag, xpath="."): ...
# Structure validation
def elements_should_be_equal(self, source, expected, exclude_children=False, normalize_whitespace=False): ...
def elements_should_match(self, source, expected, exclude_children=False, normalize_whitespace=False): ...
def element_should_exist(self, source, xpath, message=None): ...
def element_should_not_exist(self, source, xpath, message=None): ...Keywords for Telnet connections and automation (requires telnetlib).
class Telnet:
"""Keywords for Telnet connections."""
def open_connection(self, host, alias=None, port=23, timeout=None, newline=None,
prompt=None, prompt_is_regexp=False, encoding="UTF-8",
encoding_errors="ignore", default_log_level="INFO"): ...
def login(self, username, password, login_prompt="login: ", password_prompt="Password: ",
login_timeout="1 minute", login_incorrect="Login incorrect"): ...
def write(self, text, loglevel=None): ...
def write_bare(self, text): ...
def write_control_character(self, character): ...
def read(self, loglevel=None): ...
def read_until(self, expected, loglevel=None): ...
def read_until_regexp(self, *expected): ...
def read_until_prompt(self, loglevel=None, strip_prompt=False): ...
def execute_command(self, command, loglevel=None, strip_prompt=False): ...
def close_connection(self, loglevel=None): ...
def close_all_connections(self): ...
def switch_connection(self, index_or_alias): ...
def get_connection(self, index_or_alias=None): ...
def get_connections(self): ...Library for Robot Framework's remote library interface.
class Remote:
"""Library for connecting to remote Robot Framework library servers."""
def __init__(self, uri="http://127.0.0.1:8270", timeout=None): ...
# All keywords are dynamically provided by the remote server
def get_keyword_names(self): ...
def run_keyword(self, name, args, kwargs): ...
def get_keyword_arguments(self, name): ...
def get_keyword_documentation(self, name): ...# Standard library names
STDLIBS = frozenset([
'BuiltIn', 'Collections', 'DateTime', 'Dialogs', 'Easter',
'OperatingSystem', 'Process', 'Remote', 'Screenshot',
'String', 'Telnet', 'XML'
])Import and Use Libraries:
*** Settings ***
Library Collections
Library String
Library OperatingSystem
Library Process
*** Test Cases ***
Collections Example
${list}= Create List first second third
Append To List ${list} fourth
${length}= Get Length ${list}
Should Be Equal As Integers ${length} 4
List Should Contain Value ${list} second
String Processing Example
${text}= Set Variable Hello World
${upper}= Convert To Uppercase ${text}
Should Be Equal ${upper} HELLO WORLD
Should Start With ${text} Hello
${words}= Split String ${text}
Should Be Equal ${words}[0] Hello
File Operations Example
Create File /tmp/test.txt Test content
File Should Exist /tmp/test.txt
${content}= Get File /tmp/test.txt
Should Be Equal ${content} Test content
Remove File /tmp/test.txt
File Should Not Exist /tmp/test.txt
Process Execution Example
${result}= Run Process echo Hello from process
Should Be Equal As Integers ${result.rc} 0
Should Be Equal ${result.stdout} Hello from process\n# Collection types
List = list
Dictionary = dict
# File system types
Path = str
FileContent = Union[str, bytes]
FileSize = int
# Process types
ProcessHandle = str
ReturnCode = int
ProcessResult = object # Has .rc, .stdout, .stderr attributes
# Date/time types
Timestamp = str # ISO format: "2024-01-01T12:00:00.000"
TimeString = str # Human readable: "1 minute 30 seconds"
TimeZone = str # "UTC", "local", etc.
# XML types
XMLElement = object # ElementTree element
XPath = str # XPath expression
# Regular expression types
Pattern = str # Regular expression pattern
RegexpMatch = object # Match resultInstall with Tessl CLI
npx tessl i tessl/pypi-robotframework