Collections
Chapter lab: Text and data
This lesson continues in the same lab as the lesson before it. If you don’t have it yet, download it here.
Or fetch and unpack it from a terminal in VS Code:
curl -fsSLO https://manykarim.github.io/robotframework-essentials-web/labs/ch15-text.zip && unzip -q ch15-text.zip && rm ch15-text.zipInvoke-WebRequest https://manykarim.github.io/robotframework-essentials-web/labs/ch15-text.zip -OutFile ch15-text.zip; Expand-Archive ch15-text.zip -DestinationPath .; Remove-Item ch15-text.zipOpen the folder in VS Code with code rfe-ch15-text (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-ch15-text/
Directory.vscode/
- extensions.json
Directorychecks/
- smoke.robot
Directorysample_data/
- app.log
- catalog.xml
- orders.csv
- results.xml
- settings.cfg
- .gitignore
- .python-version
- LAB.md
- pyproject.toml
- README.md
- requirements.txt
- uv.lock
The Collections standard library works with lists and dictionaries: build
them, search them, and read values out. You met Create List and
Length Should Be in Part 1; here are the everyday operations —
List Should Contain Value, Create Dictionary, Dictionary Should Contain Key,
and Get From Dictionary.
Task 1 — Work with lists and dictionaries
Section titled “Task 1 — Work with lists and dictionaries”Goal: create checks/collections.robot that builds a list and a dictionary,
checks their contents, and reads a value out of the dictionary.
Here is the same set of operations over different values. Adapt them.
Worked example — adapt it, don’t copy it
*** Settings ***Library Collections
*** Test Cases ***Build A List And A Dict ${colors}= Create List red green blue Length Should Be ${colors} 3 List Should Contain Value ${colors} green ${stock}= Create Dictionary red=5 blue=2 Dictionary Should Contain Key ${stock} blue ${n}= Get From Dictionary ${stock} red Should Be Equal As Integers ${n} 5Done when
the suite imports Collections and defines Work With Lists And Dicts.
Hint 1
Build a four-item list with Create List backpack lamp mug notebook,
then Length Should Be ${products} 4 and
List Should Contain Value ${products} mug.
Hint 2
Build a dict with Create Dictionary backpack=79 lamp=34, check a key with
Dictionary Should Contain Key, and read one with
Get From Dictionary ${prices} backpack.
Solution
*** Settings ***Library Collections
*** Test Cases ***Work With Lists And Dicts ${products}= Create List backpack lamp mug notebook Length Should Be ${products} 4 List Should Contain Value ${products} mug ${prices}= Create Dictionary backpack=79 lamp=34 Dictionary Should Contain Key ${prices} lamp ${value}= Get From Dictionary ${prices} backpack Should Be Equal As Integers ${value} 79Task 2 — Run it green
Section titled “Task 2 — Run it green”Run:
uv run robot checksrobot checkspoetry run robot checksDone when
the list and dictionary operations all hold.
Check your understanding
Quick recall. Your first answer stays in this browser; the quiz never blocks your progress.
Which keyword asserts a list contains a value?
Collections'
List Should Contain Value ${list} ${value}asserts membership.Show the answer
Answer:
List Should Contain Value— Collections'List Should Contain Value ${list} ${value}asserts membership.Get From Dictionary ${d} keyreturns…It returns the value stored under the key.
Show the answer
Answer: the value for that key — It returns the value stored under the key.
Key terms
- Collectionsconcept
- Standard library for list and dictionary operations.
- Get From Dictionarykeyword
- Return the value for a key in a dictionary.