Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Playwright Testing Conversion #170

Merged
merged 199 commits into from
Oct 22, 2022
Merged
Show file tree
Hide file tree
Changes from 197 commits
Commits
Show all changes
199 commits
Select commit Hold shift + click to select a range
5943cc9
Initial skeleton subpackage.
ericsnekbytes Aug 2, 2022
455d5a8
Initial WIP playwright test skeleton.
ericsnekbytes Aug 9, 2022
7c00171
WIP util edits.
ericsnekbytes Aug 12, 2022
d30b82e
Added refactors from team session.
ericsnekbytes Sep 6, 2022
09437c5
WIP NotebookFrontend refactor
ericsnekbytes Sep 7, 2022
8bb241b
WIP working test in debug mode.
ericsnekbytes Sep 7, 2022
1a04366
WIP working in debug mode, fix editor_page wait.
ericsnekbytes Sep 7, 2022
269fd61
Working (ROUGH) POC test (todo remove explicit waits).
ericsnekbytes Sep 7, 2022
8f43e49
Cleanup.
ericsnekbytes Sep 7, 2022
88bf45b
Added checks for frontend objects.
ericsnekbytes Sep 12, 2022
4765a49
Added wait method.
ericsnekbytes Sep 12, 2022
e1abe46
Added more test logic.
ericsnekbytes Sep 12, 2022
a3f7a88
Added more test logic.
ericsnekbytes Sep 12, 2022
055c803
Finished adding test logic, fixed wait_for_cell_output index bug
ericsnekbytes Sep 12, 2022
7372e9f
Small refactors/cleanup, disabled not-yet-used logic.
ericsnekbytes Sep 13, 2022
2bc8127
More code cleanup.
ericsnekbytes Sep 13, 2022
099a103
Replaced cmdtrl func with encapsulated mod key method.
ericsnekbytes Sep 13, 2022
3a1d6ee
Cell output wait logic fix.
ericsnekbytes Sep 14, 2022
be816bb
Added WIP test_deletecell and related utils updates.
ericsnekbytes Sep 15, 2022
5b58524
Renaming.
ericsnekbytes Sep 15, 2022
8372360
Test/framework updates.
ericsnekbytes Sep 15, 2022
a53cf8e
Test updates.
ericsnekbytes Sep 15, 2022
e1de729
Test updates.
ericsnekbytes Sep 15, 2022
d32d052
Finished test_delete_cells()
ericsnekbytes Sep 15, 2022
b5bc971
Finished test_interrupt()
ericsnekbytes Sep 15, 2022
7f72539
Minor cleanup.
ericsnekbytes Sep 15, 2022
ee196f4
Added test prototyper docs.
ericsnekbytes Sep 15, 2022
61b155e
Revised docstring.
ericsnekbytes Sep 15, 2022
ba8d2b7
Fixed JS evaluate call in get_cell_contents()
ericsnekbytes Sep 15, 2022
a6a730e
Updated cell data return format.
ericsnekbytes Sep 15, 2022
e8366dc
Updated test_interrupt().
ericsnekbytes Sep 15, 2022
5258f5e
Added test_find_and_replace() + framework updates.
ericsnekbytes Sep 15, 2022
ebbd827
Refactored to encapsulate playwright cell element objects.
ericsnekbytes Sep 16, 2022
d20d5b9
Comments.
ericsnekbytes Sep 16, 2022
28ec795
Finished rough test_display_image (some TODOs).
ericsnekbytes Sep 19, 2022
004cd9e
WIP working test_buffering with reload from team session
RRosio Sep 20, 2022
a547fe1
Merge branch 'pw-test-buffering' into playwright_conversion
RRosio Sep 20, 2022
c7bc11a
Merge branch 'playwright_conversion' into test_markdown_wip
ericsnekbytes Sep 20, 2022
ecebe2a
Finished test_markdown.
ericsnekbytes Sep 21, 2022
36b9ed9
Merge branch 'test_markdown_wip' into playwright_conversion
ericsnekbytes Sep 21, 2022
d013012
Finished test_merge_cells
ericsnekbytes Sep 21, 2022
33adce1
Merge branch 'pw_test_merge_cells' into playwright_conversion
ericsnekbytes Sep 21, 2022
6dd67e9
working test_clipboard_multiselect
RRosio Sep 21, 2022
2830a0f
Added test_multiselect
ericsnekbytes Sep 22, 2022
f7e73f3
Merge branch 'pw_test_multiselect' into playwright_conversion
ericsnekbytes Sep 22, 2022
92db77e
Added test_move_multiselection
ericsnekbytes Sep 22, 2022
8c473cc
Merge branch 'pw_test_move_multiselection' into playwright_conversion
ericsnekbytes Sep 22, 2022
3aa9430
Added test_multiselect_toggle
ericsnekbytes Sep 22, 2022
5564cde
Merge branch 'pw_test_multiselect_toggle' into playwright_conversion
ericsnekbytes Sep 22, 2022
acb6e2d
Added test_prompt_numbers
ericsnekbytes Sep 22, 2022
d99e019
Merge branch 'pw_test_prompt_numbers' into playwright_conversion
ericsnekbytes Sep 22, 2022
f529dd9
Added test_dualmode_arrows
ericsnekbytes Sep 22, 2022
78f5dfd
Merge branch 'pw_test_dualmode_arrows' into playwright_conversion
ericsnekbytes Sep 22, 2022
65cc783
Added test_dualmode_cellmode
ericsnekbytes Sep 22, 2022
985c72e
Merge branch 'pw_test_dualmode_cellmode' into playwright_conversion
ericsnekbytes Sep 22, 2022
f53174d
Added test_dualmode_clipboard
ericsnekbytes Sep 22, 2022
4bb0b61
Merge branch 'pw_test_dualmode_clipboard' into playwright_conversion
ericsnekbytes Sep 22, 2022
32f9828
working test undelete
RRosio Sep 23, 2022
7c6a507
Added test_dualmode_insertcell
ericsnekbytes Sep 23, 2022
25531a2
Merge branch 'pw_test_dualmode_insertcell' into playwright_conversion
ericsnekbytes Sep 23, 2022
40d1dd3
working test_shutdown
RRosio Sep 23, 2022
ec6e37e
Merge branch 'pw_shutdown' into playwright_conversion
RRosio Sep 23, 2022
3f2581b
Added test_dualmode_execute
ericsnekbytes Sep 23, 2022
6989512
Merge branch 'pw_test_dualmode_execute' into playwright_conversion
ericsnekbytes Sep 23, 2022
36d1483
Added test_dualmode_markdown
ericsnekbytes Sep 23, 2022
f97d0d7
Merge branch 'pw_test_dualmode_markdown' into playwright_conversion
ericsnekbytes Sep 23, 2022
b9877be
Added test_kernel_menu
ericsnekbytes Sep 27, 2022
b7eff8b
Cleanup/refactors for test_execute_code
ericsnekbytes Sep 28, 2022
7faf22a
Merge branch 'pw_refactor_exec_code' into playwright_conversion
ericsnekbytes Sep 28, 2022
055a354
Refactored test_dualmode_arrows/utils and related code.
ericsnekbytes Sep 28, 2022
64549e1
Merge branch 'pw_refactor_test_dualmode_arrows' into playwright_conve…
ericsnekbytes Sep 28, 2022
495d66c
Minor cleanup test_dualmode_clipboard
ericsnekbytes Sep 28, 2022
7de2f95
Minor cleanup test_dualmode_execute
ericsnekbytes Sep 28, 2022
49eb342
Merge branch 'pw_refactor_test_dualmode_execute' into playwright_conv…
ericsnekbytes Sep 28, 2022
aafb1a3
test display isolation and utils wait selector added
RRosio Sep 28, 2022
1ead1d4
Merge branch 'pw_display_isolation' into playwright_conversion
RRosio Sep 28, 2022
fb83d09
updates to the scope of fixtures, remove wait for selector causing ti…
RRosio Oct 5, 2022
ebc8031
Merge branch 'pw-flakiness-rev1' into playwright_conversion
RRosio Oct 5, 2022
6947005
3 updated tests
RRosio Oct 5, 2022
b1c8091
Merge branch 'playwright_conversion' into pw_save_tests
RRosio Oct 5, 2022
2bd2104
Merge branch 'pw_save_tests' into playwright_conversion
RRosio Oct 5, 2022
c93a943
Merge branch 'playwright_conversion' into pw_test_dualmode_insertcell
ericsnekbytes Oct 6, 2022
e1d69c0
Refactor test_dualmode_insertcell
ericsnekbytes Oct 6, 2022
095f998
Merge branch 'pw_test_dualmode_insertcell' into playwright_conversion
ericsnekbytes Oct 6, 2022
d55e119
Merge branch 'playwright_conversion' into pw_refactor_test_display_image
ericsnekbytes Oct 6, 2022
8d81faa
Refactor test_display_image and related utils
ericsnekbytes Oct 6, 2022
581f439
Merge branch 'pw_refactor_test_display_image' into playwright_conversion
ericsnekbytes Oct 6, 2022
b24505f
Refactor test_clipboard_multiselect
ericsnekbytes Oct 6, 2022
d66f142
Merge branch 'pw_refactor_test_clipboard_multiselect' into playwright…
ericsnekbytes Oct 6, 2022
cd92f20
Refactor test_move_multiselection
ericsnekbytes Oct 6, 2022
602c710
Merge branch 'pw_refactor_test_move_multiselection' into playwright_c…
ericsnekbytes Oct 6, 2022
17a4c3b
refactored test dashboard nav and added utils functions
RRosio Oct 6, 2022
ad400cf
refactored test_save and navigat_to util function added
RRosio Oct 6, 2022
dbeee23
Merge branch 'pw-save-refactor' into playwright_conversion
RRosio Oct 6, 2022
351af2d
test_buffering cleanup
RRosio Oct 6, 2022
93c52b3
Merge branch 'pw_refactor_test_buffering' into playwright_conversion
RRosio Oct 6, 2022
016c7c5
clean display isolation
RRosio Oct 6, 2022
009b7dc
Merge branch 'pw_cleanup_display_isolation' into playwright_conversion
RRosio Oct 6, 2022
cd19fe1
cleaup shutdown test and refactor test_save_readonly_as, added Fronte…
RRosio Oct 6, 2022
66e0925
Refactor test_kernel_menu
ericsnekbytes Oct 6, 2022
3fdf54d
Merge branch 'pw_refactor_test_kernel_menu' into playwright_conversion
ericsnekbytes Oct 6, 2022
d20b408
Merge branch 'pw_cleanup' into playwright_conversion
RRosio Oct 6, 2022
3127744
Merge branch 'playwright_conversion' of github.com:ericsnekbytes/nbcl…
ericsnekbytes Oct 6, 2022
9873677
Merge branch 'playwright_conversion' of github.com:ericsnekbytes/nbcl…
ericsnekbytes Oct 6, 2022
cca89fb
refactored test_save_as_notebook recovered
RRosio Oct 6, 2022
de05435
Merge branch 'pw_save_as_nb' into playwright_conversion
RRosio Oct 6, 2022
6f60cac
WIP test_notifications
ericsnekbytes Oct 6, 2022
5822205
working test_notifications with update to wait for selector function
RRosio Oct 7, 2022
77a72f9
cleanup test notifications
RRosio Oct 7, 2022
c1af555
Merge branch 'pw_test_notifications' into playwright_conversion
RRosio Oct 7, 2022
e3baacc
WIP added some utils docs.
ericsnekbytes Oct 7, 2022
7f2c3a3
The .cells prop now uses FrontendElement, removed/refactored cell inf…
ericsnekbytes Oct 11, 2022
0d046a2
Merge branch 'pw_cell_dict_refactor' into playwright_conversion
ericsnekbytes Oct 11, 2022
44c6ca6
Merge branch 'playwright_conversion' into pw_refactor_test_markdown
ericsnekbytes Oct 11, 2022
a8d62dc
Cleanup/refactor to use FrontendElement.
ericsnekbytes Oct 11, 2022
ebb2f4f
Merge branch 'pw_refactor_test_markdown' into playwright_conversion
ericsnekbytes Oct 11, 2022
a9ca493
Minor import cleanup
ericsnekbytes Oct 11, 2022
be21d12
Merge branch 'playwright_conversion' into pw_refactor_test_prompt_num…
ericsnekbytes Oct 11, 2022
edb39e8
Cleanup/refactor to use FrontendElement.
ericsnekbytes Oct 11, 2022
0a7e55b
Merge branch 'pw_refactor_test_prompt_numbers' into playwright_conver…
ericsnekbytes Oct 11, 2022
e5f6ff4
adding playwright tests workflow yaml
RRosio Oct 11, 2022
44002e0
Merge branch 'playwright_conversion' into pw_workflow
ericsnekbytes Oct 11, 2022
558bacf
Merge branch 'playwright_conversion' into pw_conversion_docs_rev1
ericsnekbytes Oct 11, 2022
158f767
Removed legacy/unused code.
ericsnekbytes Oct 11, 2022
80cbd67
Merge branch 'pw_conversion_docs_rev1' into playwright_conversion
ericsnekbytes Oct 11, 2022
45a8a54
Added docs.
ericsnekbytes Oct 11, 2022
343bc99
Docs and related cleanup.
ericsnekbytes Oct 11, 2022
cc9d8db
Added minor docs updates to utils.
ericsnekbytes Oct 11, 2022
ae646d9
Added more docs.
ericsnekbytes Oct 11, 2022
9cd1352
Merge branch 'playwright_conversion' into pw_workflow
ericsnekbytes Oct 11, 2022
f807eee
Merge branch 'pw_workflow' of github.com:ericsnekbytes/nbclassic into…
ericsnekbytes Oct 11, 2022
abf8bc0
Wait for start refactor WIP.
ericsnekbytes Oct 11, 2022
3a6f99c
Disabled/moved selenium workflow file
ericsnekbytes Oct 11, 2022
43577c8
Made Page objects private.
ericsnekbytes Oct 11, 2022
50733f1
Merge branch 'pw_cleanup_round1' into playwright_conversion
ericsnekbytes Oct 11, 2022
a147f24
Merge branch 'playwright_conversion' into pw_workflow
ericsnekbytes Oct 11, 2022
c850682
Refactor fixture/browser object naming.
ericsnekbytes Oct 12, 2022
0f32dbd
Merge branch 'pw_cleanup_round2' into playwright_conversion
ericsnekbytes Oct 12, 2022
468bc7d
Minor docs updates/fixes.
ericsnekbytes Oct 12, 2022
252b432
test dashboard nav updates for api timeout error
RRosio Oct 13, 2022
6e960c5
Merge branch 'playwright_conversion' into pw_workflow
ericsnekbytes Oct 13, 2022
3a2e6c7
Revert "test dashboard nav updates for api timeout error"
RRosio Oct 14, 2022
7202647
Merge branch 'playwright_conversion' into pw_workflow
RRosio Oct 14, 2022
10566f6
Merge branch 'pw_workflow' of https://github.com/ericsnekbytes/nbclas…
RRosio Oct 14, 2022
2031387
fix for test_dashboard_nav and added utils functions
RRosio Oct 13, 2022
9e04ca5
refactor test_save_readonly_as and test_save_notebook_as and added ut…
RRosio Oct 14, 2022
9947aca
update method name in test_kernel_menu
RRosio Oct 14, 2022
e75e4b6
move/disabled flaky selenium tests
RRosio Oct 14, 2022
a4ac916
update timeout for wait_for_cell_output
RRosio Oct 14, 2022
a176807
Merge branch 'pw_workflow' into playwright_conversion
RRosio Oct 14, 2022
2897524
updated find_and_replace and focus locator in locate_and_focus
RRosio Oct 14, 2022
3ff08b1
flakyness updates
RRosio Oct 14, 2022
9823f05
exception handling for timeout error
RRosio Oct 17, 2022
c3bfc65
Added retry script for CI runner py dependency install step.
ericsnekbytes Oct 17, 2022
b4a8565
Refactor element locator.
ericsnekbytes Oct 17, 2022
b45fab6
Refactor modal check method.
ericsnekbytes Oct 17, 2022
5df05f2
save_as_notebook: wrapped wait_for in try except block
RRosio Oct 17, 2022
9566380
Merge branch 'pw_action_scripts' into playwright_conversion
ericsnekbytes Oct 17, 2022
010ce1f
Merge branch 'pw_debug_test_kernel_menu' into playwright_conversion
ericsnekbytes Oct 17, 2022
4ccc21f
Flakiness updates for text_execute_code and test_kernel_menu + utils
ericsnekbytes Oct 17, 2022
8a44270
Merge branch 'playwright_conversion' into pw_debug_actions
RRosio Oct 17, 2022
773ee23
Merge branch 'playwright_conversion' into pw_debug_actions
RRosio Oct 17, 2022
0a735ef
Fix get_cell_output refactor
ericsnekbytes Oct 17, 2022
1bb8ebf
Updated get_cell_output
ericsnekbytes Oct 17, 2022
2508fa7
Fix wrong classname in FrontendElement
ericsnekbytes Oct 17, 2022
033a10f
updates from wait_for to expect not to be visible
RRosio Oct 17, 2022
b196304
Merge branch 'playwright_conversion' into pw_debug_actions
RRosio Oct 17, 2022
8f90d6e
Refactor test_shutdown
ericsnekbytes Oct 17, 2022
96d3233
Merge branch 'pw_debug_actions' into playwright_conversion
RRosio Oct 17, 2022
5e1704b
Reverted utils edits
ericsnekbytes Oct 17, 2022
c87fe80
Merge branch 'playwright_conversion' of github.com:ericsnekbytes/nbcl…
ericsnekbytes Oct 17, 2022
157c007
update editor page wait for selector
RRosio Oct 18, 2022
3150423
Dummy branch for single test runs
ericsnekbytes Oct 18, 2022
1b2084b
Merge branch 'main' into playwright_conversion
ericsnekbytes Oct 18, 2022
9efdf7c
Merge branch 'playwright_conversion' of github.com:ericsnekbytes/nbcl…
ericsnekbytes Oct 18, 2022
2aca0e4
Merge branch 'playwright_conversion' into pw_single_runs
ericsnekbytes Oct 18, 2022
770b14b
Combine single test runs into one step
ericsnekbytes Oct 18, 2022
e225f09
testing full test suit runs #1
RRosio Oct 18, 2022
05526c4
macos dbg2
RRosio Oct 18, 2022
14f04c9
Added state checks at various points in the test.
ericsnekbytes Oct 19, 2022
1df58f5
Merge branch 'pw_refactor_test_exec_code2' into playwright_conversion
ericsnekbytes Oct 19, 2022
e8f16dc
Added extra checks for cell output.
ericsnekbytes Oct 19, 2022
81da4b6
update save_readonly_as
RRosio Oct 19, 2022
fa3d098
Merge branch 'pw_dbg1' into playwright_conversion
RRosio Oct 19, 2022
16c4162
Merge branch 'pw_refactor_test_exec_code2' into playwright_conversion
ericsnekbytes Oct 19, 2022
e264193
Refactor find/replace to use .value in eval call.
ericsnekbytes Oct 20, 2022
d5ee6a4
Merge branch 'pw_refactor_find_rep2' into playwright_conversion
ericsnekbytes Oct 20, 2022
103f5ca
Added retry to browser fixture
ericsnekbytes Oct 20, 2022
146b072
Removed wait from locate and focus method.
ericsnekbytes Oct 20, 2022
94be604
Temp workflow edits for debugging (add workflows back later)
ericsnekbytes Oct 20, 2022
2ac94b8
Fixed temp workflow run files.
ericsnekbytes Oct 20, 2022
b8a909d
Fixed temp workflow edits.
ericsnekbytes Oct 20, 2022
b5cf67a
Temp workflow edits
ericsnekbytes Oct 20, 2022
d677d66
More workflow edits.
ericsnekbytes Oct 20, 2022
d3bcdc2
Revised timeout on test_kernel_menu, WIP workflow edits.
ericsnekbytes Oct 20, 2022
3525185
Updated workflow files and the test prototyper.
ericsnekbytes Oct 21, 2022
e668ffd
Removed selenium tests.
ericsnekbytes Oct 21, 2022
328a8c7
Added macos back to action, added command printout to install script,…
ericsnekbytes Oct 21, 2022
d3e5a81
Removed selenium from setup.py
ericsnekbytes Oct 21, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Flaky Selenium Tests
name: Playwright Tests

on:
push:
Expand All @@ -11,15 +11,8 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu, macos]
python-version: [ '3.7', '3.8', '3.9']
exclude:
- os: ubuntu
python-version: '3.7'
- os: ubuntu
python-version: '3.9'
- os: macos
python-version: '3.8'
os: [ubuntu]
python-version: [ '3.7', '3.8', '3.9', '3.10']
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -41,13 +34,8 @@ jobs:

- name: Install Python dependencies
run: |
python -m pip install -U pip setuptools wheel
pip install --upgrade selenium
pip install pytest
pip install .[test]
python tools/install_pydeps.py

- name: Run Tests
- name: Run Playwright Tests
run: |
export JUPYTER_TEST_BROWSER=firefox
export MOZ_HEADLESS=1
pytest -sv nbclassic/tests/selenium
pytest -sv nbclassic/tests/end_to_end
53 changes: 0 additions & 53 deletions .github/workflows/selenium.yml

This file was deleted.

162 changes: 162 additions & 0 deletions nbclassic/tests/end_to_end/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
"""Fixtures for pytest/playwright end_to_end tests."""


import datetime
import os
import json
import sys
import time
from os.path import join as pjoin
from subprocess import Popen
from tempfile import mkstemp
from urllib.parse import urljoin

import pytest
import requests
from testpath.tempdir import TemporaryDirectory

import nbformat
from nbformat.v4 import new_notebook, new_code_cell
from .utils import NotebookFrontend, BROWSER_CONTEXT, BROWSER_OBJ, TREE_PAGE, SERVER_INFO


def _wait_for_server(proc, info_file_path):
"""Wait 30 seconds for the notebook server to start"""
for i in range(300):
if proc.poll() is not None:
raise RuntimeError("Notebook server failed to start")
if os.path.exists(info_file_path):
try:
with open(info_file_path) as f:
return json.load(f)
except ValueError:
# If the server is halfway through writing the file, we may
# get invalid JSON; it should be ready next iteration.
pass
time.sleep(0.1)
raise RuntimeError("Didn't find %s in 30 seconds", info_file_path)


@pytest.fixture(scope='function')
def notebook_server():
info = {}
with TemporaryDirectory() as td:
nbdir = info['nbdir'] = pjoin(td, 'notebooks')
os.makedirs(pjoin(nbdir, 'sub ∂ir1', 'sub ∂ir 1a'))
os.makedirs(pjoin(nbdir, 'sub ∂ir2', 'sub ∂ir 1b'))

info['extra_env'] = {
'JUPYTER_CONFIG_DIR': pjoin(td, 'jupyter_config'),
'JUPYTER_RUNTIME_DIR': pjoin(td, 'jupyter_runtime'),
'IPYTHONDIR': pjoin(td, 'ipython'),
}
env = os.environ.copy()
env.update(info['extra_env'])

command = [sys.executable, '-m', 'nbclassic',
'--no-browser',
'--notebook-dir', nbdir,
# run with a base URL that would be escaped,
# to test that we don't double-escape URLs
'--ServerApp.base_url=/a@b/',
]
print("command=", command)
proc = info['popen'] = Popen(command, cwd=nbdir, env=env)
info_file_path = pjoin(td, 'jupyter_runtime',
f'jpserver-{proc.pid:d}.json')
info.update(_wait_for_server(proc, info_file_path))

print("Notebook server info:", info)
yield info

# Shut the server down
requests.post(urljoin(info['url'], 'api/shutdown'),
headers={'Authorization': 'token '+info['token']})


@pytest.fixture(scope='function')
def playwright_browser(playwright):
start = datetime.datetime.now()
while (datetime.datetime.now() - start).seconds < 30:
try:
if os.environ.get('JUPYTER_TEST_BROWSER') == 'chrome':
browser = playwright.chromium.launch()
else:
browser = playwright.firefox.launch()
break
except Exception:
time.sleep(.2)

yield browser

# Teardown
browser.close()


@pytest.fixture(scope='function')
def authenticated_browser_data(playwright_browser, notebook_server):
browser_obj = playwright_browser
browser_context = browser_obj.new_context()
browser_context.jupyter_server_info = notebook_server
tree_page = browser_context.new_page()
tree_page.goto("{url}?token={token}".format(**notebook_server))

auth_browser_data = {
BROWSER_CONTEXT: browser_context,
TREE_PAGE: tree_page,
SERVER_INFO: notebook_server,
BROWSER_OBJ: browser_obj,
}

return auth_browser_data


@pytest.fixture(scope='function')
def notebook_frontend(authenticated_browser_data):
yield NotebookFrontend.new_notebook_frontend(authenticated_browser_data)


@pytest.fixture(scope='function')
def prefill_notebook(playwright_browser, notebook_server):
browser_obj = playwright_browser
browser_context = browser_obj.new_context()
# playwright_browser is the browser_context,
# notebook_server is the server with directories

# the return of function inner takes in a dictionary of strings to populate cells
def inner(cells):
cells = [new_code_cell(c) if isinstance(c, str) else c
for c in cells]
# new_notebook is an nbformat function that is imported so that it can create a
# notebook that is formatted as it needs to be
nb = new_notebook(cells=cells)

# Create temporary file directory and store it's reference as well as the path
fd, path = mkstemp(dir=notebook_server['nbdir'], suffix='.ipynb')

# Open the file and write the format onto the file
with open(fd, 'w', encoding='utf-8') as f:
nbformat.write(nb, f)

# Grab the name of the file
fname = os.path.basename(path)

# Add the notebook server as a property of the playwright browser with the name jupyter_server_info
browser_context.jupyter_server_info = notebook_server
# Open a new page in the browser and refer to it as the tree page
tree_page = browser_context.new_page()

# Navigate that page to the base URL page AKA the tree page
tree_page.goto("{url}?token={token}".format(**notebook_server))

auth_browser_data = {
BROWSER_CONTEXT: browser_context,
TREE_PAGE: tree_page,
SERVER_INFO: notebook_server,
BROWSER_OBJ: browser_obj
}

return NotebookFrontend.new_notebook_frontend(auth_browser_data, existing_file_name=fname)

# Return the function that will take in the dict of code strings
return inner
30 changes: 30 additions & 0 deletions nbclassic/tests/end_to_end/manual_test_prototyper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""Test basic cell execution methods, related shortcuts, and error modes

Run this manually:
# Normal pytest run
pytest nbclassic/tests/end_to_end/test_interrupt.py
# with playwright debug (run and poke around in the web console)
PWDEBUG=1 pytest -s nbclassic/tests/end_to_end/test_interrupt.py
"""


from .utils import TREE_PAGE, EDITOR_PAGE


# # Use/uncomment this for manual test prototytping
# # (the test suite will run this if it's uncommented)
# def test_do_something(notebook_frontend):
# # Do something with the notebook_frontend here
# notebook_frontend.add_cell()
# notebook_frontend.add_cell()
# assert len(notebook_frontend.cells) == 3
#
# notebook_frontend.delete_all_cells()
# assert len(notebook_frontend.cells) == 1
#
# notebook_frontend.editor_page.pause()
# cell_texts = ['aa = 1', 'bb = 2', 'cc = 3']
# a, b, c = cell_texts
# notebook_frontend.populate(cell_texts)
# assert notebook_frontend.get_cells_contents() == [a, b, c]
# notebook_frontend._pause()
45 changes: 45 additions & 0 deletions nbclassic/tests/end_to_end/test_buffering.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"""Tests buffering of execution requests."""


from .utils import TREE_PAGE, EDITOR_PAGE


def test_kernels_buffer_without_conn(prefill_notebook):
"""Test that execution request made while disconnected is buffered."""

notebook_frontend = prefill_notebook(["print(1 + 2)"])
notebook_frontend.wait_for_kernel_ready()

notebook_frontend.evaluate("() => { IPython.notebook.kernel.stop_channels }", page=EDITOR_PAGE)
notebook_frontend.execute_cell(0)

notebook_frontend.evaluate("() => { IPython.notebook.kernel.reconnect }", page=EDITOR_PAGE)
notebook_frontend.wait_for_kernel_ready()

outputs = notebook_frontend.wait_for_cell_output(0)
assert outputs.get_inner_text().strip() == '3'


def test_buffered_cells_execute_in_order(prefill_notebook):
"""Test that buffered requests execute in order."""

notebook_frontend = prefill_notebook(['', 'k=1', 'k+=1', 'k*=3', 'print(k)'])

# Repeated execution of cell queued up in the kernel executes
# each execution request in order.
notebook_frontend.wait_for_kernel_ready()
notebook_frontend.evaluate("() => IPython.notebook.kernel.stop_channels();", page=EDITOR_PAGE)
# k == 1
notebook_frontend.execute_cell(1)
# k == 2
notebook_frontend.execute_cell(2)
# k == 6
notebook_frontend.execute_cell(3)
# k == 7
notebook_frontend.execute_cell(2)
notebook_frontend.execute_cell(4)
notebook_frontend.evaluate("() => IPython.notebook.kernel.reconnect();", page=EDITOR_PAGE)
notebook_frontend.wait_for_kernel_ready()

outputs = notebook_frontend.wait_for_cell_output(4)
assert outputs.get_inner_text().strip() == '7'
48 changes: 48 additions & 0 deletions nbclassic/tests/end_to_end/test_clipboard_multiselect.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"""Tests clipboard by copying, cutting and pasting multiple cells"""


from .utils import TREE_PAGE, EDITOR_PAGE


# Optionally perfom this test with Ctrl+c and Ctrl+v
def test_clipboard_multiselect(prefill_notebook):
notebook = prefill_notebook(['', '1', '2', '3', '4', '5a', '6b', '7c', '8d'])

assert notebook.get_cells_contents() == ['', '1', '2', '3', '4', '5a', '6b', '7c', '8d']

# Copy the first 3 cells
# Paste the values copied from the first three cells into the last 3 cells

# Selecting the fist 3 cells
notebook.select_cell_range(1, 3)

# Copy those selected cells
notebook.try_click_selector('#editlink', page=EDITOR_PAGE)
notebook.try_click_selector('//*[@id="copy_cell"]/a/span[1]', page=EDITOR_PAGE)

# Select the last 3 cells
notebook.select_cell_range(6, 8)

# Paste the cells in clipboard onto selected cells
notebook.try_click_selector('#editlink', page=EDITOR_PAGE)
notebook.try_click_selector('//*[@id="paste_cell_replace"]/a', page=EDITOR_PAGE)

assert notebook.get_cells_contents() == ['', '1', '2', '3', '4', '5a', '1', '2', '3']

# Select the last four cells, cut them and paste them below the first cell

# Select the last 4 cells
notebook.select_cell_range(5, 8)

# Click Edit button and the select cut button
notebook.try_click_selector('#editlink', page=EDITOR_PAGE)
notebook.try_click_selector('//*[@id="cut_cell"]/a', page=EDITOR_PAGE)

# Select the first cell
notebook.select_cell_range(0, 0)

# Paste the cells in our clipboard below this first cell we are focused at
notebook.try_click_selector('#editlink', page=EDITOR_PAGE)
notebook.try_click_selector('//*[@id="paste_cell_below"]/a/span[1]', page=EDITOR_PAGE)

assert notebook.get_cells_contents() == ['', '5a', '1', '2', '3', '1', '2', '3', '4']
Loading