Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
takluyver merged 6 commits intojupyter:masterfromarovit:add_find_replace_test
Jun 10, 2018
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
[WIP 838: Writing test for 'Find and replace' in selected cell apply …
…on all cells]
  • Loading branch information
arovitn committedMay 18, 2018
commit6fc09088ed268af7335efcdb48f8afd526ac3fbb
25 changes: 25 additions & 0 deletionsnotebook/tests/selenium/test_find_and_replace_apply_all.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
importos
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Let's call the filetest_find_and_replace.py - we'll probably later want to add tests that aren't doing apply all.

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)
22 changes: 21 additions & 1 deletionnotebook/tests/selenium/utils.py
View file
Open in desktop
Original file line numberDiff line numberDiff 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
Expand DownExpand Up@@ -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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Looks like thereplace_all parameter doesn't do anything. It's fine to drop it for now - it can always be added back when there's a test that wants to use it.

self.focus_cell(index)
esc(self.browser, 'F')
time.sleep(1) # TODO: find better way to fill the find and replace form
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Are there any specific elements on the form? We can wait for an element to appear.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Hmm, I don't want to comment now before trying again (I rem trying the wait logic while working on this, but couldn't get the wait working because I couldn't find any specific element, but let me retry)

self.browser.find_elements_by_css_selector("button.btn.btn-default.btn-sm")[2].click()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

What's this doing?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This code is basically for clicking double "upside down" arrow (third button) on the find and replace form to enable global replace. It's kinda hacky way of doing it, since the buttons don't have any specific ids on them which made it harder to fetch them directly. But let me will revisit this commit to see if we can make it more robust. Thanks !

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

We could add an ID, so long as that's not going to cause problems. If you do, try closing and reopening the dialog a few times so it's created several successive buttons with the same ID, and check that the button still works.

JS = "document.getElementsByClassName('form-control input-sm')[0].setAttribute('value', '%s')"%find_txt
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

We shouldn't need to construct JS just to set the value of a form field like this, I think.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

right, let me see how I can make it better.

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)
Expand DownExpand Up@@ -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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This isn't necessary -Esc isn't used as a modifier key that you have to hold down while pressing other keys. Just callself.to_command_mode() and then send the other keys as normal.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I see okay. Makes sense, will call self.to_command_mode()



[8]ページ先頭

©2009-2025 Movatter.jp