|
19 | 19 |
|
20 | 20 | PORT = 18888 |
21 | 21 | CONFIG_URL = f"http://localhost:{PORT}/offlinenotebook/config" |
22 | | -JUPYTERLAB_URL = f"http://localhost:{PORT}/lab/tree/example.ipynb" |
23 | | -JUPYTERNOTEBOOK_URL = f"http://localhost:{PORT}/tree/example.ipynb" |
| 22 | +JUPYTER_URL = { |
| 23 | + "lab": f"http://localhost:{PORT}/lab/tree/example.ipynb", |
| 24 | + "notebook": f"http://localhost:{PORT}/tree/example.ipynb", |
| 25 | +} |
24 | 26 | EXPECTED_SIZE = 1700 |
25 | 27 | EXPECTED_EMPTY_SIZE = 450 |
26 | 28 | EXPECTED_NUM_CELLS = 5 |
@@ -136,107 +138,6 @@ def initialise(self, tmpdir, app, url): |
136 | 138 | self.initialise_firefox(str(downloaddir), url) |
137 | 139 |
|
138 | 140 |
|
139 | | -class TestOfflineNotebook(FirefoxTestBase): |
140 | | - def download_visible(self): |
141 | | - self.wait.until( |
142 | | - EC.element_to_be_clickable( |
143 | | - (By.XPATH, "//button[@title='Download visible']") |
144 | | - ) |
145 | | - ).click() |
146 | | - |
147 | | - size = os.stat(self.expected_download).st_size |
148 | | - with open(self.expected_download) as f: |
149 | | - nb = json.load(f) |
150 | | - ncells = len(nb["cells"]) |
151 | | - os.remove(self.expected_download) |
152 | | - return size, ncells |
153 | | - |
154 | | - def save_to_browser_storage(self): |
155 | | - self.driver.find_element( |
156 | | - By.XPATH, "//button[@title='Save to browser storage']" |
157 | | - ).click() |
158 | | - dialog = self.wait.until( |
159 | | - EC.visibility_of_element_located((By.CSS_SELECTOR, "div.modal-dialog")) |
160 | | - ) |
161 | | - |
162 | | - assert dialog.find_element(By.CSS_SELECTOR, "h4.modal-title").text == ( |
163 | | - "Notebook saved to browser storage" |
164 | | - ) |
165 | | - assert dialog.find_element(By.CSS_SELECTOR, "div.modal-body").text == ( |
166 | | - "repoid: https://github.com/manics/jupyter-offlinenotebook\n" |
167 | | - "path: example.ipynb" |
168 | | - ) |
169 | | - dialog.find_element(By.CSS_SELECTOR, "button.btn-default").click() |
170 | | - |
171 | | - def restore_from_browser_storage(self): |
172 | | - self.driver.find_element( |
173 | | - By.XPATH, "//button[@title='Restore from browser storage']" |
174 | | - ).click() |
175 | | - dialog = self.wait.until( |
176 | | - EC.visibility_of_element_located((By.CSS_SELECTOR, "div.modal-dialog")) |
177 | | - ) |
178 | | - |
179 | | - assert dialog.find_element(By.CSS_SELECTOR, "h4.modal-title").text == ( |
180 | | - "This will replace your current notebook with" |
181 | | - ) |
182 | | - assert dialog.find_element(By.CSS_SELECTOR, "div.modal-body").text == ( |
183 | | - "repoid: https://github.com/manics/jupyter-offlinenotebook\n" |
184 | | - "path: example.ipynb" |
185 | | - ) |
186 | | - buttons = dialog.find_elements(By.CSS_SELECTOR, "button.btn-default") |
187 | | - assert buttons[0].text == "OK" |
188 | | - assert buttons[1].text == "Cancel" |
189 | | - buttons[0].click() |
190 | | - |
191 | | - def wait_for_modal_dialog(self): |
192 | | - # element_to_be_clickable doesn't actually mean clickable |
193 | | - # so need to make sure the modal dialog has cleared |
194 | | - # https://stackoverflow.com/a/51842120 |
195 | | - self.wait.until( |
196 | | - EC.invisibility_of_element_located( |
197 | | - (By.XPATH, "//div[@class='modal-backdrop']") |
198 | | - ) |
199 | | - ) |
200 | | - # Still doesn't work so force a pause |
201 | | - sleep(0.5) |
202 | | - |
203 | | - @pytest.mark.flaky(max_runs=3) |
204 | | - def test_offline_notebook(self, tmpdir): |
205 | | - # Selenium can't access IndexedDB so instead check save/load by |
206 | | - # downloading the updated notebook |
207 | | - |
208 | | - self.initialise(tmpdir, "nbclassic", JUPYTERNOTEBOOK_URL) |
209 | | - |
210 | | - size, ncells = self.download_visible() |
211 | | - assert_expected_size(size) |
212 | | - assert ncells == EXPECTED_NUM_CELLS |
213 | | - |
214 | | - self.save_to_browser_storage() |
215 | | - print("Saved to browser storage") |
216 | | - |
217 | | - # Delete some cells and download |
218 | | - # element_to_be_clickable doesn't actually mean clickable |
219 | | - self.wait_for_modal_dialog() |
220 | | - for n in range(EXPECTED_NUM_CELLS): |
221 | | - self.wait.until( |
222 | | - EC.element_to_be_clickable( |
223 | | - (By.XPATH, "//button[@title='cut selected cells']") |
224 | | - ) |
225 | | - ).click() |
226 | | - size, ncells = self.download_visible() |
227 | | - assert_empty_size(size) |
228 | | - assert ncells == 1 |
229 | | - |
230 | | - self.restore_from_browser_storage() |
231 | | - |
232 | | - # download_visible uses element_to_be_clickable but that doesn't |
233 | | - # actually mean clickable |
234 | | - self.wait_for_modal_dialog() |
235 | | - size, ncells = self.download_visible() |
236 | | - assert_expected_size(size) |
237 | | - assert ncells == EXPECTED_NUM_CELLS |
238 | | - |
239 | | - |
240 | 141 | class TestOfflineLab(FirefoxTestBase): |
241 | 142 | def download_visible(self): |
242 | 143 | self.wait.until( |
@@ -297,16 +198,14 @@ def restore_from_browser_storage(self): |
297 | 198 | buttons[1].click() |
298 | 199 |
|
299 | 200 | @pytest.mark.flaky(max_runs=3) |
300 | | - def test_offline_lab(self, tmpdir): |
| 201 | + # Notebook 7 is based on JupyterLab |
| 202 | + @pytest.mark.parametrize("app", ["lab", "notebook"]) |
| 203 | + def test_offline_lab(self, tmpdir, app): |
301 | 204 | # Selenium can't access IndexedDB so instead check save/load by |
302 | 205 | # downloading the updated notebook |
303 | 206 |
|
304 | | - self.initialise(tmpdir, "lab", JUPYTERLAB_URL) |
305 | | - assert self.major_version in (3, 4) |
306 | | - if self.major_version == 3: |
307 | | - self.toolbar_button = "button" |
308 | | - else: |
309 | | - self.toolbar_button = "jp-button" |
| 207 | + self.initialise(tmpdir, app, JUPYTER_URL[app]) |
| 208 | + self.toolbar_button = "jp-button" |
310 | 209 |
|
311 | 210 | # Wait for the loading logo to appear, then disappear |
312 | 211 | try: |
|
0 commit comments