Keywords

Robot Framework Keywords: Built-in, Library and User Keywords Explained

Connected command blocks representing a sequence of keywords

Robot Framework keywords are the building blocks of every test and task. Each step in a test case is a keyword call with arguments, and keywords can come from the BuiltIn library, from external libraries, from your own Python code or from user keywords written directly in test data.

Three Sources of Keywords

Understanding where a keyword comes from explains how to find its documentation, how to fix a “No keyword with name found” error and where new functionality should be added. Every keyword falls into one of three groups.

TypeDefined inExample
Built-in keywordsThe BuiltIn library, always availableLog, Should Be Equal, Set Variable
Library keywordsStandard or external libraries, imported in SettingsOpen Browser, Create List, GET
User keywordsKeywords sections in suite or resource filesLog In As, Add Product To Cart

Built-in Keywords You Will Use Daily

BuiltIn is imported automatically and covers logging, verification, variables and flow control. Knowing its most common keywords saves time, because many small tasks need no extra library at all.

  • Log and Log To Console for messages
  • Should Be Equal, Should Contain and Should Be True for checks
  • Set Variable, Set Test Variable and Set Suite Variable for values
  • Run Keyword And Return Status for conditional logic
  • Wait Until Keyword Succeeds for retries
  • Evaluate for short Python expressions

Standard and External Library Keywords

Standard libraries ship with the framework but must be imported, for example Collections, String, OperatingSystem, DateTime and Process. External libraries such as SeleniumLibrary or RequestsLibrary are installed with pip and imported the same way through the Library setting.

*** Settings ***
Library    Collections
Library    OperatingSystem
Library    SeleniumLibrary    timeout=10s

Arguments after the library name configure the library itself. In the example above, SeleniumLibrary receives a default timeout. The Robot Framework Selenium article explains that library in depth.

Creating User Keywords

User keywords combine existing keywords into higher-level steps. They are defined in a Keywords section, use the same syntax as test cases and can declare arguments, documentation, tags, return values and teardowns through bracketed settings.

*** Keywords ***
Add Product To Cart
    [Documentation]    Adds a product by name.
    [Arguments]    ${name}    ${qty}=1
    Search Product    ${name}
    Set Quantity      ${qty}
    Click Add Button

Get Cart Total
    ${total}=    Read Total From Page
    RETURN    ${total}

The ${qty}=1 syntax gives the argument a default value. RETURN passes a value back to the caller, which then stores it with the familiar ${variable}= assignment.

Embedded Arguments

Arguments can also be embedded directly into a keyword name. This makes steps read like natural sentences, which is particularly useful in behaviour-driven tests written with Given, When and Then prefixes.

*** Keywords ***
User "${name}" Is Logged In
    Log In As    ${name}    ${DEFAULT_PASSWORD}

Keyword Name Matching Rules

Keyword names are matched case-insensitively, and spaces and underscores are ignored. That flexibility helps readability, but it also means two libraries can expose keywords with the same name, which the framework reports as a conflict.

  • Should Be Equal and should_be_equal refer to the same keyword
  • Prefix with the library name to resolve conflicts, such as BuiltIn.Log
  • Keywords in the same suite file take priority over imported ones
  • Given, When, Then, And and But prefixes are ignored during matching

Organising Keywords in Resource Files

Resource files use the .resource extension and contain Settings, Variables and Keywords sections but no tests. Import them with the Resource setting to share keywords across suites, and group them by page, feature or domain so that each file stays focused.

LayerContains
TestsBusiness-level steps only
Resource keywordsWorkflows composed from library keywords
Python librariesComplex logic, parsing and integrations

This layering mirrors the advice in the Robot Framework Python article: keep readable intent in test data and push computation into code.

Documenting Keywords

The Libdoc tool generates HTML documentation for libraries and resource files, including argument lists and the text from [Documentation] or Python docstrings. Publishing this documentation lets teammates discover existing keywords before writing duplicates. The Robot Framework documentation article shows how to generate it.

Naming Keywords Well

Good keyword names describe intent from the reader’s point of view. A name such as Order Should Be Confirmed tells a reviewer what is verified, while Check Element Text 3 forces them to open the implementation to understand the step.

  • Use the language of the business domain
  • Start verification keywords with “Should” or end them with “Should Be …”
  • Avoid technical details such as locators in user keyword names
  • Keep names unique across imported resource files

Consistent naming also makes keyword search in Libdoc and editor completion far more effective, because related keywords group together alphabetically.

Keyword Tags and Teardowns

User keywords support [Tags] for categorisation and [Teardown] for cleanup that must run even when a step fails. A keyword teardown is ideal for closing connections or removing temporary files created inside that keyword.

Export Report As CSV
    [Tags]    export
    Open Export Dialog
    Choose Format    CSV
    [Teardown]    Close Export Dialog

Frequently Asked Questions

How many arguments can a keyword take?

There is no small fixed limit. Keywords can accept positional, named, default, variable-length and free named arguments, although keeping signatures short improves readability.

Can a user keyword call another user keyword?

Yes. User keywords can call any keyword available in their scope, including other user keywords, library keywords and BuiltIn keywords.

Where can I see every keyword a library offers?

Open the library’s Libdoc page. Standard library documentation is published on the official website, and most external libraries publish their own keyword documentation.

What happens when two libraries define the same keyword?

The framework reports that multiple keywords match the name. Resolve it by prefixing the call with the library name, such as SeleniumLibrary.Click Element, or by changing the library search order.

Should every repeated step become a user keyword?

Steps repeated across several tests are good candidates, especially when they describe one business action. Avoid wrapping single library calls without adding meaning, because extra layers can make logs harder to follow.

Review a proposed keyword by reading its name inside a complete test. A name such as Confirm Order Total gives the reviewer a clear expectation. Put technical arguments in the underlying library call and expose only the values that help explain the case, such as the order reference and expected total in cents.

Conclusion

Robot Framework keywords turn automation into readable steps. Rely on BuiltIn for everyday checks, import standard and external libraries for specific technologies, build user keywords in resource files for reusable workflows and document everything with Libdoc so the team can find and reuse it.