Skip to content

Commit bd43378

Browse files
committed
add capture all outputs
1 parent 3332cb7 commit bd43378

File tree

10 files changed

+102
-31
lines changed

10 files changed

+102
-31
lines changed

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# robotframework-jupyterlibrary
2+
> A Robot Framework library for testing Jupyter end-user applications and extensions
3+
4+
---
5+
6+
> _TODO: binder, tests, pip, conda_
7+
8+
# Installation
9+
10+
## Development Installation
11+
- get Firefox
12+
- get Miniconda
13+
- update and activate
14+
```bash
15+
conda env update
16+
conda activate robotframework-jupyterlibrary
17+
```
18+
- then
19+
```bash
20+
pip install -e . --no-deps --ignore-installed
21+
```
22+
- run the tests
23+
```
24+
python -m atest.run
25+
```
26+
27+
# Using
28+
> _TODO: Figure out a documentation strategy that works with
29+
janky-imported resources_
30+
31+
Write `.robot` files that use `JupyterLibrary` keywords. See the
32+
[acceptance tests](./atest/acceptance) for examples.

atest/acceptance/10_lab/10_notebook.robot

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
*** Settings ***
22
Suite Setup Wait for New Jupyter Server to be Ready
3-
Test Teardown Close All Browsers
3+
Test Teardown Reset JupyterLab and Close
4+
Default Tags notebook
45
Library JupyterLibrary
56
Library Process
67

@@ -12,6 +13,13 @@ IPython Notebook
1213
Wait Until Kernel Is Idle
1314
Capture Page Screenshot ipython.png
1415

16+
IPython Notebook Outputs
17+
Open JupyterLab
18+
Launch a new JupyterLab Document
19+
Add and Run Cell print("hello world")
20+
Wait Until Kernel Is Idle
21+
Screenshot Each Output of Active Document ${OUTPUT_DIR}${/}ipython
22+
1523
*** Keywords ***
1624
Clean Up Everything
1725
Close All Browsers

atest/run.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212

1313
def run_tests(*robot_args):
1414
proc = subprocess.Popen([
15-
"python", "-m", "robot", "-d", out, tests
16-
], cwd=here)
15+
"python", "-m", "robot", "-d", out,
16+
] + list(robot_args) + [
17+
tests,
18+
], cwd=here)
1719

1820
try:
1921
return proc.wait()
@@ -23,4 +25,4 @@ def run_tests(*robot_args):
2325

2426

2527
if __name__ == "__main__":
26-
sys.exit(run_tests(sys.argv[1:]))
28+
sys.exit(run_tests(*sys.argv[1:]))

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = robotframework-jupyterlibrary
3-
description = A Robot Framework library for testing Jupyter end-user applications
3+
description = A Robot Framework library for testing Jupyter end-user applications and extensions
44
long_description = file: README.md, CHANGELOG.md
55
url = https://github.com/robots-from-jupyter/robotframework-jupyterlibrary
66
author = Nicholas Bollweg

src/JupyterLibrary/keywords/screenshots.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
class ScreenshotKeywords(LibraryComponent):
1717
@keyword
18-
def capture_element_screenshot(self, locator, filename, embed=True):
18+
def capture_element_screenshot(self, locator, filename):
1919
el = self.find_element(locator)
2020
BuiltIn().run_keyword("Capture Page Screenshot", filename)
2121
rect = {**el.location, **el.size}

src/JupyterLibrary/resources/jupyterlab/Commands.robot

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ Resource JupyterLibrary/resources/jupyterlab/Selectors.robot
77
Execute JupyterLab Command
88
[Arguments] ${command} ${accept}=${True} ${close}=${True}
99
[Documentation] Use the JupyterLab Command Palette to run a command
10-
Maybe accept a prompt
10+
Maybe accept a JupyterLab prompt
1111
Maybe Open JupyterLab Sidebar command-palette
1212
Input Text css:${JLAB CSS CMD INPUT} ${command}
1313
Wait Until Page Contains Element css:${JLAB CSS CMD ITEM}
1414
Click Element css:${JLAB CSS CMD ITEM}
15-
Run Keyword If ${accept} Maybe Accept a Prompt
16-
Run Keyword If ${close} Maybe Close Sidebar
15+
Run Keyword If ${accept} Maybe Accept a JupyterLab Prompt
16+
Run Keyword If ${close} Maybe Close JupyterLab Sidebar
1717

18-
Reset Application State and Close
18+
Reset JupyterLab and Close
1919
[Documentation] Try to clean up after doing some things to the JupyterLab state
2020
Execute JupyterLab Command Reset Application State
2121
Close Browser
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
*** Settings ***
2+
Documentation Get screenshots and content of a JupyterLab Notebook
3+
Resource JupyterLibrary/resources/jupyterlab/Selectors.robot
4+
5+
*** Keywords ***
6+
Screenshot Each Output of Active Cell
7+
[Arguments] ${prefix}
8+
${outputs} = Get WebElements css:${JLAB CSS ACTIVE OUTPUT CHILDREN} ${JLAB CSS OUTPUT} > *
9+
:FOR ${i} IN RANGE ${outputs.__len__()}
10+
\ Capture Element Screenshot ${outputs[${i}]} ${prefix}_output_${i}.png
11+
12+
Screenshot Markdown of Active Cell
13+
[Arguments] ${prefix}
14+
${inputs} = Get WebElements css:${JLAB CSS ACTIVE CELL MARKDOWN}
15+
:FOR ${i} IN RANGE ${inputs.__len__()}
16+
\ Capture Element Screenshot ${inputs[${i}]} ${prefix}_markdown_${i}.png
17+
18+
Screenshot Each Output of Active Document
19+
[Arguments] ${prefix}
20+
${cells} = Get WebElements css:${JLAB CSS ACTIVE DOC CELLS}
21+
:FOR ${i} IN RANGE ${cells.__len__()}
22+
\ Click element ${cells[${i}]}
23+
\ Run Keyword And Ignore Error Click element ${cells[${i + 1}]}
24+
\ Click element ${cells[${i}]}
25+
\ Sleep 0.1s
26+
\ Screenshot each output of active cell ${prefix}_cell_${i}
27+
\ Screenshot Markdown of active cell ${prefix}_cell_${i}
Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
*** Variables ***
2-
${JLAB ID SPLASH} jupyterlab-splash
2+
${JLAB CSS ACCEPT} .jp-mod-accept
3+
${JLAB CSS ACTIVE DOC} .jp-Document:not(.jp-mod-hidden)
4+
${JLAB CSS ACTIVE DOC CELLS} ${JLAB CSS ACTIVE DOC} .jp-Cell
5+
${JLAB CSS ACTIVE CELL} ${JLAB CSS ACTIVE DOC} .jp-Cell.jp-mod-active
6+
${JLAB CSS ACTIVE OUTPUT CHILDREN} ${JLAB CSS ACTIVE CELL} .jp-OutputArea-child
7+
${JLAB CSS OUTPUT} .jp-OutputArea-output
8+
${JLAB CSS ACTIVE CELL MARKDOWN} ${JLAB CSS ACTIVE CELL} .jp-MarkdownOutput:not(.jp-mod-hidden)
39

10+
${JLAB CSS ACTIVE SIDEBAR} .jp-SideBar .p-TabBar-tab.p-mod-current
11+
${JLAB CSS BUSY KERNEL} .jp-Toolbar-kernelStatus.jp-FilledCircleIcon
412
${JLAB CSS CELL} .jp-Notebook .jp-Cell:last-of-type .jp-InputArea-editor .CodeMirror
5-
${JLAB CSS SPINNER} .jp-Spinner
6-
${JLAB CSS CMD PALETTE} li[data-id="command-palette"]
713
${JLAB CSS CMD INPUT} .p-CommandPalette-input
814
${JLAB CSS CMD ITEM} .p-CommandPalette-item
9-
${JLAB CSS ACCEPT} .jp-mod-accept
10-
${JLAB CSS ACTIVE SIDEBAR} .jp-SideBar .p-TabBar-tab.p-mod-current
11-
${JLAB CSS SIDEBAR TAB} .jp-SideBar .p-TabBar-tab
12-
${JLAB CSS BUSY KERNEL} .jp-Toolbar-kernelStatus.jp-FilledCircleIcon
13-
14-
${JLAB CSS NB TOOLBAR} .jp-NotebookPanel-toolbar
15-
16-
${JLAB CSS ICON RUN} .jp-RunIcon
15+
${JLAB CSS CMD PALETTE} li[data-id="command-palette"]
1716
${JLAB CSS ICON ADD} .jp-AddIcon
18-
19-
${JLAB XP TOP} //div[@id='jp-top-panel']
20-
${JLAB XP MENU LABEL} //div[@class='p-MenuBar-itemLabel']
21-
${JLAB XP MENU ITEM LABEL} //div[@class='p-Menu-itemLabel']
17+
${JLAB CSS ICON RUN} .jp-RunIcon
18+
${JLAB CSS NB TOOLBAR} .jp-NotebookPanel-toolbar
19+
${JLAB CSS SIDEBAR TAB} .jp-SideBar .p-TabBar-tab
20+
${JLAB CSS SPINNER} .jp-Spinner
21+
${JLAB ID SPLASH} jupyterlab-splash
22+
${JLAB TEXT BUSY PROMPT} In [*]:
2223
${JLAB XP CARD} //div[@class='jp-LauncherCard']
2324
${JLAB XP DOCK} //div[@id='jp-main-dock-panel']
24-
25-
${JLAB TEXT BUSY PROMPT} In [*]:
25+
${JLAB XP MENU ITEM LABEL} //div[@class='p-Menu-itemLabel']
26+
${JLAB XP MENU LABEL} //div[@class='p-MenuBar-itemLabel']
27+
${JLAB XP TOP} //div[@id='jp-top-panel']

src/JupyterLibrary/resources/jupyterlab/Shell.robot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ Open With JupyterLab Menu
3939
:FOR ${item_label} IN @{submenu_labels}
4040
\ Click JupyterLab Menu Item ${item_label}
4141

42-
Maybe Accept a Prompt
42+
Maybe Accept a JupyterLab Prompt
4343
${accept} = Get WebElements css:${JLAB CSS ACCEPT}
4444
Run Keyword If ${accept} Click Element ${accept[0]}

src/JupyterLibrary/resources/jupyterlab/Sidebar.robot

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ Resource JupyterLibrary/resources/jupyterlab/Selectors.robot
44

55

66
*** Keywords ***
7-
Maybe Close Sidebar
7+
Maybe Close JupyterLab Sidebar
88
[Documentation] Attempt to close the JupyterLab sidebar
99
${active} = Get WebElements css:${JLAB CSS ACTIVE SIDEBAR}
1010
Run Keyword If ${active} Click Element ${active[0]}
1111

12-
Maybe Open Sidebar
12+
Maybe Open JupyterLab Sidebar
1313
[Arguments] ${data id}
1414
[Documentation] Attempt to open a JupyterLab sidebar (if not already open)
15-
Maybe Close Sidebar
15+
Maybe Close JupyterLab Sidebar
1616
Click Element css:${JLAB CSS SIDEBAR TAB}[data-id="${data id}"]

0 commit comments

Comments
 (0)