add find by image commands and tests#224
Merged
add find by image commands and tests#224
Conversation
KazuCocoa
reviewed
Jun 12, 2018
| def test_find_based_on_image_template(self): | ||
| image_path = desired_capabilities.PATH('find_by_image_success.png') | ||
| el = WebDriverWait(self.driver, 3).until( | ||
| EC.presence_of_element_located((By.IMAGE, image_path)) |
appium/webdriver/webdriver.py
Outdated
| screenshot = self.get_screenshot_as_base64() | ||
| with open(png_img_path, 'rb') as png_file: | ||
| b64_data = base64.encodestring(png_file.read()) | ||
| b64_data = b64_data.replace("\n", "") |
Contributor
There was a problem hiding this comment.
why this is needed?
appium/webdriver/webdriver.py
Outdated
| except Exception as e: | ||
| if 'Cannot find any occurrences' in str(e): | ||
| raise NoSuchElementException(e) | ||
| else: |
Contributor
There was a problem hiding this comment.
else is redundant after raise
appium/webdriver/webdriver.py
Outdated
| b64_data = b64_data.replace("\n", "") | ||
| try: | ||
| res = self.find_image_occurrence(screenshot, b64_data) | ||
| except Exception as e: |
Contributor
There was a problem hiding this comment.
Perhaps, we only want to catch WebDriverException instances
appium/webdriver/webdriver.py
Outdated
| els = [] | ||
| try: | ||
| els.append(self.find_element_by_image(png_img_path)) | ||
| except Exception: |
appium/webdriver/webdriver.py
Outdated
| """ | ||
| return self.find_elements(by=By.ANDROID_UIAUTOMATOR, value=uia_string) | ||
|
|
||
| def find_element_by_image(self, png_img_path): |
Contributor
There was a problem hiding this comment.
I think it might be handy to pass the threshold to this method explicitly and set it to 0.5 by default, so clients can customise the behaviour if needed
KazuCocoa
reviewed
Jun 12, 2018
| Uses driver.find_image_occurrence under the hood. | ||
|
|
||
| :Args: | ||
| - png_img_path - a string corresponding to the path of a PNG image |
Member
There was a problem hiding this comment.
Should we address match_threshold?
| els.append(self.find_element_by_image(png_img_path, match_threshold)) | ||
| except NoSuchElementException: | ||
| pass | ||
| return els |
mykola-mokhnach
approved these changes
Jun 12, 2018
KazuCocoa
approved these changes
Jun 12, 2018
Member
Author
|
@imurchie mind publishing a new version when you get a chance? |
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
cc @imurchie @dpgraham @mykola-mokhnach @KazuCocoa .
This represents my vision for how clients should expose the template matching functionality with opencv. I.e., return a "clone" of WebElement with a smaller set of methods, so users can imagine they are simply finding "elements" and clicking on them.
Note that tests will only pass with appium/appium-support#74 applied to the Appium server used for testing.