Skip to content

Calling styles

Chapter lab: Keywords and importsch03-keywords-imports.zip · 3 KB

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

Download ch03-keywords-imports.zip

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

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

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

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

The same keyword can be called several ways:

  • Positional — arguments in order: Greeting For Ada.
  • Named — by argument name: Greeting For name=Ada.
  • Embedded — values written into the keyword name itself.
  • Behavior-driven — with Given/When/Then prefixes that Robot Framework ignores, so calls read like sentences.

Embedded arguments make a keyword read like plain language. A keyword named Number ${n} Is Positive is called Number 5 Is Positive, and 5 becomes the argument ${n}.

Task 1 — Write an embedded-argument keyword

Section titled “Task 1 — Write an embedded-argument keyword”
Edit

Goal: in checks/styles.robot, write an embedded-argument keyword Number ${n} Is Positive and a test that calls it positionally.

Here is the same idea with more embedded values — a keyword that reads a whole sentence. Adapt it to a single embedded number.

Worked example — adapt it, don’t copy it

*** Test Cases ***
Two Plus Three
Sum Of 2 And 3 Is 5
*** Keywords ***
Sum Of ${a} And ${b} Is ${c}
${sum}= Evaluate ${a} + ${b}
Should Be Equal As Integers ${sum} ${c}

Done when

the test Five Is Positive passes.

Hint 1

Define a keyword whose name carries the value: Number ${n} Is Positive. The ${n} captures whatever is written in that spot when it’s called.

Hint 2

In the body, assert Should Be True ${n} > 0.

Hint 3

Call it positionally as Number 5 Is Positive in a test named Five Is Positive.

Solution
*** Test Cases ***
Five Is Positive
Number 5 Is Positive
*** Keywords ***
Number ${n} Is Positive
[Documentation] Assert the embedded number is greater than zero.
Should Be True ${n} > 0

Task 2 — Call it in behavior-driven style and pass

Section titled “Task 2 — Call it in behavior-driven style and pass”
Run

Add a test that calls the same keyword with a Given prefix:

Given A Positive Number
Given Number 7 Is Positive

Robot Framework strips the Given and matches Number 7 Is Positive.

Done when

the test Given A Positive Number passes.

Check your understanding

Quick recall. Your first answer stays in this browser; the quiz never blocks your progress.

  1. An embedded-argument keyword like Number ${n} Is Positive is called by…

    Show the answer

    Answer: Writing the value into the call: Number 5 Is Positive — Embedded arguments are written into the keyword call itself, reading like a sentence.

  2. Behavior-driven style uses which prefixes?

    Show the answer

    Answer: Given/When/Then (and And/But) — Robot Framework ignores the leading Given/When/Then/And/But so keywords read as BDD sentences.

Key terms

embedded argumentsconcept
Argument values written into the keyword name, e.g. Number ${n} Is Positive.
Given/When/Thenconcept
BDD prefixes Robot Framework ignores, so keyword calls read as behavior sentences.

All terms in the glossary →