- Notifications
You must be signed in to change notification settings - Fork5.5k
Add find replace test#3630
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
ce7a568c37bf0355be52b6fc090833c1deab22994eFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
…on all cells]
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| importos | ||
| ||
| importpytest | ||
| deftest_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 | ||
| assertnotebook.get_cell_contents(0)==cell_0.replace(find_str,replace_str) | ||
| assertnotebook.get_cell_contents(1)==cell_1.replace(find_str,replace_str) | ||
| assertnotebook.get_cell_contents(2)==cell_2.replace(find_str,replace_str) | ||
| assertnotebook.get_cell_contents(3)==cell_3.replace(find_str,replace_str) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 @@ def focus_cell(self, index=0): | ||
| 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() | ||
| ||