Keywords are the core building blocks of Robot Framework tests.
They represent actions or steps performed during a test case, such as opening a browser, entering text, or verifying results.
Robot Framework follows a keyword-driven testing approach, meaning every test action is expressed using keywords, making test cases readable, modular, and reusable.
1. Built-in Keywords
Robot Framework and its standard libraries provide many ready-to-use keywords, so you don’t need to write common functions from scratch.
Commonly Used Built-in Keywords
|
Keyword |
Description |
Example |
|
Log |
Logs a message |
Log Hello Robot Framework |
|
Sleep |
Pause execution for given time |
Sleep 2s |
|
Should be Equal |
Verifies equality |
Should be Equal 5 5 |
|
Set Variable |
Stores a value in a variable |
${value}= Set Variable 10 |
|
Run Keyword If |
Executes a keyword conditionally. |
Run Keyword If ${status} == PASS Log Success |
|
Evaluate |
Executes a Python expression. |
${sum}= Evaluate 5 + 3 |
Example Using Built-in Keywords
Explanation:
Built-in keywords simplify test creation by handling common tasks like logging, waiting, and assertions without any additional coding.
2. SeleniumLibrary Keywords
When working with web automation, SeleniumLibrary provides powerful keywords to interact with browsers, elements, and pages.
You must import it using:
Commonly Used SeleniumLibrary Keywords
|
Keyword |
Description |
Example |
|
Open Browser |
Opens a specified URL in a given browser. |
Open Browser https://example.com chrome |
|
Close Browser |
Closes the active browser window. |
Close Browser |
|
Maximize Browser Window |
Maximizes the current browser window. |
Maximize Browser Window |
|
Go To |
Navigates to a new URL within the same session. |
Go To https://google.com |
|
Input Text |
Enters text into an input field. |
Input Text id=username testUser |
|
Click Button |
Clicks a button element. |
Click Button id=loginBtn |
|
Click Element |
Clicks any element (button, link, etc.) by locator. |
Click Element css:button.submit |
|
Click Link |
Clicks a hyperlink element. |
Click Link Contact Us |
|
Wait Until Element Is Visible |
Waits until the given element is visible on the page. |
Wait Until Element Is Visible id:username 10s |
|
Page Should Contain |
Verifies that the given text appears on the page. |
Page Should Contain Welcome |
|
Page Should Contain Element |
Verifies that a given web element exists. |
Page Should Contain Element xpath://button[text()='Login'] |
|
Get Title |
Returns the current page title. |
${title}= Get Title |
|
Capture Page Screenshot |
Takes a screenshot of the current page. |
Capture Page Screenshot |
Example Using SeleniumLibrary Keywords
Explanation:
This test opens a browser, logs into a sample site, verifies a welcome message, captures a screenshot, and then closes the browser.
3. User-Defined Keywords
You can create your own keywords to group multiple actions together.
This makes your tests cleaner, reusable, and easier to maintain.
Example – Creating and Using Custom Keywords
Test Explanation:
Open Google Page: Opens Google and verifies the page title.
Verify Google Text: Checks that “Google” appears and the search box exists.
Close Browser Safely: Closes the browser session.