-
Notifications
You must be signed in to change notification settings - Fork 572
feat: Add viewmatcher #480
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
Merged
+112
−0
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
83dd5f9
Add android view matcher as strategy locator
ki4070ma c771a41
Add docstring
ki4070ma 79005fd
Add functional test
ki4070ma 654b806
Remove find_elements_by_android_data_matcher
ki4070ma 425039b
Fix docstring
ki4070ma 0063c06
tweak docstring
ki4070ma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
77 changes: 77 additions & 0 deletions
77
test/functional/android/search_context/find_by_view_matcher_tests.py
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#!/usr/bin/env python | ||
|
||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import os | ||
import unittest | ||
|
||
import pytest | ||
from selenium.common.exceptions import WebDriverException | ||
|
||
from appium import webdriver | ||
from appium.webdriver.common.mobileby import MobileBy | ||
from appium.webdriver.extensions.search_context.android import ( | ||
AndroidSearchContext | ||
) | ||
from test.functional.android.helper.test_helper import ( | ||
desired_capabilities, | ||
is_ci | ||
) | ||
|
||
|
||
class FindByViewMatcherTests(unittest.TestCase): | ||
|
||
def setUp(self): | ||
desired_caps = desired_capabilities.get_desired_capabilities('ApiDemos-debug.apk.zip') | ||
desired_caps['automationName'] = 'Espresso' | ||
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps) | ||
|
||
def tearDown(self): | ||
if is_ci(): | ||
# Take the screenshot to investigate when tests failed only on CI | ||
img_path = os.path.join(os.getcwd(), self._testMethodName + '.png') | ||
self.driver.get_screenshot_as_file(img_path) | ||
self.driver.quit() | ||
|
||
def test_find_single_element(self): | ||
el = self.driver.find_element_by_android_view_matcher( | ||
name='withText', args=['Accessibility'], className='ViewMatchers') | ||
assert el.text == 'Accessibility' | ||
|
||
def test_find_single_element_ful_class_name(self): | ||
el = self.driver.find_element_by_android_view_matcher( | ||
name='withText', args=['Accessibility'], className='androidx.test.espresso.matcher.ViewMatchers') | ||
assert el.text == 'Accessibility' | ||
|
||
def test_find_single_element_using_hamcrest_matcher(self): | ||
el = self.driver.find_element_by_android_view_matcher( | ||
name='withText', | ||
args={ | ||
'name': 'containsString', | ||
'args': 'Animati', | ||
'class': 'org.hamcrest.Matchers'}, | ||
className='ViewMatchers') | ||
assert el.text == 'Animation' | ||
|
||
# androidx.test.espresso.AmbiguousViewMatcherException: | ||
# 'with text: a string containing "Access"' matches multiple views in the hierarchy. | ||
def test_find_multiple_elements(self): | ||
value = AndroidSearchContext()._build_data_matcher( | ||
name='withSubstring', args=['Access'], className='ViewMatchers') | ||
with pytest.raises(WebDriverException): | ||
self.driver.find_elements(by=MobileBy.ANDROID_VIEW_MATCHER, value=value) | ||
|
||
|
||
if __name__ == '__main__': | ||
suite = unittest.TestLoader().loadTestsFromTestCase(FindByViewMatcherTests) | ||
unittest.TextTestRunner(verbosity=2).run(suite) |
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
[Notes] This is reason not to have
find_elements_by_android_view_matcher
.