Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add find replace test #3630

Merged
merged 6 commits into from Jun 10, 2018

Conversation

Projects
None yet
2 participants
@arovit
Copy link
Contributor

arovit commented May 21, 2018

Adding a selenium based test for finding and replacing in selected cell applied on all cells

def esc(browser, k):
"""Send key combination esc+(k)"""
ActionChains(browser)\
.key_down(Keys.ESCAPE).send_keys(k).key_up(Keys.ESCAPE).perform()

This comment has been minimized.

@takluyver

takluyver May 27, 2018

Member

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

This comment has been minimized.

@arovit

arovit May 31, 2018

Author Contributor

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

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

This comment has been minimized.

@takluyver

takluyver May 27, 2018

Member

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

This comment has been minimized.

@arovit

arovit May 31, 2018

Author Contributor

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)

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

This comment has been minimized.

@takluyver

takluyver May 27, 2018

Member

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

This comment has been minimized.

@arovit

arovit May 31, 2018

Author Contributor

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

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

This comment has been minimized.

@takluyver

takluyver May 27, 2018

Member

What's this doing?

This comment has been minimized.

@arovit

arovit May 31, 2018

Author Contributor

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 !

This comment has been minimized.

@takluyver

takluyver May 31, 2018

Member

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.

@arovit

This comment has been minimized.

Copy link
Contributor Author

arovit commented Jun 1, 2018

Thanks, added 'ids' in the find_and_replace form. Code looks much clearer now.

@@ -163,6 +163,7 @@ define([

var allCellsButton = $('<button/>')
.append($('<i/>').addClass('fa fa-arrows-v'))
.attr('id', 'allcells_id')

This comment has been minimized.

@takluyver

takluyver Jun 2, 2018

Member

IDs don't need to have a _id suffix, but they do need to be unique on the whole page - that includes IDs that might come from extensions or from output produced in a notebook. So let's make them a bit more specific, like findreplace_allcells_btn - and likewise for the other ones added here.

@@ -100,6 +100,16 @@ 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):

This comment has been minimized.

@takluyver

takluyver Jun 2, 2018

Member

Looks like the replace_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.

@@ -0,0 +1,25 @@
import os

This comment has been minimized.

@takluyver

takluyver Jun 2, 2018

Member

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

@takluyver

This comment has been minimized.

Copy link
Member

takluyver commented Jun 2, 2018

It is looking much clearer :-)

arovitn
renamed the ids, removed the replace_all parameter and changed the na…
…me of the testcase as mentioned in the comments
@arovit

This comment has been minimized.

Copy link
Contributor Author

arovit commented Jun 8, 2018

Thanks for reviewing, renamed the ids, removed the replace_all parameter and changed the name of testcase.

@takluyver takluyver added this to the 5.6 milestone Jun 10, 2018

@takluyver takluyver merged commit 702b67d into jupyter:master Jun 10, 2018

4 checks passed

codecov/patch 0% of diff hit (target 0%)
Details
codecov/project 74.25% (-0.21%) compared to 893505a
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@takluyver

This comment has been minimized.

Copy link
Member

takluyver commented Jun 10, 2018

Thanks!

@mpacer mpacer changed the title [WIP: 838] Add find replace test Add find replace test Jun 13, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.