Skip to content

Commit

Permalink
Merge pull request #4310 from takluyver/selenium-multiselect
Browse files Browse the repository at this point in the history
Convert multiselect test to Selenium
  • Loading branch information
takluyver authored Jan 8, 2019
2 parents 31c2184 + 9035cb1 commit 09b8c93
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 102 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ __pycache__
\#*#
.#*
.coverage
.pytest_cache
src

*.swp
Expand All @@ -38,4 +39,5 @@ config.rst
/.project
/.pydevproject

package-lock.json
package-lock.json
geckodriver.log
100 changes: 0 additions & 100 deletions notebook/tests/notebook/multiselect.js

This file was deleted.

65 changes: 65 additions & 0 deletions notebook/tests/selenium/test_multiselect.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
def test_multiselect(notebook):
def extend_selection_by(delta):
notebook.browser.execute_script(
"Jupyter.notebook.extend_selection_by(arguments[0]);", delta)

def n_selected_cells():
return notebook.browser.execute_script(
"return Jupyter.notebook.get_selected_cells().length;")

a = 'print("a")'
b = 'print("b")'
c = 'print("c")'
notebook.edit_cell(index=0, content=a)
notebook.append(b, c)

notebook.focus_cell(0)
assert n_selected_cells() == 1

# Check that only one cell is selected according to CSS classes as well
selected_css = notebook.browser.find_elements_by_css_selector(
'.cell.jupyter-soft-selected, .cell.selected')
assert len(selected_css) == 1

# Extend the selection down one
extend_selection_by(1)
assert n_selected_cells() == 2

# Contract the selection up one
extend_selection_by(-1)
assert n_selected_cells() == 1

# Extend the selection up one
notebook.focus_cell(1)
extend_selection_by(-1)
assert n_selected_cells() == 2

# Convert selected cells to Markdown
notebook.browser.execute_script("Jupyter.notebook.cells_to_markdown();")
cell_types = notebook.browser.execute_script(
"return Jupyter.notebook.get_cells().map(c => c.cell_type)")
assert cell_types == ['markdown', 'markdown', 'code']
# One cell left selected after conversion
assert n_selected_cells() == 1

# Convert selected cells to raw
notebook.focus_cell(1)
extend_selection_by(1)
assert n_selected_cells() == 2
notebook.browser.execute_script("Jupyter.notebook.cells_to_raw();")
cell_types = notebook.browser.execute_script(
"return Jupyter.notebook.get_cells().map(c => c.cell_type)")
assert cell_types == ['markdown', 'raw', 'raw']
# One cell left selected after conversion
assert n_selected_cells() == 1

# Convert selected cells to code
notebook.focus_cell(0)
extend_selection_by(2)
assert n_selected_cells() == 3
notebook.browser.execute_script("Jupyter.notebook.cells_to_code();")
cell_types = notebook.browser.execute_script(
"return Jupyter.notebook.get_cells().map(c => c.cell_type)")
assert cell_types == ['code'] * 3
# One cell left selected after conversion
assert n_selected_cells() == 1
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
zip_safe = False,
install_requires = [
'jinja2',
'tornado>=4',
'tornado>=4, <6',
# pyzmq>=17 is not technically necessary,
# but hopefully avoids incompatibilities with Tornado 5. April 2018
'pyzmq>=17',
Expand Down

0 comments on commit 09b8c93

Please sign in to comment.