MAGIC#
JupyterLibrary
provides a few lightweight IPython magics for its own testing purposes.
If you like writing and executing Robot Framework in a Jupyter kernel, you might like a more full-featured experience:
%reload_ext JupyterLibrary
The %%robot
magic runs a cell of code as you would write in a .robot
file. No funny stuff (by default).
%%robot -o _static
*** Tasks ***
Log Something
Log Something
🤖 making files in
/home/docs/checkouts/readthedocs.org/user_builds/robotframework-jupyterlibrary/checkouts/stable/docs/_static/_robot_magic_/b48ff0e77cff
🤖 running!
-
stdout.txt
============================================================================== Untitled b48ff0e77cff ============================================================================== Log Something | PASS | ------------------------------------------------------------------------------ Untitled b48ff0e77cff | PASS | 1 task, 1 passed, 0 failed ============================================================================== Output: /home/docs/checkouts/readthedocs.org/user_builds/robotframework-jupyterlibrary/checkouts/stable/docs/_static/_robot_magic_/b48ff0e77cff/output.xml Log: /home/docs/checkouts/readthedocs.org/user_builds/robotframework-jupyterlibrary/checkouts/stable/docs/_static/_robot_magic_/b48ff0e77cff/log.html Report: /home/docs/checkouts/readthedocs.org/user_builds/robotframework-jupyterlibrary/checkouts/stable/docs/_static/_robot_magic_/b48ff0e77cff/report.html
-
stderr.txt
empty
🤖 returned 0
The interactive help is pretty good.
%%robot?
Of note: you can specify extra arguments to robot.run
with -a
, the name of a local variable.
args = dict(include=["mytag:a"])
%%robot -a args -o _static
*** Tasks ***
Do thing A
[Tags] mytag:a
Log A
Do thing B
[Tags] mytag:b
Log B
Do thing AB
[Tags] mytag:a mytag:b
Log AB
🤖 making files in
/home/docs/checkouts/readthedocs.org/user_builds/robotframework-jupyterlibrary/checkouts/stable/docs/_static/_robot_magic_/0b0dd3cec340
🤖 running!
-
stdout.txt
============================================================================== Untitled 0b0dd3cec340 ============================================================================== Do thing A | PASS | ------------------------------------------------------------------------------ Do thing AB | PASS | ------------------------------------------------------------------------------ Untitled 0b0dd3cec340 | PASS | 2 tasks, 2 passed, 0 failed ============================================================================== Output: /home/docs/checkouts/readthedocs.org/user_builds/robotframework-jupyterlibrary/checkouts/stable/docs/_static/_robot_magic_/0b0dd3cec340/output.xml Log: /home/docs/checkouts/readthedocs.org/user_builds/robotframework-jupyterlibrary/checkouts/stable/docs/_static/_robot_magic_/0b0dd3cec340/log.html Report: /home/docs/checkouts/readthedocs.org/user_builds/robotframework-jupyterlibrary/checkouts/stable/docs/_static/_robot_magic_/0b0dd3cec340/report.html
-
stderr.txt
empty
🤖 returned 0
Running JupyterLibrary
#
The line below is a Markdown Cell… change it to a Code Cell to run it
%%robot
*** Settings ***
Documentation A nice task suite
Library JupyterLibrary
Suite Setup Wait For New Jupyter Server To Be Ready
Test Teardown Reset JupyterLab And Close
Suite Teardown Run Keyword And Ignore Error Terminate All Jupyter Servers
*** Tasks ***
A Notebook in JupyterLab
Open JupyterLab
Launch A New JupyterLab Document
Add And Run JupyterLab Code Cell print("hello" + " world")
Wait Until page Contains hello world
Capture Page Screenshot ran-code.png
With Widgets#
There is some more stuff coming with
%%robot
, but for now,ipywidgets.interact
can be used to quickly build UI around robot-generated artifacts
from pathlib import Path
from IPython.display import display, Image
ipywidgets = None
try:
import ipywidgets
except:
pass
if ipywidgets:
@ipywidgets.interact
def show_image(i=(0, 100)):
all_images = sorted(Path("_robot_magic_").rglob("*.png"), key=lambda p: p.stat().st_mtime)
if not all_images:
return
start = all_images[0].stat().st_mtime
i = min(len(all_images) - 1, i)
img = all_images[i]
delta = img.stat().st_mtime - start
display(f"[{round(delta)}s][{i} of {len(all_images)}] {img.name}", Image(img))