Skip to content

Commit 3582d34

Browse files
Fix iOS common/element/button
1 parent 67f719e commit 3582d34

File tree

4 files changed

+94
-5
lines changed

4 files changed

+94
-5
lines changed

ios_tests/lib/ios/specs/common/element/button.rb

+5-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def gray
2929
end
3030

3131
t 'buttons' do
32-
exp = ['Back', 'Back', 'Gray', 'Right pointing arrow', 'Rounded', 'Custom Text', 'More info', 'More info', 'More info', 'Add contact']
32+
exp = ['Back', 'UINavigationBarBackIndicatorDefault.png', 'Gray', 'Right pointing arrow', 'Rounded', 'Custom Text', 'More info', 'More info', 'More info', 'Add contact']
3333
buttons.must_equal exp
3434
end
3535

@@ -54,8 +54,10 @@ def gray
5454
end
5555

5656
t 'button_num' do
57-
# select the second button containing 'in'
58-
button_num('in', 2).name.must_equal 'More info'
57+
# select x button containing 'in'
58+
button_num('in', 1).name.must_equal 'UINavigationBarBackIndicatorDefault.png'
59+
button_num('in', 2).name.must_equal 'Right pointing arrow'
60+
button_num('in', 3).name.must_equal 'More info'
5961
end
6062

6163
t 'after_last' do

lib/appium_lib/common/element/button.rb renamed to lib/appium_lib/android/element/button.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# encoding: utf-8
22
# UIAButton methods
33
module Appium
4-
module Common
4+
module Android
55
# Find a button by text and optionally number.
66
# @param text [String, Integer] the text to exactly match. If int then the button at that index is returned.
77
# @param number [Integer] the occurrence of the button matching text. Defaults to the first button.

lib/appium_lib/driver.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111
require_relative 'common/helper'
1212
require_relative 'common/patch'
1313
require_relative 'common/version'
14-
require_relative 'common/element/button'
1514
require_relative 'common/element/window'
1615

1716
# ios
1817
require_relative 'ios/helper'
1918
require_relative 'ios/patch'
19+
2020
require_relative 'ios/element/alert'
21+
require_relative 'ios/element/button'
2122
require_relative 'ios/element/generic'
2223
require_relative 'ios/element/textfield'
2324
require_relative 'ios/element/text'
@@ -28,6 +29,7 @@
2829
require_relative 'android/helper'
2930
require_relative 'android/patch'
3031
require_relative 'android/element/alert'
32+
require_relative 'android/element/button'
3133
require_relative 'android/element/generic'
3234
require_relative 'android/element/textfield'
3335
require_relative 'android/element/text'

lib/appium_lib/ios/element/button.rb

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# encoding: utf-8
2+
# UIAButton methods
3+
module Appium
4+
module Ios
5+
# Find a button by text and optionally number.
6+
# @param text [String, Integer] the text to exactly match. If int then the button at that index is returned.
7+
# @param number [Integer] the occurrence of the button matching text. Defaults to the first button.
8+
# @return [Button] the button found with text and matching number
9+
def button text, number=0
10+
# return button at index.
11+
return ele_index :button, text if text.is_a? Numeric
12+
13+
number >= 1 ? button_num(text, number) :
14+
find_ele_by_name_include(:button, text)
15+
end
16+
17+
# Get an array of button texts or button elements if text is provided.
18+
# @param text [String] the text to exactly match
19+
# @return [Array<String>, Array<Buttons>] either an array of button texts or an array of button elements if text is provided.
20+
def buttons text=nil
21+
text == nil ? find_eles_attr(:button, :name) :
22+
find_eles_by_name_include(:button, text)
23+
end
24+
25+
# Get the first button element.
26+
# @return [Button]
27+
def first_button
28+
first_ele :button
29+
end
30+
31+
# Get the last button element.
32+
# @return [Button]
33+
def last_button
34+
last_ele :button
35+
end
36+
37+
# Get the first button element that exactly matches text.
38+
# @param text [String] the text to match exactly
39+
# @return [Button]
40+
def button_exact text
41+
find_ele_by_name :button, text
42+
end
43+
44+
# Get all button elements that exactly match text.
45+
# @param text [String] the text to match exactly
46+
# @return [Array<Button>]
47+
def buttons_exact text
48+
find_eles_by_name :button, text
49+
end
50+
51+
# Get an array of button elements.
52+
# @return [Array<Button>]
53+
def e_buttons
54+
find_eles :button
55+
end
56+
57+
# Expected to be called via button method.
58+
#
59+
# Get the button element exactly matching text and
60+
# occurrence. number=2 means the 2nd occurrence.
61+
#
62+
# find the second Sign In button
63+
#
64+
# b = e_button 'Sign In', 2
65+
#
66+
# Button order will change in iOS vs Android
67+
# so if there's no button found at number then
68+
# return the first button.
69+
#
70+
# @param text [String] the text to match
71+
# @param number [Integer] the button occurance to return. 1 = first button
72+
# @return [Button] the button that matches text and number
73+
def button_num text, number=1
74+
raise 'Number must be >= 1' if number <= 0
75+
number = number - 1 # zero indexed
76+
result = nil
77+
78+
elements = buttons text
79+
elements.size > number ? result = elements[number]
80+
: result = elements.first
81+
82+
result
83+
end
84+
end # module Common
85+
end # module Appium

0 commit comments

Comments
 (0)