Libraries and resources
Chapter lab: Keywords and imports
This chapter works in a prepared project. Download it before the first task; it unpacks into its own folder.
Download ch03-keywords-imports.zip
Or fetch and unpack it from a terminal in VS Code:
curl -fsSLO https://manykarim.github.io/robotframework-essentials-web/labs/ch03-keywords-imports.zip && unzip -q ch03-keywords-imports.zip && rm ch03-keywords-imports.zipInvoke-WebRequest https://manykarim.github.io/robotframework-essentials-web/labs/ch03-keywords-imports.zip -OutFile ch03-keywords-imports.zip; Expand-Archive ch03-keywords-imports.zip -DestinationPath .; Remove-Item ch03-keywords-imports.zipOpen the folder in VS Code with code rfe-ch03-keywords-imports (or File → Open Folder…) and accept the recommended RobotCode and Python extensions. Then set it up:
uv syncpython3 -m venv .venvsource .venv/bin/activatepip install -r requirements.txtpython -m venv .venv.venv\Scripts\Activate.ps1pip install -r requirements.txtKeep the environment active in every terminal where you run lesson commands.
poetry install --no-rootPython 3.13 or newer is required; uv installs it when it is missing.
Open in browserNo setup? Try the lab right here: its files, an editor and a terminal, running in your browser.
What's inside
Directoryrfe-ch03-keywords-imports/
Directory.vscode/
- extensions.json
Directorychecks/
- imports.robot
Directoryresources/
- common.resource
- .gitignore
- .python-version
- LAB.md
- pyproject.toml
- README.md
- requirements.txt
- uv.lock
Keywords arrive in a suite two ways, both declared in *** Settings ***:
Libraryimports Python-backed keywords — the standard libraries (Collections,String,OperatingSystem, …) and third-party ones.Resourceimports keywords and variables from a shared.resourcefile you write in Robot Framework syntax.
This chapter’s workspace already has a resource at resources/common.resource
imported by checks/imports.robot. Add a library import alongside it.
Task 1 — Import the Collections library and use one of its keywords
Section titled “Task 1 — Import the Collections library and use one of its keywords”Goal: in checks/imports.robot, import the Collections library and add a
test that builds a list and checks its length.
Here is the same pattern with a different library — importing String and
calling one of its keywords. Adapt it to Collections.
Worked example — adapt it, don’t copy it
*** Settings ***Library String
*** Test Cases ***Path Splits Into Parts @{parts}= Split String a/b/c / Length Should Be ${parts} 3Done when
checks/imports.robot imports Collections and calls Create List,
and the new test passes.
Hint 1
Add Library Collections to the *** Settings *** section, alongside the
existing Resource import.
Hint 2
Add a test that builds a list with Create List and checks it with
Length Should Be.
Hint 3
${items}= Create List backpack lamp mug, then
Length Should Be ${items} 3.
Solution
*** Settings ***Resource ../resources/common.resourceLibrary Collections
*** Test Cases ***Catalog List Has Items ${items}= Create List backpack lamp mug Length Should Be ${items} 3Task 2 — Run the suite green
Section titled “Task 2 — Run the suite green”Run it:
uv run robot checksrobot checkspoetry run robot checksDone when
the test Catalog List Has Items passes.
Preview unavailableWatch a test case become simpler and its keywords and variables reusable by extracting them into a resource file.
Check your understanding
Quick recall. Your first answer stays in this browser; the quiz never blocks your progress.
What is the difference between a Library and a Resource import?
Libraryimports Python-backed keywords (e.g. Collections);Resourceimports keywords and variables from a.resourcefile.Show the answer
Answer: A Library adds keywords from Python; a Resource adds keywords/variables from a .resource file —
Libraryimports Python-backed keywords (e.g. Collections);Resourceimports keywords and variables from a.resourcefile.Where do you declare imports?
LibraryandResourceimports go in the*** Settings ***section.Show the answer
Answer:
*** Settings ***—LibraryandResourceimports go in the*** Settings ***section.
Key terms
- Libraryconcept
- Imports Python-backed keywords, e.g.
Library Collections. - Resourceconcept
- Imports keywords and variables from a shared
.resourcefile, e.g.Resource ../resources/common.resource.