Calling styles
Chapter lab: Keywords and imports
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:
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
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/Thenprefixes 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”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} > 0Task 2 — Call it in behavior-driven style and pass
Section titled “Task 2 — Call it in behavior-driven style and pass”Add a test that calls the same keyword with a Given prefix:
Given A Positive Number Given Number 7 Is PositiveRobot 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.
An embedded-argument keyword like
Number ${n} Is Positiveis called by…Embedded arguments are written into the keyword call itself, reading like a sentence.
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.Behavior-driven style uses which prefixes?
Robot Framework ignores the leading Given/When/Then/And/But so keywords read as BDD sentences.
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.