Skip to content

Commit 2aca6f9

Browse files
authored
Merge pull request #3508 from Sheshtawy/convert-dualmode-insertcell-to-selenium
Convert dualmode_insertcell.js
2 parents 6d258b5 + b25a142 commit 2aca6f9

File tree

4 files changed

+64
-84
lines changed

4 files changed

+64
-84
lines changed

notebook/tests/notebook/dualmode_cellinsert.js

-82
This file was deleted.

notebook/tests/selenium/test_deletecell.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import os
2-
import pytest
31

42
def cell_is_deletable(nb, index):
53
JS = 'return Jupyter.notebook.get_cell({}).is_deletable();'.format(index)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
from selenium.webdriver.common.keys import Keys
2+
from .utils import shift
3+
4+
def test_insert_cell(notebook):
5+
a = "print('a')"
6+
b = "print('b')"
7+
c = "print('c')"
8+
9+
notebook.edit_cell(index=0, content=a)
10+
notebook.append(b, c)
11+
notebook.to_command_mode()
12+
13+
assert notebook.get_cells_contents() == [a, b, c]
14+
15+
notebook.to_command_mode()
16+
notebook.focus_cell(2)
17+
notebook.convert_cell_type(2, "markdown")
18+
19+
# insert code cell above
20+
notebook.current_cell.send_keys("a")
21+
assert notebook.get_cell_contents(2) == ""
22+
assert notebook.get_cell_type(2) == "code"
23+
assert len(notebook.cells) == 4
24+
25+
# insert code cell below
26+
notebook.current_cell.send_keys("b")
27+
assert notebook.get_cell_contents(2) == ""
28+
assert notebook.get_cell_contents(3) == ""
29+
assert notebook.get_cell_type(3) == "code"
30+
assert len(notebook.cells) == 5
31+
32+
notebook.edit_cell(index=1, content="cell1")
33+
notebook.focus_cell(1)
34+
notebook.current_cell.send_keys("a")
35+
assert notebook.get_cell_contents(1) == ""
36+
assert notebook.get_cell_contents(2) == "cell1"
37+
38+
notebook.edit_cell(index=1, content='cell1')
39+
notebook.edit_cell(index=2, content='cell2')
40+
notebook.edit_cell(index=3, content='cell3')
41+
notebook.focus_cell(2)
42+
notebook.current_cell.send_keys("b")
43+
assert notebook.get_cell_contents(1) == "cell1"
44+
assert notebook.get_cell_contents(2) == "cell2"
45+
assert notebook.get_cell_contents(3) == ""
46+
assert notebook.get_cell_contents(4) == "cell3"
47+
48+
# insert above multiple selected cells
49+
notebook.focus_cell(1)
50+
shift(notebook.browser, Keys.DOWN)
51+
notebook.current_cell.send_keys('a')
52+
53+
# insert below multiple selected cells
54+
notebook.focus_cell(2)
55+
shift(notebook.browser, Keys.DOWN)
56+
notebook.current_cell.send_keys('b')
57+
assert notebook.get_cells_contents()[1:5] == ["", "cell1", "cell2", ""]

notebook/tests/selenium/utils.py

+7
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,17 @@ def get_cells_contents(self):
131131
JS = 'return Jupyter.notebook.get_cells().map(function(c) {return c.get_text();})'
132132
return self.browser.execute_script(JS)
133133

134+
def get_cell_contents(self, index=0, selector='div .CodeMirror-code'):
135+
return self.cells[index].find_element_by_css_selector(selector).text
136+
134137
def set_cell_metadata(self, index, key, value):
135138
JS = 'Jupyter.notebook.get_cell({}).metadata.{} = {}'.format(index, key, value)
136139
return self.browser.execute_script(JS)
137140

141+
def get_cell_type(self, index=0):
142+
JS = 'return Jupyter.notebook.get_cell({}).cell_type'.format(index)
143+
return self.browser.execute_script(JS)
144+
138145
def set_cell_input_prompt(self, index, prmpt_val):
139146
JS = 'Jupyter.notebook.get_cell({}).set_input_prompt({})'.format(index, prmpt_val)
140147
self.browser.execute_script(JS)

0 commit comments

Comments
 (0)