Skip to content

Collections

Chapter lab: Text and datach15-text.zip · 5 KB

This lesson continues in the same lab as the lesson before it. If you don’t have it yet, download it here.

Download ch15-text.zip

Or fetch and unpack it from a terminal in VS Code:

Terminal window
curl -fsSLO https://manykarim.github.io/robotframework-essentials-web/labs/ch15-text.zip && unzip -q ch15-text.zip && rm ch15-text.zip

Open 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:

Terminal window
uv sync
Terminal window
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

Keep the environment active in every terminal where you run lesson commands.

Terminal window
poetry install --no-root

Python 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”
Edit

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} 5

Done 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} 79
Run

Run:

Terminal window
uv run robot checks
Terminal window
robot checks
Terminal window
poetry run robot checks

Done 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.

  1. Which keyword asserts a list contains a value?

    Show the answer

    Answer: List Should Contain Value — Collections' List Should Contain Value ${list} ${value} asserts membership.

  2. Get From Dictionary ${d} key returns…

    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.

All terms in the glossary →