Workshop on authoring Robot Framework test and task suites with JupyterLab
Asko Soukka University of Jyväskylä |
Nicholas Bollweg Project Jupyter |
---|---|
https://github.com/robots-from-jupyter/robotlab/releases
Ingredients: Conda, JupyterLab, Robot[Mode|Kernel], Jupytext, Selenium[Library|Screenshots|Testabilit], OpenCV, RESTInstance, Firefox, GeckoDriver, starter notebooks...
Install Miniconda, launch Anaconda Prompt, then:
$ conda install -c conda-forge nodejs jupyterlab ipywidgets
$ pip install robotkernel
$ jupyter labextension install \
jupyterlab_robotmode --no-build
$ jupyter labextension install \
@jupyter-widgets/jupyterlab-manager
Launch Anaconda Prompt, then:
$ conda install -c conda-forge firefox geckodriver
$ pip install robotframework-seleniumscreenshots \
RESTinstance jupytext jupyter-starters nbimporter
$ jupyter labextension install \
jupyterlab-jupytext --no-build
$ jupyter labextension install \
@deathbeds/jupyterlab-starters
From RobotLab with Windows Command Prompt:
$ c:\robotlab\Scripts\activate.bat
$ robotlab
From RobotLab with MacOS / Linux terminal:
$ ~/robotlab/bin/activate
$ robotlab
From manually installed Anaconda Prompt:
$ jupyter lab
00 JupyterLab User Interface
00 What is the Jupyter Notebook
00 Keyboard Shortcuts
01 Running Code
02 Python XKCD
The JSON API for XKCD is described at
Create a new Python notebook and implement function, which accepts an integer and returns XKCD image of the given number.
def get_xkcd_by_num(num):
return None
Write narrative documentation for that function in Markdown and executable Python example lines.
TAB
CTRL + ENTER
until readyhttps://ipython.readthedocs.io/en/stable/interactive/magics.html
Magics are “magical” syntax for modifying the underlying Python environment supported mainly by Jupyter Python kernels.
For example
!pip install requests
would install requests Python package into Python environment.
02 Robot XKCD
Create a new Robot notebook and implement keyword
*** Keywords ***
Get XKCD by num
[Arguments] ${num}
which accepts an integer and [Return]
image of the given number. Write narrative documentation for that keyword in Markdown and executable Robot example *** Tasks ***
.
*** [Heading] ***
Some completions can be suggested only after at least one cell with *** Test Cases***
or *** Tasks ***
has been executed.
Cells without any robot *** [Heading] ***
or content outside headings may be silently ignored.
Failing library import is silently ignored (but logged).
Thumb of rule for weird or erratic behavior: Restart the kernel.
05 Interactive Selenium
TAB
-suggestions:id:
, name:
, link:
TAB
-completions:id:
, name:
, link:
, tag:
, xpath:
, partial link:
css: + TAB
07 Prototyping keywords
09 Prototyping Libraries
06 Importing Notebooks
Parameterize 06 Importing Notebooks
with
*** Variables ***
${DEPARTURE_DATE} ${EMPTY}
${DEPARTURE_TIME} 17.00
Modify notebook task to use ${DEPARTURE_TIME}
and to prefer ${DEPARTURE_DATE}
when it is not empty. Customize or write new Python keywords when necessary.
Using JupyterLab
File → Export Notebook As… →
Using Jypyter nbconvert
$ jupyter nbconvert --to html MyNotebook.ipynb
How to customize nbconvert
HTML-templates:
https://nbconvert.readthedocs.io/en/latest/customizing.html
Executing notebook with Jupyter
jupyter nbconvert --to notebook --execute MyNotebook.ipynb
Executing notebook with RobotKernel
nbrobot MyNotebook.ipynb
Executing exported script with Robot Framework
jupyter nbconvert --to script MyNotebook.ipynb
robot MyNotebook.robot
.ipynb
and .robot
%%python module WidgetDemo
import ipywidgets as widgets
w = widgets.IntSlider()
display(w)
class WidgetDemo:
def get_value(self):
return w.value