-
Notifications
You must be signed in to change notification settings - Fork 572
add find by image commands and tests #224
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
Conversation
| 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)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah.. interesting.
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", "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
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): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
left a couple of comments
| Uses driver.find_image_occurrence under the hood. | ||
| :Args: | ||
| - png_img_path - a string corresponding to the path of a PNG image |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we address match_threshold?
| els.append(self.find_element_by_image(png_img_path, match_threshold)) | ||
| except NoSuchElementException: | ||
| pass | ||
| return els |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
|
@imurchie mind publishing a new version when you get a chance? |
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.