appium_lib 0.0.30 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/Rakefile +15 -7
- data/appium_lib.gemspec +3 -3
- data/docs.md +7 -5
- data/lib/appium_lib.rb +34 -6
- data/lib/appium_lib/android/element/alert.rb +43 -0
- data/lib/appium_lib/android/element/generic.rb +94 -0
- data/lib/appium_lib/android/element/textfield.rb +43 -0
- data/lib/appium_lib/android/helper.rb +120 -0
- data/lib/appium_lib/android/patch.rb +10 -0
- data/lib/appium_lib/common/element/button.rb +83 -0
- data/lib/appium_lib/common/element/text.rb +44 -0
- data/lib/appium_lib/common/element/window.rb +9 -0
- data/lib/appium_lib/common/helper.rb +140 -0
- data/lib/appium_lib/common/patch.rb +83 -0
- data/lib/appium_lib/common/version.rb +6 -0
- data/lib/appium_lib/driver.rb +265 -0
- data/lib/appium_lib/ios/element/alert.rb +56 -0
- data/lib/appium_lib/ios/element/generic.rb +170 -0
- data/lib/appium_lib/ios/element/textfield.rb +90 -0
- data/lib/appium_lib/ios/helper.rb +103 -0
- data/lib/appium_lib/ios/patch.rb +15 -0
- data/readme.md +10 -3
- data/release_notes.md +8 -0
- metadata +19 -15
- data/lib/appium_lib/console.rb +0 -254
- data/lib/appium_lib/element/android/alert.rb +0 -45
- data/lib/appium_lib/element/android/generic.rb +0 -88
- data/lib/appium_lib/element/android/textfield.rb +0 -44
- data/lib/appium_lib/element/button.rb +0 -83
- data/lib/appium_lib/element/ios/alert.rb +0 -49
- data/lib/appium_lib/element/ios/generic.rb +0 -140
- data/lib/appium_lib/element/ios/textfield.rb +0 -93
- data/lib/appium_lib/element/text.rb +0 -43
- data/lib/appium_lib/element/window.rb +0 -12
- data/lib/appium_lib/helper.rb +0 -278
- data/lib/appium_lib/patch.rb +0 -90
- data/lib/appium_lib/version.rb +0 -4
@@ -1,44 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
if $os == :android
|
3
|
-
# UIATextField methods
|
4
|
-
|
5
|
-
# Get an array of textfield texts.
|
6
|
-
# @return [Array<String>]
|
7
|
-
def textfields
|
8
|
-
find_eles_attr :textfield, :text
|
9
|
-
end
|
10
|
-
|
11
|
-
# Get an array of textfield elements.
|
12
|
-
# @return [Array<Textfield>]
|
13
|
-
def e_textfields
|
14
|
-
find_eles :textfield
|
15
|
-
end
|
16
|
-
|
17
|
-
# Get the first textfield element.
|
18
|
-
# @return [Textfield]
|
19
|
-
def first_textfield
|
20
|
-
first_ele :textfield
|
21
|
-
end
|
22
|
-
|
23
|
-
# Get the last textfield element.
|
24
|
-
# @return [Textfield]
|
25
|
-
def last_textfield
|
26
|
-
last_ele :textfield
|
27
|
-
end
|
28
|
-
|
29
|
-
# Get the first textfield that matches text.
|
30
|
-
# @param text [String, Integer] the text to match exactly. If int then the textfield at that index is returned.
|
31
|
-
# @return [Textfield]
|
32
|
-
def textfield text
|
33
|
-
return ele_index :textfield, text if text.is_a? Numeric
|
34
|
-
find_ele_by_text :textfield, text
|
35
|
-
end
|
36
|
-
|
37
|
-
# Get the first textfield that includes text.
|
38
|
-
# @param text [String] the text the textfield must include
|
39
|
-
# @return [Textfield]
|
40
|
-
def textfield_include text
|
41
|
-
find_ele_by_text_include :textfield, text
|
42
|
-
end
|
43
|
-
|
44
|
-
end # if $os == :android
|
@@ -1,83 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
# UIAButton methods
|
3
|
-
|
4
|
-
# Find a button by text and optionally number.
|
5
|
-
# @param text [String, Integer] the text to exactly match. If int then the button at that index is returned.
|
6
|
-
# @param number [Integer] the occurance of the button matching text. Defaults to the first button.
|
7
|
-
# @return [Button] the button found with text and matching number
|
8
|
-
def button text, number=0
|
9
|
-
# return button at index.
|
10
|
-
return ele_index :button, text if text.is_a? Numeric
|
11
|
-
|
12
|
-
number >= 1 ? button_num( text, number ) :
|
13
|
-
find_ele_by_text_include( :button, text )
|
14
|
-
end
|
15
|
-
|
16
|
-
# Get an array of button texts or button elements if text is provided.
|
17
|
-
# @param text [String] the text to exactly match
|
18
|
-
# @return [Array<String>, Array<Buttons>] either an array of button texts or an array of button elements if text is provided.
|
19
|
-
def buttons text=nil
|
20
|
-
text == nil ? find_eles_attr( :button, :text ) :
|
21
|
-
find_eles_by_text_include( :button, text )
|
22
|
-
end
|
23
|
-
|
24
|
-
# Get the first button element.
|
25
|
-
# @return [Button]
|
26
|
-
def first_button
|
27
|
-
first_ele :button
|
28
|
-
end
|
29
|
-
|
30
|
-
# Get the last button element.
|
31
|
-
# @return [Button]
|
32
|
-
def last_button
|
33
|
-
last_ele :button
|
34
|
-
end
|
35
|
-
|
36
|
-
# Get the first button element that exactly matches text.
|
37
|
-
# @param text [String] the text to match exactly
|
38
|
-
# @return [Button]
|
39
|
-
def button_exact text
|
40
|
-
find_ele_by_text :button, text
|
41
|
-
end
|
42
|
-
|
43
|
-
# Get all button elements that exactly match text.
|
44
|
-
# @param text [String] the text to match exactly
|
45
|
-
# @return [Array<Button>]
|
46
|
-
def buttons_exact text
|
47
|
-
find_eles_by_text :button, text
|
48
|
-
end
|
49
|
-
|
50
|
-
# Get an array of button elements.
|
51
|
-
# @return [Array<Button>]
|
52
|
-
def e_buttons
|
53
|
-
find_eles :button
|
54
|
-
end
|
55
|
-
|
56
|
-
# Expected to be called via button method.
|
57
|
-
#
|
58
|
-
# Get the button element exactly matching text and
|
59
|
-
# occurrence. number=2 means the 2nd occurrence.
|
60
|
-
#
|
61
|
-
# find the second Sign In button
|
62
|
-
#
|
63
|
-
# b = e_button 'Sign In', 2
|
64
|
-
#
|
65
|
-
# Button order will change in iOS vs Android
|
66
|
-
# so if there's no button found at number then
|
67
|
-
# return the first button.
|
68
|
-
#
|
69
|
-
# @param text [String] the text to match
|
70
|
-
# @param number [Integer] the button occurance to return. 1 = first button
|
71
|
-
# @return [Button] the button that matches text and number
|
72
|
-
def button_num text, number=1
|
73
|
-
raise "Number must be >= 1" if number <= 0
|
74
|
-
number = number - 1 # zero indexed
|
75
|
-
|
76
|
-
result = nil
|
77
|
-
|
78
|
-
elements = buttons text
|
79
|
-
elements.size > number ? result = elements[number]
|
80
|
-
: result = elements.first
|
81
|
-
|
82
|
-
result
|
83
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
if $os == :ios
|
3
|
-
# iOS only
|
4
|
-
# Tap the alert button identified by value.
|
5
|
-
# @param value [Integer, String] either an integer index of the button or the button's name
|
6
|
-
# @return [void]
|
7
|
-
def alert_click value
|
8
|
-
$driver.execute_script "UIATarget.localTarget().frontMostApp().alert().buttons()[#{value}].tap();"
|
9
|
-
end
|
10
|
-
|
11
|
-
# Get the alert message text.
|
12
|
-
# @return [String]
|
13
|
-
def alert_text
|
14
|
-
$driver.switch_to.alert.text
|
15
|
-
end
|
16
|
-
|
17
|
-
# Accept the alert.
|
18
|
-
# @return [void]
|
19
|
-
def alert_accept
|
20
|
-
$driver.switch_to.alert.accept
|
21
|
-
end
|
22
|
-
|
23
|
-
# Get the text of the alert's accept button.
|
24
|
-
# The last button is considered "accept."
|
25
|
-
# @return [String]
|
26
|
-
def alert_accept_text
|
27
|
-
a = $driver.find_element(:tag_name, :alert)
|
28
|
-
return if a.nil?
|
29
|
-
b = a.find_elements(:tag_name, :button)
|
30
|
-
b.last.text if b && b.size >= 1
|
31
|
-
end
|
32
|
-
|
33
|
-
# Dismiss the alert.
|
34
|
-
# @return [void]
|
35
|
-
def alert_dismiss
|
36
|
-
$driver.switch_to.alert.dismiss
|
37
|
-
end
|
38
|
-
|
39
|
-
# Get the text of the alert's dismiss button.
|
40
|
-
# The first button is considered "dismiss."
|
41
|
-
# @return [String]
|
42
|
-
def alert_dismiss_text
|
43
|
-
a = $driver.find_element(:tag_name, :alert)
|
44
|
-
return if a.nil?
|
45
|
-
b = a.find_elements(:tag_name, :button)
|
46
|
-
b.first.text if b && b.size >= 1
|
47
|
-
end
|
48
|
-
|
49
|
-
end # if $os == :ios
|
@@ -1,140 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
if $os == :ios
|
3
|
-
=begin
|
4
|
-
name, names, text, text should match substring and case insensitive.
|
5
|
-
|
6
|
-
iOS .name() is the accessibility attribute. If not defined, then .label() is used instead.
|
7
|
-
This differs from Android where name (the content description) is empty when not set.
|
8
|
-
|
9
|
-
name defaults to label when undefined. value is never a default so that must be
|
10
|
-
included in a new search.
|
11
|
-
|
12
|
-
Find - search everything.
|
13
|
-
|
14
|
-
The search order is:
|
15
|
-
1. name
|
16
|
-
2. label (implied by name)
|
17
|
-
3. value
|
18
|
-
|
19
|
-
Android name = iOS name & label
|
20
|
-
Android text = iOS value
|
21
|
-
=end
|
22
|
-
|
23
|
-
def first_ele_js predicate
|
24
|
-
# returnElems requires a wrapped $(element).
|
25
|
-
# set to empty array when length is zero to prevent hang.
|
26
|
-
#
|
27
|
-
# UIAElementNil when not matched
|
28
|
-
#
|
29
|
-
# 1. secureTextFields
|
30
|
-
# 2. textFields
|
31
|
-
# 3. buttons
|
32
|
-
# 4. elements
|
33
|
-
%Q(
|
34
|
-
function isNil( a ) {
|
35
|
-
return a.type() === 'UIAElementNil';
|
36
|
-
}
|
37
|
-
|
38
|
-
var w = au.mainWindow;
|
39
|
-
var search = "#{predicate}";
|
40
|
-
var a = w.secureTextFields().firstWithPredicate(search);
|
41
|
-
if ( isNil(a) ) {
|
42
|
-
a = w.textFields().firstWithPredicate(search);
|
43
|
-
if ( isNil(a) ) {
|
44
|
-
a = w.buttons().firstWithPredicate(search);
|
45
|
-
if ( isNil(a) ) {
|
46
|
-
a = w.elements().firstWithPredicate(search);
|
47
|
-
}
|
48
|
-
}
|
49
|
-
}
|
50
|
-
|
51
|
-
if ( a.length === 0 ) {
|
52
|
-
a = [];
|
53
|
-
}
|
54
|
-
|
55
|
-
au._returnElems($(a));
|
56
|
-
)
|
57
|
-
end
|
58
|
-
|
59
|
-
def all_ele_js predicate
|
60
|
-
%Q(
|
61
|
-
var w = au.mainWindow;
|
62
|
-
var search = "#{predicate}";
|
63
|
-
var a = w.elements().withPredicate(search).toArray();
|
64
|
-
|
65
|
-
if ( a.length === 0 ) {
|
66
|
-
a = [];
|
67
|
-
}
|
68
|
-
|
69
|
-
au._returnElems($(a));
|
70
|
-
)
|
71
|
-
end
|
72
|
-
|
73
|
-
# Return the first element matching text.
|
74
|
-
# @param text [String] the text to search for
|
75
|
-
# @return [Element] the first matching element
|
76
|
-
def find text
|
77
|
-
js = first_ele_js "name contains[c] '#{text}' || label contains[c] '#{text}' || value contains[c] '#{text}'"
|
78
|
-
|
79
|
-
execute_script(js).first
|
80
|
-
end
|
81
|
-
|
82
|
-
# Return all elements matching text.
|
83
|
-
# @param text [String] the text to search for
|
84
|
-
# @return [Array<Element>] all matching elements
|
85
|
-
def finds text
|
86
|
-
# returnElems requires a wrapped $(element).
|
87
|
-
# must call toArray when using withPredicate instead of firstWithPredicate.
|
88
|
-
js = all_ele_js "name contains[c] '#{text}' || label contains[c] '#{text}' || value contains[c] '#{text}'"
|
89
|
-
|
90
|
-
execute_script js
|
91
|
-
end
|
92
|
-
|
93
|
-
# Return the first element matching text.
|
94
|
-
# @param text [String] the text to search for
|
95
|
-
# @return [Element] the first matching element
|
96
|
-
def text text
|
97
|
-
# TODO: Use XPath index once it's implemented
|
98
|
-
# https://github.com/appium/appium/issues/295
|
99
|
-
js = first_ele_js "value contains[c] '#{text}'"
|
100
|
-
|
101
|
-
execute_script(js).first
|
102
|
-
end
|
103
|
-
|
104
|
-
# Return all elements matching text.
|
105
|
-
# @param text [String] the text to search for
|
106
|
-
# @return [Array<Element>] all matching elements
|
107
|
-
def texts text
|
108
|
-
# XPath //* is not implemented on iOS
|
109
|
-
# https://github.com/appium/appium/issues/430
|
110
|
-
js = all_ele_js "value contains[c] '#{text}'"
|
111
|
-
|
112
|
-
execute_script js
|
113
|
-
end
|
114
|
-
|
115
|
-
# Return the first element matching name.
|
116
|
-
# on Android name is content description
|
117
|
-
# on iOS name is the accessibility label or the text.
|
118
|
-
# @param name [String] the name to search for
|
119
|
-
# @return [Element] the first matching element
|
120
|
-
def name text
|
121
|
-
js = first_ele_js "name contains[c] '#{text}' || label contains[c] '#{text}'"
|
122
|
-
|
123
|
-
execute_script(js).first
|
124
|
-
end
|
125
|
-
|
126
|
-
# Return all elements matching name.
|
127
|
-
# on Android name is content description
|
128
|
-
# on iOS name is the accessibility label or the text.
|
129
|
-
# @param name [String] the name to search for
|
130
|
-
# @return [Array<Element>] all matching elements
|
131
|
-
def names text
|
132
|
-
# find_elements :name is not the same as on Android.
|
133
|
-
# it's case sensitive and exact on iOS and not on Android.
|
134
|
-
# https://github.com/appium/appium/issues/379
|
135
|
-
js = all_ele_js "name contains[c] '#{text}' || label contains[c] '#{text}''"
|
136
|
-
|
137
|
-
execute_script js
|
138
|
-
end
|
139
|
-
|
140
|
-
end # if ios
|
@@ -1,93 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
if $os == :ios
|
3
|
-
# UIATextField & UIASecureTextField methods
|
4
|
-
#
|
5
|
-
# Find textfield and then secure elements in one server call
|
6
|
-
# to match Android.
|
7
|
-
|
8
|
-
# Get an array of textfield texts.
|
9
|
-
# @return [Array<String>]
|
10
|
-
def textfields
|
11
|
-
find_2_eles_attr :textfield, :secure, :text
|
12
|
-
end
|
13
|
-
|
14
|
-
# Get an array of textfield elements.
|
15
|
-
# @return [Array<Textfield>]
|
16
|
-
def e_textfields
|
17
|
-
execute_script textfield_js
|
18
|
-
end
|
19
|
-
|
20
|
-
# Get the first textfield element.
|
21
|
-
# @return [Textfield]
|
22
|
-
def first_textfield
|
23
|
-
js = textfield_js 'r = r.length > 0 ? $(r[0]) : r;'
|
24
|
-
execute_script(js).first
|
25
|
-
end
|
26
|
-
|
27
|
-
# Get the last textfield element.
|
28
|
-
# @return [Textfield]
|
29
|
-
def last_textfield
|
30
|
-
js = textfield_js 'r = r.length > 0 ? $(r[r.length - 1]) : r;'
|
31
|
-
execute_script(js).first
|
32
|
-
end
|
33
|
-
|
34
|
-
# Get the first textfield that matches text.
|
35
|
-
# @param text [String, Integer] the text to match exactly. If int then the textfield at that index is returned.
|
36
|
-
# @return [Textfield]
|
37
|
-
def textfield text
|
38
|
-
# Don't use ele_index because that only works on one element type.
|
39
|
-
# iOS needs to combine textfield and secure to match Android.
|
40
|
-
if text.is_a? Numeric
|
41
|
-
js = textfield_js 'r = r.length > 0 ? $(r[#{text}]) : r;'
|
42
|
-
return execute_script(js).first
|
43
|
-
end
|
44
|
-
|
45
|
-
textfield_include text
|
46
|
-
end
|
47
|
-
|
48
|
-
# Get the first textfield that includes text.
|
49
|
-
# @param text [String] the text the textfield must include
|
50
|
-
# @return [Textfield]
|
51
|
-
def textfield_include text
|
52
|
-
js = %Q(
|
53
|
-
var t = au.getElementsByXpath('textfield[contains(@text, "#{text}")]').value;
|
54
|
-
var s = au.getElementsByXpath('secure[contains(@text, "#{text}")]').value;
|
55
|
-
t.concat(s)[0];
|
56
|
-
)
|
57
|
-
|
58
|
-
puts js if defined?(Pry)
|
59
|
-
|
60
|
-
execute_script js
|
61
|
-
end
|
62
|
-
|
63
|
-
# Get the first textfield that exactly matches text.
|
64
|
-
# @param text [String] the text the textfield must exactly match
|
65
|
-
# @return [Textfield]
|
66
|
-
def textfield_exact text
|
67
|
-
# find_ele_by_text :textfield, text
|
68
|
-
js = %Q(
|
69
|
-
var t = au.getElementsByXpath('textfield[@text="#{text}"]').value;
|
70
|
-
var s = au.getElementsByXpath('secure[@text="#{text}"]').value;
|
71
|
-
t.concat(s)[0];
|
72
|
-
)
|
73
|
-
|
74
|
-
puts js if defined?(Pry)
|
75
|
-
|
76
|
-
execute_script js
|
77
|
-
end
|
78
|
-
|
79
|
-
private
|
80
|
-
|
81
|
-
# Return combined lookup of textfield and secure
|
82
|
-
# with an optional filter. $() wrap is required for .each
|
83
|
-
def textfield_js filter=''
|
84
|
-
%Q(
|
85
|
-
var t = au.lookup('textfield');
|
86
|
-
var s = au.lookup('secure');
|
87
|
-
var r = $(t.concat(s));
|
88
|
-
#{filter}
|
89
|
-
au._returnElems(r);
|
90
|
-
)
|
91
|
-
end
|
92
|
-
|
93
|
-
end # if $os
|
@@ -1,43 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
# UIAStaticText methods
|
3
|
-
|
4
|
-
# s_ prefix for static_text to avoid conflict with generic text methods.
|
5
|
-
|
6
|
-
# Get an array of text texts.
|
7
|
-
# @return [Array<String>]
|
8
|
-
def s_texts
|
9
|
-
find_eles_attr :text, :text
|
10
|
-
end
|
11
|
-
|
12
|
-
# Get an array of text elements.
|
13
|
-
# @return [Array<Text>]
|
14
|
-
def s_e_texts
|
15
|
-
find_eles :text
|
16
|
-
end
|
17
|
-
|
18
|
-
# Get the first text element.
|
19
|
-
# @return [Text]
|
20
|
-
def s_first_text
|
21
|
-
first_ele :text
|
22
|
-
end
|
23
|
-
|
24
|
-
# Get the last text element
|
25
|
-
# @return [Text]
|
26
|
-
def s_last_text
|
27
|
-
last_ele :text
|
28
|
-
end
|
29
|
-
|
30
|
-
# Get the first element that includes text.
|
31
|
-
# @param text [String, Integer] the text to find. If int then the text at that index is returned.
|
32
|
-
# @return [Text]
|
33
|
-
def s_text text
|
34
|
-
return ele_index :text, text if text.is_a? Numeric
|
35
|
-
find_ele_by_text_include :text, text
|
36
|
-
end
|
37
|
-
|
38
|
-
# Get the first textfield that matches text.
|
39
|
-
# @param text [String] the text that the tag must match
|
40
|
-
# @return [Text]
|
41
|
-
def s_text_exact text
|
42
|
-
find_ele_by_text :text, text
|
43
|
-
end
|