From ce7a568ab7d9e0527a7035110956b2a4ea0add1e Mon Sep 17 00:00:00 2001 From: arovitn Date: Fri, 20 Apr 2018 18:46:43 -0700 Subject: [PATCH] [WIP] [3335] Converting prompt_numbers.js test to selenium --- .../tests/selenium/test_prompt_numbers.py | 28 +++++++++++++++++++ notebook/tests/selenium/utils.py | 4 +++ 2 files changed, 32 insertions(+) create mode 100755 notebook/tests/selenium/test_prompt_numbers.py diff --git a/notebook/tests/selenium/test_prompt_numbers.py b/notebook/tests/selenium/test_prompt_numbers.py new file mode 100755 index 000000000..57ff5bb18 --- /dev/null +++ b/notebook/tests/selenium/test_prompt_numbers.py @@ -0,0 +1,28 @@ +import os +import pytest +import time + +# selenium test version for 'prompt_numbers.js' + +def get_prompt(nb, index): + cell = nb.cells[0] + return cell.find_element_by_class_name('input').find_element_by_class_name('input_prompt').get_attribute('innerHTML').strip() + +def set_prompt(nb, index, value): + nb.set_cell_input_prompt(index, value) + +def test_prompt_numbers(notebook): + cell_index = 0 + a = 'print("a")' + notebook.edit_cell(index=cell_index, content=a) + assert get_prompt(notebook, cell_index) == "In [ ]:" + set_prompt(notebook, cell_index, 2); + assert get_prompt(notebook, cell_index) == "In [2]:" + set_prompt(notebook, cell_index, 0); + assert get_prompt(notebook, cell_index) == "In [0]:" + set_prompt(notebook, cell_index, "'*'"); + assert get_prompt(notebook, cell_index) == "In [*]:" + set_prompt(notebook, cell_index, "undefined"); + assert get_prompt(notebook, cell_index) == "In [ ]:" + set_prompt(notebook, cell_index, "null"); + assert get_prompt(notebook, cell_index) == "In [ ]:" diff --git a/notebook/tests/selenium/utils.py b/notebook/tests/selenium/utils.py index ef4092772..d17ac0e5e 100644 --- a/notebook/tests/selenium/utils.py +++ b/notebook/tests/selenium/utils.py @@ -135,6 +135,10 @@ class Notebook: JS = 'Jupyter.notebook.get_cell({}).metadata.{} = {}'.format(index, key, value) return self.browser.execute_script(JS) + def set_cell_input_prompt(self, index, prmpt_val): + JS = 'Jupyter.notebook.get_cell({}).set_input_prompt({})'.format(index, prmpt_val) + self.browser.execute_script(JS) + def edit_cell(self, cell=None, index=0, content="", render=False): """Set the contents of a cell to *content*, by cell object or by index """