Skip to content

Commit 987526d

Browse files
authored
Add view tag (#124)
* add viewtag in finders for espresso driver * update changelog * rename key name from android_viewtag to viewtag to follow other definitions * add a line * tweak checking finder method * fix rubocop
1 parent 70130b3 commit 987526d

File tree

3 files changed

+32
-29
lines changed

3 files changed

+32
-29
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file.
33

44
## [Unreleased]
55
### Enhancements
6+
- Add `:viewtag` for Espresso driver [appium-espresso-driver#189](https://github.com/appium/appium-espresso-driver/pull/189)
67

78
### Bug fixes
89

lib/appium_lib_core/common/base/search_context.rb

+12-8
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,19 @@ module SearchContext
55
# referenced: ::Selenium::WebDriver::SearchContext
66

77
FINDERS = ::Selenium::WebDriver::SearchContext::FINDERS.merge(
8-
accessibility_id: 'accessibility id',
9-
image: '-image',
8+
accessibility_id: 'accessibility id',
9+
image: '-image',
1010
# Android
11-
uiautomator: '-android uiautomator',
11+
uiautomator: '-android uiautomator', # Unavailable in Espresso
12+
viewtag: '-android viewtag', # Available in Espresso
1213
# iOS
13-
uiautomation: '-ios uiautomation',
14-
predicate: '-ios predicate string',
15-
class_chain: '-ios class chain',
14+
uiautomation: '-ios uiautomation',
15+
predicate: '-ios predicate string',
16+
class_chain: '-ios class chain',
1617
# Windows
1718
windows_uiautomation: '-windows uiautomation',
1819
# Tizen
19-
tizen_uiautomation: '-tizen uiautomation'
20+
tizen_uiautomation: '-tizen uiautomation'
2021
)
2122

2223
#
@@ -54,6 +55,9 @@ module SearchContext
5455
# # For Android
5556
# ## With uiautomator
5657
# find_elements :uiautomator, 'new UiSelector().clickable(true)'
58+
# ## With viewtag, but only for Espresso
59+
# ## `setTag`/`getTag` in https://developer.android.com/reference/android/view/View
60+
# find_elements :viewtag, 'new UiSelector().clickable(true)'
5761
#
5862
# # For iOS
5963
# ## With :predicate
@@ -113,7 +117,7 @@ def find_elements(*args)
113117

114118
def _set_by_from_finders(how)
115119
by = FINDERS[how.to_sym]
116-
raise ArgumentError, "cannot find element by #{how.inspect}" unless by
120+
raise ArgumentError, "cannot find element by #{how.inspect}. Available finders are #{FINDERS.keys}." unless by
117121
by
118122
end
119123

test/unit/driver_test.rb

+19-21
Original file line numberDiff line numberDiff line change
@@ -82,27 +82,25 @@ def test_default_timeout_for_http_client
8282
end
8383

8484
def test_search_context_in_element_class
85-
assert_equal 'class name', ::Selenium::WebDriver::Element::FINDERS[:class]
86-
assert_equal 'class name', ::Selenium::WebDriver::Element::FINDERS[:class_name]
87-
assert_equal 'css selector', ::Selenium::WebDriver::Element::FINDERS[:css]
88-
assert_equal 'id', ::Selenium::WebDriver::Element::FINDERS[:id]
89-
assert_equal 'link text', ::Selenium::WebDriver::Element::FINDERS[:link]
90-
assert_equal 'link text', ::Selenium::WebDriver::Element::FINDERS[:link_text]
91-
assert_equal 'name', ::Selenium::WebDriver::Element::FINDERS[:name]
92-
assert_equal 'partial link text', ::Selenium::WebDriver::Element::FINDERS[:partial_link_text]
93-
assert_equal 'tag name', ::Selenium::WebDriver::Element::FINDERS[:tag_name]
94-
assert_equal 'xpath', ::Selenium::WebDriver::Element::FINDERS[:xpath]
95-
assert_equal 'accessibility id', ::Selenium::WebDriver::Element::FINDERS[:accessibility_id]
96-
assert_equal '-android uiautomator', ::Selenium::WebDriver::Element::FINDERS[:uiautomator]
97-
assert_equal '-ios uiautomation', ::Selenium::WebDriver::Element::FINDERS[:uiautomation]
98-
assert_equal '-ios predicate string', ::Selenium::WebDriver::Element::FINDERS[:predicate]
99-
assert_equal '-ios class chain', ::Selenium::WebDriver::Element::FINDERS[:class_chain]
100-
assert_equal '-ios uiautomation', ::Selenium::WebDriver::Element::FINDERS[:uiautomation]
101-
assert_equal '-ios predicate string', ::Selenium::WebDriver::Element::FINDERS[:predicate]
102-
assert_equal '-ios class chain', ::Selenium::WebDriver::Element::FINDERS[:class_chain]
103-
assert_equal '-windows uiautomation', ::Selenium::WebDriver::Element::FINDERS[:windows_uiautomation]
104-
assert_equal '-tizen uiautomation', ::Selenium::WebDriver::Element::FINDERS[:tizen_uiautomation]
105-
assert_equal '-image', ::Selenium::WebDriver::Element::FINDERS[:image]
85+
assert_equal 19, ::Selenium::WebDriver::Element::FINDERS.length
86+
assert_equal({ class: 'class name',
87+
class_name: 'class name',
88+
css: 'css selector',
89+
id: 'id',
90+
link: 'link text',
91+
link_text: 'link text',
92+
name: 'name',
93+
partial_link_text: 'partial link text',
94+
tag_name: 'tag name',
95+
xpath: 'xpath',
96+
accessibility_id: 'accessibility id',
97+
image: '-image',
98+
uiautomator: '-android uiautomator',
99+
viewtag: '-android viewtag', uiautomation: '-ios uiautomation',
100+
predicate: '-ios predicate string',
101+
class_chain: '-ios class chain',
102+
windows_uiautomation: '-windows uiautomation',
103+
tizen_uiautomation: '-tizen uiautomation' }, ::Selenium::WebDriver::Element::FINDERS)
106104
end
107105
end
108106
end

0 commit comments

Comments
 (0)