Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file.

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

### Bug fixes

Expand Down
20 changes: 12 additions & 8 deletions lib/appium_lib_core/common/base/search_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@ module SearchContext
# referenced: ::Selenium::WebDriver::SearchContext

FINDERS = ::Selenium::WebDriver::SearchContext::FINDERS.merge(
accessibility_id: 'accessibility id',
image: '-image',
accessibility_id: 'accessibility id',
image: '-image',
# Android
uiautomator: '-android uiautomator',
uiautomator: '-android uiautomator', # Unavailable in Espresso
viewtag: '-android viewtag', # Available in Espresso
# iOS
uiautomation: '-ios uiautomation',
predicate: '-ios predicate string',
class_chain: '-ios class chain',
uiautomation: '-ios uiautomation',
predicate: '-ios predicate string',
class_chain: '-ios class chain',
# Windows
windows_uiautomation: '-windows uiautomation',
# Tizen
tizen_uiautomation: '-tizen uiautomation'
tizen_uiautomation: '-tizen uiautomation'
)

#
Expand Down Expand Up @@ -54,6 +55,9 @@ module SearchContext
# # For Android
# ## With uiautomator
# find_elements :uiautomator, 'new UiSelector().clickable(true)'
# ## With viewtag, but only for Espresso
# ## `setTag`/`getTag` in https://developer.android.com/reference/android/view/View
# find_elements :viewtag, 'new UiSelector().clickable(true)'
#
# # For iOS
# ## With :predicate
Expand Down Expand Up @@ -113,7 +117,7 @@ def find_elements(*args)

def _set_by_from_finders(how)
by = FINDERS[how.to_sym]
raise ArgumentError, "cannot find element by #{how.inspect}" unless by
raise ArgumentError, "cannot find element by #{how.inspect}. Available finders are #{FINDERS.keys}." unless by
by
end

Expand Down
40 changes: 19 additions & 21 deletions test/unit/driver_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,27 +82,25 @@ def test_default_timeout_for_http_client
end

def test_search_context_in_element_class
assert_equal 'class name', ::Selenium::WebDriver::Element::FINDERS[:class]
assert_equal 'class name', ::Selenium::WebDriver::Element::FINDERS[:class_name]
assert_equal 'css selector', ::Selenium::WebDriver::Element::FINDERS[:css]
assert_equal 'id', ::Selenium::WebDriver::Element::FINDERS[:id]
assert_equal 'link text', ::Selenium::WebDriver::Element::FINDERS[:link]
assert_equal 'link text', ::Selenium::WebDriver::Element::FINDERS[:link_text]
assert_equal 'name', ::Selenium::WebDriver::Element::FINDERS[:name]
assert_equal 'partial link text', ::Selenium::WebDriver::Element::FINDERS[:partial_link_text]
assert_equal 'tag name', ::Selenium::WebDriver::Element::FINDERS[:tag_name]
assert_equal 'xpath', ::Selenium::WebDriver::Element::FINDERS[:xpath]
assert_equal 'accessibility id', ::Selenium::WebDriver::Element::FINDERS[:accessibility_id]
assert_equal '-android uiautomator', ::Selenium::WebDriver::Element::FINDERS[:uiautomator]
assert_equal '-ios uiautomation', ::Selenium::WebDriver::Element::FINDERS[:uiautomation]
assert_equal '-ios predicate string', ::Selenium::WebDriver::Element::FINDERS[:predicate]
assert_equal '-ios class chain', ::Selenium::WebDriver::Element::FINDERS[:class_chain]
assert_equal '-ios uiautomation', ::Selenium::WebDriver::Element::FINDERS[:uiautomation]
assert_equal '-ios predicate string', ::Selenium::WebDriver::Element::FINDERS[:predicate]
assert_equal '-ios class chain', ::Selenium::WebDriver::Element::FINDERS[:class_chain]
assert_equal '-windows uiautomation', ::Selenium::WebDriver::Element::FINDERS[:windows_uiautomation]
assert_equal '-tizen uiautomation', ::Selenium::WebDriver::Element::FINDERS[:tizen_uiautomation]
assert_equal '-image', ::Selenium::WebDriver::Element::FINDERS[:image]
assert_equal 19, ::Selenium::WebDriver::Element::FINDERS.length
assert_equal({ class: 'class name',
class_name: 'class name',
css: 'css selector',
id: 'id',
link: 'link text',
link_text: 'link text',
name: 'name',
partial_link_text: 'partial link text',
tag_name: 'tag name',
xpath: 'xpath',
accessibility_id: 'accessibility id',
image: '-image',
uiautomator: '-android uiautomator',
viewtag: '-android viewtag', uiautomation: '-ios uiautomation',
predicate: '-ios predicate string',
class_chain: '-ios class chain',
windows_uiautomation: '-windows uiautomation',
tizen_uiautomation: '-tizen uiautomation' }, ::Selenium::WebDriver::Element::FINDERS)
end
end
end