-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
Selenium utils + markdown rendering tests #3458
Merged
Merged
Changes from all commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
9d4cf94
add utils module and wait_for_selector
mpacer 7c659f5
add quick_selenium script for quickly starting up a selenium interact…
mpacer 0994db2
Introduce Notebook class and give usage example in quick_selenium
mpacer f9dd7c1
add basic cell functionality to Notebook class
mpacer c9a8504
add body property
mpacer 3d3086e
add edit_cell and execute_cell methods; remove focus_cell edit parameter
mpacer 4b6a0a7
Add CellTypeError and convert_cell_type and wait_for_stale_cell methods
mpacer 2b7f549
Add add_cell and add_markdown_cell methods
mpacer e2243d6
add method that allows you to close the notebook without confirming
mpacer 86ae162
add first markdown test and a notebook fixture for new notebook
mpacer bf39dec
move sauce driver logic into isolated function, simplify selenium_driver
mpacer e0ed2c4
make authenticated browser module scope fixture for permission reasons
mpacer c220215
use wait_for_selector from utils module in test_dashboard_nav
mpacer 3092800
add wait_for_selector to the cells property and to_command_mode
mpacer 3615d4a
enhance wait_for_selector to handle returning single elements
mpacer d634f1d
add new_window contextmanager for creating, switching, & waiting on n…
mpacer a112ab6
add select_kernel function for clicking "new" & selecting a kernel
mpacer ebef7ba
create new_notebook classmethod creating/switching to new Notebook page
mpacer 5d19785
small changes to naming things
mpacer 3571f16
introduce cell __iter__, & __setitem__/__getitem__ for cells & indices
mpacer e183fc1
enrich signature for execute_cell to accept both index and cell directly
mpacer c16dac2
use new rich container __*__ methods to make adding & executing nicer
mpacer e9971a9
simplify __getitem__ __setitem__ to handle only ints/slices and ints
mpacer bf4868d
remove wait_for_selector call inside self.cells property
mpacer 02e0ac3
fix add_cell logic, add content param, edit_cell default not render
mpacer 98c09f8
use index method to get cell index in execute_cell
mpacer 5e43458
add append, extend & coerce_to_cell methods
mpacer d9dd5d8
add run_all method
mpacer 33ca649
add get_rendered_contents helper function
mpacer 0999798
use new utilities, enable more markdown cells to be added easily
mpacer 7808a89
make append actually append to the end of cell list
mpacer c081af5
add other markdown string conversion examples for test
mpacer d598ef5
switch fstring to format string
mpacer 3c4596b
Take into account lab as a potential endpoint for the driver
mpacer 79603b4
add quick_notebook utility and give docstring reminder to quit browsers
mpacer 74af79c
Improve docstrings & comments; Remove unused code; Relocate script
mpacer 515f8e2
nicer error and use append directly do not iterate over cells
mpacer c23ba2a
Docstrings and naming clarity
takluyver a6f604a
No need for copy
takluyver 7266fd5
Remove unused variant of append for now
takluyver File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
"""Utilities for driving Selenium interactively to develop tests. | ||
|
||
These are not used in the tests themselves - rather, the developer writing tests | ||
can use them to experiment with Selenium. | ||
""" | ||
from selenium.webdriver import Firefox | ||
|
||
from notebook.tests.selenium.utils import Notebook | ||
from notebook.notebookapp import list_running_servers | ||
|
||
class NoServerError(Exception): | ||
|
||
def __init__(self, message): | ||
self.message = message | ||
|
||
def quick_driver(lab=False): | ||
"""Quickly create a selenium driver pointing at an active noteboook server. | ||
|
||
Usage example: | ||
|
||
from notebook.tests.selenium.quick_selenium import quick_driver | ||
driver = quick_driver | ||
|
||
Note: you need to manually close the driver that opens with driver.quit() | ||
""" | ||
try: | ||
server = list(list_running_servers())[0] | ||
except IndexError as e: | ||
raise NoServerError('You need a server running before you can run ' | ||
'this command') | ||
driver = Firefox() | ||
auth_url = '{url}?token={token}'.format(**server) | ||
driver.get(auth_url) | ||
|
||
# If this redirects us to a lab page and we don't want that; | ||
# then we need to redirect ourselves to the classic notebook view | ||
if driver.current_url.endswith('/lab') and not lab: | ||
driver.get(driver.current_url.rstrip('lab')+'tree') | ||
return driver | ||
|
||
|
||
def quick_notebook(): | ||
"""Quickly create a new classic notebook in a selenium driver | ||
|
||
|
||
Usage example: | ||
|
||
from notebook.tests.selenium.quick_selenium import quick_notebook | ||
nb = quick_notebook() | ||
|
||
Note: you need to manually close the driver that opens with nb.browser.quit() | ||
""" | ||
return Notebook.new_notebook(quick_driver()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import os | ||
|
||
import pytest | ||
from selenium.webdriver.common.keys import Keys | ||
|
||
from .utils import wait_for_selector, Notebook | ||
|
||
pjoin = os.path.join | ||
|
||
|
||
@pytest.fixture | ||
def notebook(authenticated_browser): | ||
return Notebook.new_notebook(authenticated_browser) | ||
|
||
|
||
def get_rendered_contents(nb): | ||
cl = ["text_cell", "render"] | ||
rendered_cells = [cell.find_element_by_class_name("text_cell_render") | ||
for cell in nb.cells | ||
if all([c in cell.get_attribute("class") for c in cl])] | ||
return [x.get_attribute('innerHTML').strip() | ||
for x in rendered_cells | ||
if x is not None] | ||
|
||
|
||
def test_markdown_cell(notebook): | ||
nb = notebook | ||
cell_text = ["# Foo", | ||
'**Bar**', | ||
'*Baz*', | ||
'```\nx = 1\n```', | ||
'```aaaa\nx = 1\n```', | ||
] | ||
expected_contents = ['<h1 id="Foo">Foo<a class="anchor-link" href="#Foo">¶</a></h1>', | ||
'<p><strong>Bar</strong></p>', | ||
'<p><em>Baz</em></p>', | ||
'<pre><code>x = 1\n</code></pre>', | ||
'<pre><code class="cm-s-ipython language-aaaa">x = 1\n</code></pre>' | ||
] | ||
nb.append(*cell_text, cell_type="markdown") | ||
nb.run_all() | ||
rendered_contents = get_rendered_contents(nb) | ||
assert rendered_contents == expected_contents |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's have a module level docstring to explain that these utilities are not used by the tests, but they're intended for interactive exploration while writing tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had intended to add this.