Skip to content

Commit eb52418

Browse files
authored
Merge pull request #6484 from ericsnekbytes/selenium_test_updates
Selenium test updates
2 parents dc64e03 + 446d02e commit eb52418

15 files changed

+64
-31
lines changed

notebook/tests/selenium/test_dashboard_nav.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import os
22

3+
from selenium.webdriver.common.by import By
4+
35
from notebook.utils import url_path_join
46
from notebook.tests.selenium.utils import wait_for_selector
57
pjoin = os.path.join
@@ -31,9 +33,9 @@ def get_list_items(browser):
3133

3234
return [{
3335
'link': a.get_attribute('href'),
34-
'label': a.find_element_by_class_name('item_name').text,
36+
'label': a.find_element(By.CLASS_NAME, 'item_name').text,
3537
'element': a,
36-
} for a in browser.find_elements_by_class_name('item_link')]
38+
} for a in browser.find_elements(By.CLASS_NAME, 'item_link')]
3739

3840
def only_dir_links(browser):
3941
"""Return only links that point at other directories in the tree"""

notebook/tests/selenium/test_display_image.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
The effect of shape metadata is validated, using Image(retina=True)
44
"""
55

6+
from selenium.webdriver.common.by import By
7+
68
from .utils import wait_for_tag
79

810

@@ -36,7 +38,7 @@ def validate_img(notebook, cell_index, image_fmt, retina):
3638

3739
# Find the image element that was just displayed
3840
wait_for_tag(notebook.cells[cell_index], "img", single=True)
39-
img_element = notebook.cells[cell_index].find_element_by_tag_name("img")
41+
img_element = notebook.cells[cell_index].find_element(By.TAG_NAME, "img")
4042

4143
src = img_element.get_attribute("src")
4244
prefix = src.split(',')[0]

notebook/tests/selenium/test_display_isolation.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
An object whose metadata contains an "isolated" tag must be isolated
44
from the rest of the document.
55
"""
6+
7+
from selenium.webdriver.common.by import By
8+
69
from .utils import wait_for_tag
710

811

@@ -43,16 +46,16 @@ def isolated_html(notebook):
4346
iframe = wait_for_tag(notebook.browser, "iframe", single=True)
4447

4548
# The non-isolated div will be in the body
46-
non_isolated_div = notebook.body.find_element_by_id("non-isolated")
49+
non_isolated_div = notebook.body.find_element(By.ID, "non-isolated")
4750
assert non_isolated_div.value_of_css_property("color") == red
4851

4952
# The non-isolated styling will have affected the output of other cells
50-
test_div = notebook.body.find_element_by_id("test")
53+
test_div = notebook.body.find_element(By.ID, "test")
5154
assert test_div.value_of_css_property("color") == red
5255

5356
# The isolated div will be in an iframe, only that element will be blue
5457
notebook.browser.switch_to.frame(iframe)
55-
isolated_div = notebook.browser.find_element_by_id("isolated")
58+
isolated_div = notebook.browser.find_element(By.ID, "isolated")
5659
assert isolated_div.value_of_css_property("color") == blue
5760
notebook.browser.switch_to.default_content()
5861
# Clean up the html test cells
@@ -80,13 +83,13 @@ def isolated_svg(notebook):
8083

8184
# The first rectangle will be red
8285
notebook.browser.switch_to.frame(iframes[0])
83-
isolated_svg_1 = notebook.browser.find_element_by_id('r1')
86+
isolated_svg_1 = notebook.browser.find_element(By.ID, 'r1')
8487
assert isolated_svg_1.value_of_css_property("fill") == yellow
8588
notebook.browser.switch_to.default_content()
8689

8790
# The second rectangle will be black
8891
notebook.browser.switch_to.frame(iframes[1])
89-
isolated_svg_2 = notebook.browser.find_element_by_id('r2')
92+
isolated_svg_2 = notebook.browser.find_element(By.ID, 'r2')
9093
assert isolated_svg_2.value_of_css_property("fill") == black
9194

9295
# Clean up the svg test cells

notebook/tests/selenium/test_dualmode_arrows.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Tests arrow keys on both command and edit mode"""
2+
from selenium.webdriver.common.by import By
23
from selenium.webdriver.common.keys import Keys
34

45
def test_dualmode_arrows(notebook):
@@ -76,7 +77,7 @@ def test_dualmode_arrows(notebook):
7677

7778
# Tests in edit mode.
7879
# First, erase the previous content and then setup the cells to test the keys to move up.
79-
[notebook.browser.find_element_by_class_name("fa-cut.fa").click() for i in range(6)]
80+
[notebook.browser.find_element(By.CLASS_NAME, "fa-cut.fa").click() for i in range(6)]
8081
[notebook.body.send_keys("b") for i in range(2)]
8182
notebook.body.send_keys("a")
8283
notebook.body.send_keys(Keys.ENTER)

notebook/tests/selenium/test_execute_code.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from selenium.webdriver.common.by import By
12
from selenium.webdriver.common.keys import Keys
23
from .utils import shift, cmdtrl
34

@@ -33,7 +34,8 @@ def clear_outputs():
3334
# Execute cell with toolbar button
3435
notebook.edit_cell(index=0, content='a=13; print(a)')
3536
clear_outputs()
36-
notebook.browser.find_element_by_css_selector(
37+
notebook.browser.find_element(
38+
By.CSS_SELECTOR,
3739
"button[data-jupyter-action='jupyter-notebook:run-cell-and-select-next']").click()
3840
outputs = notebook.wait_for_cell_output(0)
3941
assert outputs[0].text == '13'

notebook/tests/selenium/test_interrupt.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
from selenium.webdriver.common.by import By
2+
13
from .utils import wait_for_selector
24

5+
36
def interrupt_from_menu(notebook):
47
# Click interrupt button in kernel menu
5-
notebook.browser.find_element_by_id('kernellink').click()
8+
notebook.browser.find_element(By.ID, 'kernellink').click()
69
wait_for_selector(notebook.browser, '#int_kernel', single=True).click()
710

811
def interrupt_from_keyboard(notebook):

notebook/tests/selenium/test_kernel_menu.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
def test_cancel_restart_or_shutdown(notebook):
1717
"""Click each of the restart options, then cancel the confirmation dialog"""
1818
browser = notebook.browser
19-
kernel_menu = browser.find_element_by_id('kernellink')
19+
kernel_menu = browser.find_element(By.ID, 'kernellink')
2020

2121
for menu_item in restart_selectors + [shutdown_selector]:
2222
kernel_menu.click()
@@ -30,7 +30,7 @@ def test_cancel_restart_or_shutdown(notebook):
3030

3131
def test_menu_items(notebook):
3232
browser = notebook.browser
33-
kernel_menu = browser.find_element_by_id('kernellink')
33+
kernel_menu = browser.find_element(By.ID, 'kernellink')
3434

3535
for menu_item in restart_selectors:
3636
# Shutdown

notebook/tests/selenium/test_markdown.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
from selenium.webdriver.common.by import By
2+
13
from nbformat.v4 import new_markdown_cell
24

5+
36
def get_rendered_contents(nb):
47
cl = ["text_cell", "render"]
5-
rendered_cells = [cell.find_element_by_class_name("text_cell_render")
8+
rendered_cells = [cell.find_element(By.CLASS_NAME, "text_cell_render")
69
for cell in nb.cells
710
if all([c in cell.get_attribute("class") for c in cl])]
811
return [x.get_attribute('innerHTML').strip()

notebook/tests/selenium/test_multiselect.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
from selenium.webdriver.common.by import By
2+
3+
14
INITIAL_CELLS = ['print("a")', 'print("b")', 'print("c")']
25

6+
37
def test_multiselect(prefill_notebook):
48
notebook = prefill_notebook(INITIAL_CELLS)
59

@@ -15,7 +19,8 @@ def n_selected_cells():
1519
assert n_selected_cells() == 1
1620

1721
# Check that only one cell is selected according to CSS classes as well
18-
selected_css = notebook.browser.find_elements_by_css_selector(
22+
selected_css = notebook.browser.find_elements(
23+
By.CSS_SELECTOR,
1924
'.cell.jupyter-soft-selected, .cell.selected')
2025
assert len(selected_css) == 1
2126

notebook/tests/selenium/test_notifications.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Test the notification area and widgets
33
"""
44
import pytest
5+
from selenium.webdriver.common.by import By
56

67
from .utils import wait_for_selector, wait_for_script_to_return_true
78

@@ -95,7 +96,7 @@ def test_notification(notebook):
9596

9697
assert widget_message(notebook, "test") == "test click", "callback: message is correct"
9798

98-
notebook.browser.find_element_by_id("notification_test").click()
99+
notebook.browser.find_element(By.ID, "notification_test").click()
99100
wait_for_script_to_return_true(notebook.browser,
100101
'return IPython.notification_area.widget("test")._clicked;')
101102
wait_for_selector(notebook.browser, "#notification_test", obscures=True)

0 commit comments

Comments
 (0)