appium_lib 0.0.25 → 0.0.26

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- Y2ExYzEwMjM4NDA2N2FlMjAwNTY3MDA2ZmEwZmRkMzk0MDVkYjA4MQ==
4
+ ODllNGVkMzc4M2RhNDMzYjE5Yzc4NDM3MTdhMzYzNjRmMDVlMGVhMQ==
5
5
  data.tar.gz: !binary |-
6
- NWYyODE1M2NlN2E5OGNiZjY3YzEyMTRhZDI0YmQ4Mjk1YWVhODg5Yw==
6
+ NjI2OGVjNjY4NWJmNTAxZjk5M2E0MmM5MDE0YWQzMjRkODRkNmI5Yg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZjQxMzFlY2EzMmU0Y2M4MjAzYmUxYzMyYmRjMDk0Mjc2MTc4OTEwNTQ2NjQ2
10
- NGRhZGFjY2RmYmJlM2Q0NTMwMDAxZDBhMDk4YjYwYmNlODQ4OTgzNWJhZjNk
11
- YjFiODAwYTgxZWVlYWY2ZTNhYWU1ZGQxMzJmYjNlNWE5ODI2N2Q=
9
+ MDdkNjIwNWUzODQzZmVkYzJlYjAwMmQ5MTdiNjUyZGUzMjNlMDVkNGE1M2Zk
10
+ ZmQwMTBhZjdmYmRlZmQ0MmNkZmVjOTRkZGJjOWRhYjJhMjcxZGU4YjFlNTgy
11
+ NDI3ODM5Mzc3NjJhODc4NmIwM2ZlZWFjODY0MDhlODliMjRiY2Q=
12
12
  data.tar.gz: !binary |-
13
- Y2U3OGZkZmZjYjFiMThmNjU1YTQwMmIwYzZkYWIyZjUzM2I2ZjMwM2FmNzM2
14
- Y2E0NTUwNGZlZmIzZmE0YjUxYzY4NWZjNzEwODY0OWZkMjg3ZmZiOWNmZmI1
15
- YzA4YmQ2YjBkOWZiYmUzM2U5NGEwY2QyMGIzNzk0OTE5ZTdjYzA=
13
+ ZmI2YWU4YmNkNTc2YzMwZmRkMTVlYTZkNWZkZmE1NTg4MWE5MDEzNDYzMzAy
14
+ M2I5YzBhODY5M2JkNTk0MjNkZWFmN2EwNzAxNGM4NjUzMmExYjFjNjY4MjJk
15
+ YjQ2OWMzZTkyMTVhYmY5MTMzMGQwNmE5OWVkOWNmM2EyNmRlOWI=
@@ -65,6 +65,9 @@ require 'alert'
65
65
  # combine secure & textfield on iOS to match Android behavior.
66
66
  $os == :ios ? require('ios/textfield') :
67
67
  require('android/textfield')
68
+
69
+ # implicit_wait default_wait
70
+ $default_wait = 30
68
71
 
69
72
  # WebDriver capabilities. Must be valid for Sauce to work.
70
73
  # https://github.com/jlipps/appium/blob/master/app/android.js
@@ -146,11 +149,8 @@ def start_driver
146
149
  # when no commands are entered after 60 seconds.
147
150
  $driver.execute_script 'mobile: setCommandTimeout', timeout: 9999
148
151
 
149
- # Must set implicit_wait to zero or $ commands will fail.
150
- # execute_script "$('button')"
151
- # $ commands fail anyway now so set implicit wait.
152
- # https://github.com/appium/appium/issues/214
153
- $driver.manage.timeouts.implicit_wait = 30
152
+ # Set implicit wait by default unless we're using Pry.
153
+ $driver.manage.timeouts.implicit_wait = $default_wait unless defined?(Pry)
154
154
 
155
155
  $driver
156
156
  end
@@ -163,12 +163,47 @@ end
163
163
  # Set implicit wait to timeout, defaults to 30.
164
164
  # @param timeout [Integer] the timeout in seconds
165
165
  # @return [void]
166
- def set_wait timeout=30
166
+ def set_wait timeout=$default_wait
167
167
  $driver.manage.timeouts.implicit_wait = timeout
168
168
  end
169
169
 
170
+ # Returns the default client side wait.
171
+ # This value is independent of what the server is using
172
+ # @return [Integer]
173
+ def get_wait
174
+ $default_wait
175
+ end
176
+
177
+ # Returns existance of element.
178
+ #
179
+ # Example:
180
+ #
181
+ # exists { button('sign in') } ? puts('true') : puts('false')
182
+ #
183
+ # @return [Boolean]
184
+ def exists &search_block
185
+ pre_check = 0
186
+ post_check = $default_wait
187
+
188
+ set_wait pre_check # set wait to zero
189
+
190
+ # the element exists unless an error is raised.
191
+ exists = true
192
+
193
+ begin
194
+ search_block.call # search for element
195
+ rescue
196
+ exists = false # error means it's not there
197
+ end
198
+
199
+ # restore wait
200
+ set_wait post_check
201
+
202
+ return exists
203
+ end
204
+
170
205
  # The same as $driver.execute_script
171
- # @return the object returned by execute_script
206
+ # @return [Object] the object returned by execute_script
172
207
  def execute_script script, *args
173
208
  $driver.execute_script script, *args
174
209
  end
@@ -0,0 +1,45 @@
1
+ # encoding: utf-8
2
+ if $os == :android
3
+
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
+ button(value).click
9
+ end
10
+
11
+ # Get the alert message text.
12
+ # @return [String]
13
+ def alert_text
14
+ get_page
15
+ end
16
+
17
+ # Accept the alert.
18
+ # The last button is considered "accept."
19
+ # @return [void]
20
+ def alert_accept
21
+ last_button.click
22
+ end
23
+
24
+ # Get the text of the alert's accept button.
25
+ # The last button is considered "accept."
26
+ # @return [String]
27
+ def alert_accept_text
28
+ last_button.text
29
+ end
30
+
31
+ # Dismiss the alert.
32
+ # The first button is considered "dismiss."
33
+ # @return [void]
34
+ def alert_dismiss
35
+ first_button.click
36
+ end
37
+
38
+ # Get the text of the alert's dismiss button.
39
+ # The first button is considered "dismiss."
40
+ # @return [String]
41
+ def alert_dismiss_text
42
+ first_button.text
43
+ end
44
+
45
+ end # if $os == :android
@@ -0,0 +1,47 @@
1
+ # encoding: utf-8
2
+ if $os == :android
3
+ =begin
4
+ name, names, text, text should match substring and case insensitive.
5
+
6
+ In Android //* is used to find partial case insensitive text matches.
7
+ //* is not currently implemented in iOS.
8
+
9
+ find_element :name by default uses a partial case insensitive match.
10
+ On iOS the default is an exact name match.
11
+ =end
12
+
13
+ # Return the first element matching text.
14
+ # @param text [String] the text to search for
15
+ # @return [Element] the first matching element
16
+ def text text
17
+ # TODO: Use XPath index once it's implemented
18
+ # https://github.com/appium/appium/issues/295
19
+ texts(text).first
20
+ end
21
+
22
+ # Return all elements matching text.
23
+ # @param text [String] the text to search for
24
+ # @return [Array<Element>] all matching elements
25
+ def texts text
26
+ $driver.find_elements :xpath, "//*[contains(@text, '#{text}')]"
27
+ end
28
+
29
+ # Return the first element matching name.
30
+ # on Android name is content description
31
+ # on iOS name is the accessibility label or the text.
32
+ # @param name [String] the name to search for
33
+ # @return [Element] the first matching element
34
+ def name name
35
+ $driver.find_element :name, name
36
+ end
37
+
38
+ # Return all elements matching name.
39
+ # on Android name is content description
40
+ # on iOS name is the accessibility label or the text.
41
+ # @param name [String] the name to search for
42
+ # @return [Array<Element>] all matching elements
43
+ def names name
44
+ $driver.find_elements :name, name
45
+ end
46
+
47
+ end # if $os == :android
@@ -1,7 +1,6 @@
1
1
  # encoding: utf-8
2
- # UIATextField methods
3
-
4
2
  if $os == :android
3
+ # UIATextField methods
5
4
 
6
5
  # Get an array of textfield texts.
7
6
  # @return [Array<String>]
@@ -42,4 +41,4 @@ def textfield_include text
42
41
  find_ele_by_text_include :textfield, text
43
42
  end
44
43
 
45
- end # if $os
44
+ end # if $os == :android
@@ -1,62 +1,24 @@
1
1
  # encoding: utf-8
2
2
  # UIAButton methods
3
3
 
4
- =begin
5
- Method Signatures:
6
-
7
- button( text, number = -1 )
8
- buttons( text = nil )
9
- button_include( text )
10
- buttons_include( text )
11
- first_button
12
- last_button
13
-
14
- Examples:
15
-
16
- button 'text' # 1st button exactly matching text
17
- button 'text', 2 # 2nd button exactly matching text
18
-
19
- buttons # text of all buttons.
20
- buttons 'text' # all buttons exactly matching text
21
-
22
- button_include 'text' # the first button that includes text
23
- buttons_include 'text' # all buttons that include text
24
-
25
- first_button # the first button
26
- last_button # the last button
27
- =end
28
-
29
4
  # Find a button by text and optionally number.
30
5
  # @param text [String, Integer] the text to exactly match. If int then the button at that index is returned.
31
6
  # @param number [Integer] the occurance of the button matching text. Defaults to the first button.
32
7
  # @return [Button] the button found with text and matching number
33
8
  def button text, number=0
9
+ # return button at index.
34
10
  return ele_index :button, text if text.is_a? Numeric
35
11
 
36
- number >= 1 ? button_text_num( text, number ) :
37
- button_text( text )
12
+ number >= 1 ? button_num( text, number ) :
13
+ find_ele_by_text_include( :button, text )
38
14
  end
39
15
 
40
16
  # Get an array of button texts or button elements if text is provided.
41
17
  # @param text [String] the text to exactly match
42
18
  # @return [Array<String>, Array<Buttons>] either an array of button texts or an array of button elements if text is provided.
43
19
  def buttons text=nil
44
- text == nil ? find_eles_attr(:button, :text) :
45
- find_ele_by_text(:button, text)
46
- end
47
-
48
- # Get the first button that includes text.
49
- # @param text [String] the text that the element must include
50
- # @return [Button]
51
- def button_include text
52
- find_ele_by_text_include :button, text
53
- end
54
-
55
- # Get all buttons that include text.
56
- # @param text [String] the text that the element must include
57
- # @return [Array<Button>]
58
- def buttons_include text
59
- find_eles_by_text_include :button, text
20
+ text == nil ? find_eles_attr( :button, :text ) :
21
+ find_eles_by_text_include( :button, text )
60
22
  end
61
23
 
62
24
  # Get the first button element.
@@ -71,16 +33,28 @@ def last_button
71
33
  last_ele :button
72
34
  end
73
35
 
74
- # -- prefer above methods before using these.
75
- private
76
-
77
36
  # Get the first button element that exactly matches text.
78
37
  # @param text [String] the text to match exactly
79
38
  # @return [Button]
80
- def button_text text
39
+ def button_exact text
81
40
  find_ele_by_text :button, text
82
41
  end
83
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
+ #
84
58
  # Get the button element exactly matching text and
85
59
  # occurrence. number=2 means the 2nd occurrence.
86
60
  #
@@ -92,24 +66,18 @@ end
92
66
  # so if there's no button found at number then
93
67
  # return the first button.
94
68
  #
95
- # @param text [String] the text to match exactly
69
+ # @param text [String] the text to match
96
70
  # @param number [Integer] the button occurance to return. 1 = first button
97
- # @return [Button] the button that exactly matches text and number
98
- def button_text_num text, number=1
71
+ # @return [Button] the button that matches text and number
72
+ def button_num text, number=1
99
73
  raise "Number must be >= 1" if number <= 0
100
74
  number = number - 1 # zero indexed
101
75
 
102
76
  result = nil
103
77
 
104
- elements = find_eles_by_text :button, text
78
+ elements = buttons text
105
79
  elements.size > number ? result = elements[number]
106
80
  : result = elements.first
107
81
 
108
82
  result
109
- end
110
-
111
- # Get an array of button elements.
112
- # @return [Array<Button>]
113
- def e_buttons
114
- find_eles :button
115
- end
83
+ end
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
-
2
+ if $os == :ios
3
3
  # iOS only
4
4
  # Tap the alert button identified by value.
5
5
  # @param value [Integer, String] either an integer index of the button or the button's name
@@ -44,4 +44,6 @@ def alert_dismiss_text
44
44
  return if a.nil?
45
45
  b = a.find_elements(:tag_name, :button)
46
46
  b.first.text if b && b.size >= 1
47
- end
47
+ end
48
+
49
+ end # if $os == :ios
@@ -0,0 +1,55 @@
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
+ =end
9
+
10
+ # Return the first element matching text.
11
+ # @param text [String] the text to search for
12
+ # @return [Element] the first matching element
13
+ def text text
14
+ # returnElems requires a wrapped $(element).
15
+ js = %Q(
16
+ var element = $(au.mainWindow.elements().firstWithPredicate("name contains[c] '#{text}'"));
17
+ au._returnElems(element);
18
+ )
19
+
20
+ execute_script(js).first
21
+ end
22
+
23
+ # Return all elements matching text.
24
+ # @param text [String] the text to search for
25
+ # @return [Array<Element>] all matching elements
26
+ def texts text
27
+ # returnElems requires a wrapped $(element).
28
+ # must call toArray when using withPredicate instead of firstWithPredicate.
29
+ js = %Q(
30
+ var a = au.mainWindow.elements().withPredicate("name contains[c] '#{text}'").toArray();
31
+ au._returnElems($(a));
32
+ )
33
+
34
+ execute_script js
35
+ end
36
+
37
+ # Return the first element matching name.
38
+ # on Android name is content description
39
+ # on iOS name is the accessibility label or the text.
40
+ # @param name [String] the name to search for
41
+ # @return [Element] the first matching element
42
+ def name name
43
+ text name
44
+ end
45
+
46
+ # Return all elements matching name.
47
+ # on Android name is content description
48
+ # on iOS name is the accessibility label or the text.
49
+ # @param name [String] the name to search for
50
+ # @return [Array<Element>] all matching elements
51
+ def names name
52
+ texts name
53
+ end
54
+
55
+ end # if ios
@@ -1,11 +1,10 @@
1
1
  # encoding: utf-8
2
+ if $os == :ios
2
3
  # UIATextField & UIASecureTextField methods
3
4
  #
4
5
  # Find textfield and then secure elements in one server call
5
6
  # to match Android.
6
7
 
7
- if $os == :ios
8
-
9
8
  # Get an array of textfield texts.
10
9
  # @return [Array<String>]
11
10
  def textfields
@@ -1,41 +1,43 @@
1
1
  # encoding: utf-8
2
2
  # UIAStaticText methods
3
3
 
4
+ # s_ prefix for static_text to avoid conflict with generic text methods.
5
+
4
6
  # Get an array of text texts.
5
7
  # @return [Array<String>]
6
- def texts
8
+ def s_texts
7
9
  find_eles_attr :text, :text
8
10
  end
9
11
 
10
12
  # Get an array of text elements.
11
13
  # @return [Array<Text>]
12
- def e_texts
14
+ def s_e_texts
13
15
  find_eles :text
14
16
  end
15
17
 
16
18
  # Get the first text element.
17
19
  # @return [Text]
18
- def first_text
20
+ def s_first_text
19
21
  first_ele :text
20
22
  end
21
23
 
22
24
  # Get the last text element
23
25
  # @return [Text]
24
- def last_text
26
+ def s_last_text
25
27
  last_ele :text
26
28
  end
27
29
 
28
- # Get the first element that matches text.
29
- # @param text [String, Integer] the text to find exactly. If int then the text at that index is returned.
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.
30
32
  # @return [Text]
31
- def text text
33
+ def s_text text
32
34
  return ele_index :text, text if text.is_a? Numeric
33
- find_ele_by_text :text, text
35
+ find_ele_by_text_include :text, text
34
36
  end
35
37
 
36
- # Get the first textfield that includes text.
37
- # @param text [String] the text that the tag must include
38
+ # Get the first textfield that matches text.
39
+ # @param text [String] the text that the tag must match
38
40
  # @return [Text]
39
- def text_include text
40
- find_ele_by_text_include :text, text
41
+ def s_text_exact text
42
+ find_ele_by_text :text, text
41
43
  end
@@ -29,24 +29,6 @@ def wait &block
29
29
  result
30
30
  end
31
31
 
32
- # Return the first element matching name.
33
- # on Android name is content description
34
- # on iOS name is the accessibility label or the text.
35
- # @param name [String] the name to search for
36
- # @return [Element] the first matching element
37
- def name name
38
- $driver.find_element :name, name
39
- end
40
-
41
- # Return all element matching name.
42
- # on Android name is content description
43
- # on iOS name is the accessibility label or the text.
44
- # @param name [String] the name to search for
45
- # @return [Array<Element>] all matching elements
46
- def names name
47
- $driver.find_elements :name, name
48
- end
49
-
50
32
  # Presses the back button on Android.
51
33
  # @return [void]
52
34
  def back
@@ -234,7 +216,7 @@ def get_inspect
234
216
  results.each { |e|
235
217
  out += e[:class].split('.').last + "\n"
236
218
  out += " text: #{e[:text]}\n" unless e[:text].nil?
237
- out += " desc: #{e[:desc]}\n" unless e[:desc].nil?
219
+ out += " name: #{e[:desc]}\n" unless e[:desc].nil?
238
220
  }
239
221
  out
240
222
  end
@@ -244,4 +226,4 @@ end
244
226
  def page
245
227
  puts get_inspect
246
228
  nil
247
- end
229
+ end
@@ -12,20 +12,17 @@ class Selenium::WebDriver::Element
12
12
  self.attribute :name
13
13
  end
14
14
 
15
- # Fixes NoMethodError: undefined method `type' for #<Selenium::WebDriver::Element
16
- def type
17
- self.attribute :type
18
- end
19
-
15
+ # Use tag_name to get element's type.
16
+ #
20
17
  # Tag name appears to be the same as type.
21
18
  #
22
19
  # Fixes Selenium::WebDriver::Error::UnknownError: Not yet implemented
23
20
  def tag_name
24
- type
21
+ self.attribute :type
25
22
  end
26
23
 
27
24
  # Cross platform way of entering text into a textfield
28
- def set_value text
25
+ def type text
29
26
  # enter text then tap window to hide the keyboard.
30
27
  js = %Q(
31
28
  au.getElement('#{self.ref}').setValue('#{text}');
@@ -35,7 +32,7 @@ class Selenium::WebDriver::Element
35
32
  end if $os == :ios
36
33
 
37
34
  # Cross platform way of entering text into a textfield
38
- def set_value text
35
+ def type text
39
36
  self.send_keys text
40
37
  end if $os == :android
41
38
 
@@ -1,4 +1,4 @@
1
1
  module AppiumLib
2
- VERSION = '0.0.25' unless defined? ::AppiumLib::VERSION
3
- DATE = '2013-03-28' unless defined? ::AppiumLib::DATE
2
+ VERSION = '0.0.26' unless defined? ::AppiumLib::VERSION
3
+ DATE = '2013-04-04' unless defined? ::AppiumLib::DATE
4
4
  end
data/readme.md CHANGED
@@ -4,6 +4,7 @@
4
4
  - [Documentation for appium_lib](http://www.rubydoc.info/github/appium/ruby_lib/master/frames)
5
5
 
6
6
  Helper methods for writing cross platform (iPad, iPhone, Android) tests in Ruby using Appium.
7
+ There's also an [Appium Ruby Console](https://github.com/appium/ruby_console) which uses this lib.
7
8
 
8
9
  Make sure you're using Ruby 1.9.3+ with upgraded rubygems and bundler.
9
10
 
data/release_notes.md ADDED
@@ -0,0 +1,4 @@
1
+ #### master
2
+
3
+ - Start driver will no longer default to implicit wait when used in Pry.
4
+ [*](https://github.com/appium/ruby_lib/commit/2e71e477962c70113b556700cf08c74060d77370)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appium_lib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.25
4
+ version: 0.0.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - code@bootstraponline.com
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-28 00:00:00.000000000 Z
11
+ date: 2013-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: selenium-webdriver
@@ -66,9 +66,12 @@ files:
66
66
  - appium_lib.gemspec
67
67
  - lib/appium_lib.rb
68
68
  - lib/appium_lib/console.rb
69
- - lib/appium_lib/element/alert.rb
69
+ - lib/appium_lib/element/android/alert.rb
70
+ - lib/appium_lib/element/android/generic.rb
70
71
  - lib/appium_lib/element/android/textfield.rb
71
72
  - lib/appium_lib/element/button.rb
73
+ - lib/appium_lib/element/ios/alert.rb
74
+ - lib/appium_lib/element/ios/generic.rb
72
75
  - lib/appium_lib/element/ios/textfield.rb
73
76
  - lib/appium_lib/element/text.rb
74
77
  - lib/appium_lib/element/window.rb
@@ -76,6 +79,7 @@ files:
76
79
  - lib/appium_lib/patch.rb
77
80
  - lib/appium_lib/version.rb
78
81
  - readme.md
82
+ - release_notes.md
79
83
  homepage: https://github.com/appium/ruby_lib
80
84
  licenses:
81
85
  - http://www.apache.org/licenses/LICENSE-2.0.txt