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