Skip to content

Commit c188829

Browse files
authored
gather search contexts (#118)
1 parent 2cbb18f commit c188829

File tree

19 files changed

+62
-125
lines changed

19 files changed

+62
-125
lines changed

lib/appium_lib_core/android.rb

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
# loaded in common/driver.rb
2-
require_relative 'android/search_context'
32
require_relative 'android/device'
43
require_relative 'android/uiautomator1/bridge'

lib/appium_lib_core/android/espresso/bridge.rb

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ module Espresso
55
module Bridge
66
def self.for(target)
77
target.extend Appium::Core::Android::Device
8-
Core::Android::SearchContext.extend
98
end
109
end
1110
end

lib/appium_lib_core/android/search_context.rb

-18
This file was deleted.

lib/appium_lib_core/android/uiautomator1/bridge.rb

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ module Uiautomator1
55
module Bridge
66
def self.for(target)
77
target.extend Appium::Core::Android::Device
8-
Core::Android::SearchContext.extend
98
end
109
end
1110
end

lib/appium_lib_core/android/uiautomator2/bridge.rb

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ module Uiautomator2
55
module Bridge
66
def self.for(target)
77
target.extend Appium::Core::Android::Device
8-
Core::Android::SearchContext.extend
98
target.extend Appium::Core::Android::Uiautomator2::Device
109
end
1110
end
-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
# loaded in common/driver.rb
2-
require_relative 'android/search_context'
32
require_relative 'android/device'
43
require_relative 'android/espresso/bridge'

lib/appium_lib_core/android_uiautomator2.rb

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# loaded in common/driver.rb
2-
require_relative 'android/search_context'
32
require_relative 'android/device'
43

54
require_relative 'android/uiautomator2/bridge'

lib/appium_lib_core/common/base/search_context.rb

+53-8
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,73 @@ class Base
44
module SearchContext
55
# referenced: ::Selenium::WebDriver::SearchContext
66

7-
FINDERS = ::Selenium::WebDriver::SearchContext::FINDERS.merge(accessibility_id: 'accessibility id')
8-
9-
def self.add_finders(finders)
10-
FINDERS.merge!(finders)
11-
end
7+
FINDERS = ::Selenium::WebDriver::SearchContext::FINDERS.merge(
8+
accessibility_id: 'accessibility id',
9+
# Android
10+
uiautomator: '-android uiautomator',
11+
# iOS
12+
uiautomation: '-ios uiautomation',
13+
predicate: '-ios predicate string',
14+
class_chain: '-ios class chain',
15+
# Windows
16+
windows_uiautomation: '-windows uiautomation',
17+
# Tizen
18+
tizen_uiautomation: '-tizen uiautomation'
19+
)
1220

1321
#
1422
# Find the first element matching the given arguments
1523
#
24+
# Android can find with uiautomator like a [UISelector](http://developer.android.com/tools/help/uiautomator/UiSelector.html).
25+
# iOS can find with a [UIAutomation command](https://developer.apple.com/library/ios/documentation/ToolsLanguages/Reference/UIAWindowClassReference/UIAWindow/UIAWindow.html#//apple_ref/doc/uid/TP40009930).
26+
# iOS, only for XCUITest(WebDriverAgent), can find with a [class chain]( https://github.com/facebook/WebDriverAgent/wiki/Queries)
27+
#
1628
# @overload find_element(how, what)
1729
# @param [Symbol, String] how The method to find the element by
1830
# @param [String] what The locator to use
31+
#
1932
# @overload find_element(opts)
2033
# @param [Hash] opts Find options
2134
# @option opts [Symbol] :how Key named after the method to find the element by, containing the locator
2235
# @return [Element]
23-
#
2436
# @raise [Error::NoSuchElementError] if the element doesn't exist
2537
#
2638
# @example Find element with accessibility id
27-
# find_elements :accessibility_id, 'Animation'
28-
# find_elements :accessibility_id, 'Animation'
39+
# find_elements :accessibility_id, 'Animation'
40+
# find_elements :accessibility_id, 'Animation'
41+
#
42+
# # For Android
43+
# ## With uiautomator
44+
# find_elements :uiautomator, 'new UiSelector().clickable(true)'
45+
#
46+
# # For iOS
47+
# ## With :predicate
48+
# find_elements :predicate, "isWDVisible == 1"
49+
# find_elements :predicate, 'wdName == "Buttons"'
50+
# find_elements :predicate, 'wdValue == "SearchBar" AND isWDDivisible == 1'
51+
#
52+
# ## With Class Chain
53+
# ### select the third child button of the first child window element
54+
# find_elements :class_chain, 'XCUIElementTypeWindow/XCUIElementTypeButton[3]'
55+
# ### select all the children windows
56+
# find_elements :class_chain, 'XCUIElementTypeWindow'
57+
# ### select the second last child of the second child window
58+
# find_elements :class_chain, 'XCUIElementTypeWindow[2]/XCUIElementTypeAny[-2]'
59+
# ### matching predicate. <code>`</code> is the mark.
60+
# find_elements :class_chain, 'XCUIElementTypeWindow[`visible = 1][`name = "bla"`]'
61+
# ### containing predicate. `$` is the mark.
62+
# ### Require appium-xcuitest-driver 2.54.0+. PR: https://github.com/facebook/WebDriverAgent/pull/707/files
63+
# find_elements :class_chain, 'XCUIElementTypeWindow[$name = \"bla$$$bla\"$]'
64+
# e = find_element :class_chain, "**/XCUIElementTypeWindow[$name == 'Buttons'$]"
65+
# e.tag_name #=> "XCUIElementTypeWindow"
66+
# e = find_element :class_chain, "**/XCUIElementTypeStaticText[$name == 'Buttons'$]"
67+
# e.tag_name #=> "XCUIElementTypeStaticText"
68+
#
69+
# # For Windows
70+
# find_elements :windows_uiautomation, '....'
71+
#
72+
# # For Tizen
73+
# find_elements :tizen_uiautomation, '....'
2974
#
3075
def find_element(*args)
3176
how, what = extract_args(args)

lib/appium_lib_core/ios.rb

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# loaded in common/driver.rb
2-
require_relative 'ios/search_context'
32
require_relative 'ios/device'
43

54
require_relative 'ios/uiautomation/patch'

lib/appium_lib_core/ios/search_context.rb

-27
This file was deleted.

lib/appium_lib_core/ios/uiautomation/bridge.rb

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ module Ios
44
module Uiautomation
55
module Bridge
66
def self.for(target)
7-
Core::Ios::SearchContext.extend
87
target.extend Appium::Core::Ios::Device
98

109
Core::Ios::Uiautomation.patch_webdriver_element

lib/appium_lib_core/ios/xcuitest/bridge.rb

-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ module Ios
44
module Xcuitest
55
module Bridge
66
def self.for(target)
7-
Core::Ios::SearchContext.extend
8-
Core::Ios::Xcuitest::SearchContext.extend
97
target.extend Appium::Core::Ios::Device
108
target.extend Appium::Core::Ios::Xcuitest::Device
119
end

lib/appium_lib_core/ios/xcuitest/search_context.rb

-40
This file was deleted.

lib/appium_lib_core/ios_xcuitest.rb

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# loaded in common/driver.rb
2-
require_relative 'ios/search_context'
32
require_relative 'ios/device'
43

5-
require_relative 'ios/xcuitest/search_context'
64
require_relative 'ios/xcuitest/device'
75
require_relative 'ios/xcuitest/bridge'

test/unit/android/device/mjsonwp/definition_test.rb

-4
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,6 @@ def test_with_arg_definitions
8080
:get_clipboard,
8181
:set_clipboard])
8282
end
83-
84-
def test_search_context_in_element_class_for_android
85-
assert_equal '-android uiautomator', ::Selenium::WebDriver::Element::FINDERS[:uiautomator]
86-
end
8783
end
8884
end # module MJSONWP
8985
end # module Device

test/unit/android/device/w3c/definition_test.rb

-4
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,6 @@ def test_with_arg_definitions
7979
:get_clipboard,
8080
:set_clipboard])
8181
end
82-
83-
def test_search_context_in_element_class_for_android
84-
assert_equal '-android uiautomator', ::Selenium::WebDriver::Element::FINDERS[:uiautomator]
85-
end
8682
end # class DefinitionTest
8783
end # module W3C
8884
end # module Device

test/unit/driver_test.rb

+9
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@ def test_search_context_in_element_class
9393
assert_equal 'tag name', ::Selenium::WebDriver::Element::FINDERS[:tag_name]
9494
assert_equal 'xpath', ::Selenium::WebDriver::Element::FINDERS[:xpath]
9595
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]
96105
end
97106
end
98107
end

test/unit/ios/device/mjsonwp/definition_test.rb

-6
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,6 @@ def test_with_arg_definitions
6767
:touch_id,
6868
:toggle_touch_id_enrollment])
6969
end
70-
71-
def test_search_context_in_element_class_ios
72-
assert_equal '-ios uiautomation', ::Selenium::WebDriver::Element::FINDERS[:uiautomation]
73-
assert_equal '-ios predicate string', ::Selenium::WebDriver::Element::FINDERS[:predicate]
74-
assert_equal '-ios class chain', ::Selenium::WebDriver::Element::FINDERS[:class_chain]
75-
end
7670
end # class DefinitionTest
7771
end # module MJSONWP
7872
end # module Device

test/unit/ios/device/w3c/definition_test.rb

-6
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,6 @@ def test_with_arg_definitions
7070
:touch_id,
7171
:toggle_touch_id_enrollment])
7272
end
73-
74-
def test_search_context_in_element_class_ios
75-
assert_equal '-ios uiautomation', ::Selenium::WebDriver::Element::FINDERS[:uiautomation]
76-
assert_equal '-ios predicate string', ::Selenium::WebDriver::Element::FINDERS[:predicate]
77-
assert_equal '-ios class chain', ::Selenium::WebDriver::Element::FINDERS[:class_chain]
78-
end
7973
end # class DefinitionTest
8074
end # module W3C
8175
end # module Device

0 commit comments

Comments
 (0)