Skip to content

Commit 678fb0c

Browse files
committed
Test chrome as well as firefox
1 parent c29aacd commit 678fb0c

File tree

4 files changed

+54
-10
lines changed

4 files changed

+54
-10
lines changed

.github/workflows/build.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,11 @@ jobs:
106106
run: |
107107
python -mpip install dist/*.whl
108108
109-
- name: Run pytest
110-
run: pytest -vs tests
109+
- name: Run pytest (firefox)
110+
run: python -mpytest -vs tests --browser=firefox
111+
112+
- name: Run pytest (chrome)
113+
run: python -mpytest -vs tests --browser=chrome
111114

112115
# https://packaging.python.org/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/
113116
publish-pypi:

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ This extension can be configured in `jupyter_notebook_config.py` by setting the
5959
# Warning
6060

6161
This extension is still in development.
62-
It is only tested on Firefox.
6362
Breaking changes may occur in future.
6463

6564
There are [several major limitations](https://github.com/manics/jupyter-offlinenotebook/issues) including:
@@ -75,7 +74,6 @@ This extension stores notebooks in browser storage using the [IndexedDB API](htt
7574
One server API call is made during initialisation to obtain the storage configuration.
7675
Everything else is done client-side so should work even if the server is disconnected.
7776

78-
The CI pipeline builds the extension with JupyterLab 4, but the build package works with JupyterLab 3 and NBclassic.
7977
Install the development dependencies:
8078

8179
pip install -r dev-requirements-jl4.txt

tests/conftest.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import pytest
2+
3+
4+
def pytest_addoption(parser):
5+
parser.addoption(
6+
"--browser",
7+
action="store",
8+
default="firefox",
9+
help="browser to run tests on",
10+
choices=("firefox", "chrome"),
11+
)
12+
13+
14+
@pytest.fixture
15+
def browser(request):
16+
return request.config.getoption("--browser")

tests/test_offlinenotebook.py

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
from selenium.webdriver.common.by import By
1515

1616
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
17-
from selenium.webdriver.firefox.options import Options
17+
from selenium.webdriver.firefox.options import Options as FirefoxOptions
18+
from selenium.webdriver.chrome.options import Options as ChromeOptions
1819

1920

2021
PORT = 18888
@@ -111,7 +112,7 @@ def initialise_firefox(self, downloaddir, url):
111112
"browser.helperApps.neverAsk.saveToDisk", "application/x-ipynb+json"
112113
)
113114

114-
options = Options()
115+
options = FirefoxOptions()
115116
if HEADLESS:
116117
options.add_argument("-headless")
117118

@@ -124,7 +125,28 @@ def initialise_firefox(self, downloaddir, url):
124125
self.driver.get(url)
125126
print("Firefox Initialized")
126127

127-
def initialise(self, tmpdir, app, url):
128+
def initialise_chrome(self, downloaddir, url):
129+
"""Initialises a Chrome webdriver with download preferences."""
130+
options = ChromeOptions()
131+
if HEADLESS:
132+
options.add_argument("--headless=new")
133+
134+
prefs = {
135+
"download.default_directory": downloaddir,
136+
"download.prompt_for_download": False,
137+
"safebrowsing.enabled": True,
138+
}
139+
options.add_experimental_option("prefs", prefs)
140+
141+
self.driver = webdriver.Chrome(options=options)
142+
self.wait = WebDriverWait(self.driver, TIMEOUT)
143+
144+
self.driver.get(url)
145+
# Default size is too narrow, so toolbar is partially hidden
146+
self.driver.set_window_size(1024, 768)
147+
print("Chrome Initialized")
148+
149+
def initialise(self, tmpdir, app, url, browser):
128150
jupyterdir = (tmpdir / "jupyter").mkdir()
129151
downloaddir = (tmpdir / "download").mkdir()
130152

@@ -136,7 +158,12 @@ def initialise(self, tmpdir, app, url):
136158
self.expected_download = str(downloaddir / "example.ipynb")
137159

138160
self.start_jupyter(jupyterdir, app)
139-
self.initialise_firefox(str(downloaddir), url)
161+
if browser == "firefox":
162+
self.initialise_firefox(str(downloaddir), url)
163+
elif browser == "chrome":
164+
self.initialise_chrome(str(downloaddir), url)
165+
else:
166+
pytest.fail(f"Unsupported browser: {browser}")
140167

141168

142169
class TestOfflineLab(FirefoxTestBase):
@@ -201,11 +228,11 @@ def restore_from_browser_storage(self):
201228
@pytest.mark.flaky(max_runs=3)
202229
# Notebook 7 is based on JupyterLab
203230
@pytest.mark.parametrize("app", ["lab", "notebook"])
204-
def test_offline_lab(self, tmpdir, app):
231+
def test_offline_lab(self, tmpdir, app, browser):
205232
# Selenium can't access IndexedDB so instead check save/load by
206233
# downloading the updated notebook
207234

208-
self.initialise(tmpdir, app, JUPYTER_URL[app])
235+
self.initialise(tmpdir, app, JUPYTER_URL[app], browser)
209236
self.toolbar_button = "jp-button"
210237

211238
# Wait for the loading logo to appear, then disappear

0 commit comments

Comments
 (0)