diff --git a/notebook/tests/selenium/test_find_and_replace_apply_all.py b/notebook/tests/selenium/test_find_and_replace_apply_all.py new file mode 100755 index 000000000..3365ece36 --- /dev/null +++ b/notebook/tests/selenium/test_find_and_replace_apply_all.py @@ -0,0 +1,25 @@ +import os +import pytest + + +def test_find_and_replace_apply_all(notebook): + """ test find and replace on all the cells """ + cell_0, cell_1, cell_2, cell_3 = "hello", "hellohello", "abc", "ello" + + find_str = "ello" # string to replace + replace_str = "foo" # string to replace to + + # set the contents of the cells + notebook.add_cell(index=0, content=cell_0); + notebook.add_cell(index=1, content=cell_1); + notebook.add_cell(index=2, content=cell_2); + notebook.add_cell(index=3, content=cell_3); + + # replace the strings + notebook.find_and_replace(index=0, find_txt=find_str, replace_txt=replace_str, replace_all=True) + + # check content of the cells + assert notebook.get_cell_contents(0) == cell_0.replace(find_str, replace_str) + assert notebook.get_cell_contents(1) == cell_1.replace(find_str, replace_str) + assert notebook.get_cell_contents(2) == cell_2.replace(find_str, replace_str) + assert notebook.get_cell_contents(3) == cell_3.replace(find_str, replace_str) diff --git a/notebook/tests/selenium/utils.py b/notebook/tests/selenium/utils.py index 3645354e0..a811e1885 100644 --- a/notebook/tests/selenium/utils.py +++ b/notebook/tests/selenium/utils.py @@ -1,5 +1,5 @@ import os - +import time from selenium.webdriver import ActionChains from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys @@ -100,6 +100,20 @@ class Notebook: self.to_command_mode() self.current_cell = cell + def find_and_replace(self, index=0, find_txt='', replace_txt='', replace_all=False): + self.focus_cell(index) + esc(self.browser, 'F') + time.sleep(1) # TODO: find better way to fill the find and replace form + self.browser.find_elements_by_css_selector("button.btn.btn-default.btn-sm")[2].click() + JS = "document.getElementsByClassName('form-control input-sm')[0].setAttribute('value', '%s')"%find_txt + self.browser.execute_script(JS) + JS = "document.getElementsByClassName('form-control input-sm')[1].setAttribute('value', '%s')"%replace_txt + self.browser.execute_script(JS) + self.body.send_keys(Keys.TAB) + self.body.send_keys(Keys.TAB) + self.body.send_keys(Keys.ENTER) + time.sleep(1) + def convert_cell_type(self, index=0, cell_type="code"): # TODO add check to see if it is already present self.focus_cell(index) @@ -258,3 +272,9 @@ def ctrl(browser, k): """Send key combination Ctrl+(k)""" ActionChains(browser)\ .key_down(Keys.CONTROL).send_keys(k).key_up(Keys.CONTROL).perform() + +def esc(browser, k): + """Send key combination esc+(k)""" + ActionChains(browser)\ + .key_down(Keys.ESCAPE).send_keys(k).key_up(Keys.ESCAPE).perform() +