[WIP 838: Writing test for 'Find and replace' in selected cell apply on all cells]

arovitn 8 years ago
parent 55be52b8a3
commit 6fc09088ed

@ -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)

@ -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()

Loading…
Cancel
Save