appium_lib 0.4.2 → 0.5.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.
@@ -35,6 +35,7 @@ module Appium
35
35
  100 => [ 'getStringAttribute("name")', 'GET_NAME', 100]
36
36
  }
37
37
 
38
+ # @private
38
39
  def dynamic_code_to_string code, value=false
39
40
  result = @@map[code].first
40
41
  return result unless value
@@ -39,9 +39,13 @@ module Appium::Android
39
39
  # Find all elements matching the attribute
40
40
  # On android, assume the attr is name (which falls back to text).
41
41
  #
42
+ # ```ruby
43
+ # find_eles_attr :text
44
+ # ```
45
+ #
42
46
  # @param tag_name [String] the tag name to search for
43
47
  # @return [Element]
44
- def find_eles_attr tag_name
48
+ def find_eles_attr tag_name, attribute=nil
45
49
  =begin
46
50
  sel1 = [ [4, 'android.widget.Button'], [100] ]
47
51
  sel2 = [ [4, 'android.widget.ImageButton'], [100] ]
@@ -125,8 +129,36 @@ module Appium::Android
125
129
  out
126
130
  end
127
131
 
132
+ # Count all classes on screen and print to stdout.
133
+ # Useful for appium_console.
134
+ def page_class
135
+ r = []
136
+ run_internal = lambda do |node|
137
+ if node.kind_of? Array
138
+ node.each { |node| run_internal.call node }
139
+ return
140
+ end
141
+
142
+ keys = node.keys
143
+ return if keys.empty?
144
+ r.push node['@class'] if keys.include?('@class')
145
+
146
+ run_internal.call node['node'] if keys.include?('node')
147
+ end
148
+ json = get_source
149
+ run_internal.call json['hierarchy']
150
+
151
+ r = r.sort
152
+ r.uniq.each do |ele|
153
+ print r.count(ele)
154
+ puts "x #{ele}\n"
155
+ end
156
+ nil
157
+ end
158
+
128
159
  # Android only.
129
160
  # Returns a string containing interesting elements.
161
+ # If an element has no content desc or text, then it's not returned by this method.
130
162
  # @return [String]
131
163
  def get_android_inspect
132
164
  # @private
@@ -17,13 +17,13 @@ module Appium::Common
17
17
 
18
18
  # Get the first text element.
19
19
  # @return [Text]
20
- def s_first_text
20
+ def first_s_text
21
21
  first_ele :text
22
22
  end
23
23
 
24
24
  # Get the last text element
25
25
  # @return [Text]
26
- def s_last_text
26
+ def last_s_text
27
27
  last_ele :text
28
28
  end
29
29
 
@@ -25,7 +25,8 @@ module Appium::Common
25
25
  # Example: wait { name('back').click }
26
26
  #
27
27
  # Give up after 30 seconds.
28
- # @param max_wait [Integer] the maximum time in seconds to wait for
28
+ # @param max_wait [Integer] the maximum time in seconds to wait for.
29
+ # Note that max wait 0 means infinity.
29
30
  # @param interval [Float] the time in seconds to wait after calling the block
30
31
  # @param block [Block] the block to call
31
32
  # @return [Object] the result of block.call
@@ -187,17 +188,17 @@ module Appium::Common
187
188
  JSON.parse @driver.page_source, max_nesting: 9999
188
189
  end
189
190
 
190
- # Returns the first element that matches name
191
+ # Returns the first element that exactly matches name
191
192
  #
192
- # @param name [String] the name to match
193
+ # @param name [String] the name to exactly match
193
194
  # @return [Element]
194
195
  def find_name name
195
196
  find_element :name, name
196
197
  end
197
198
 
198
- # Returns all elements that match name
199
+ # Returns all elements that exactly match name
199
200
  #
200
- # @param name [String] the name to match
201
+ # @param name [String] the name to exactly match
201
202
  # @return [Array<Element>]
202
203
  def find_names name
203
204
  find_elements :name, name
@@ -3,12 +3,14 @@
3
3
  # Add status to WebDriver
4
4
  # https://code.google.com/p/selenium/issues/detail?id=5669
5
5
  class Selenium::WebDriver::Driver
6
+ # @private
6
7
  def status
7
8
  bridge.status
8
9
  end
9
10
  end
10
11
 
11
12
  class Selenium::WebDriver::Remote::Bridge
13
+ # @private
12
14
  def status
13
15
  raw_execute :status
14
16
  end
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  module Appium
3
3
  # Version and Date are defined on the 'Appium' module, not 'Appium::Common'
4
- VERSION = '0.4.2' unless defined? ::Appium::VERSION
5
- DATE = '2013-05-20' unless defined? ::Appium::DATE
4
+ VERSION = '0.5.0' unless defined? ::Appium::VERSION
5
+ DATE = '2013-05-24' unless defined? ::Appium::DATE
6
6
  end
@@ -4,6 +4,55 @@ Based on simple_test.rb
4
4
  https://github.com/appium/appium/blob/82995f47408530c80c3376f4e07a1f649d96ba22/sample-code/examples/ruby/simple_test.rb
5
5
  https://github.com/appium/appium/blob/c58eeb66f2d6fa3b9a89d188a2e657cca7cb300f/LICENSE
6
6
  =end
7
+
8
+ # Load appium.txt (toml format) into system ENV
9
+ # the basedir of this file + appium.txt is what's used
10
+ # @param opts [Hash] file: '/path/to/appium.txt', verbose: true
11
+ # @return [nil]
12
+ def load_appium_txt opts
13
+ raise 'opts must be a hash' unless opts.kind_of? Hash
14
+ opts.each_pair { |k,v| opts[k.to_s.downcase.strip.intern] = v }
15
+ opts = {} if opts.nil?
16
+ file = opts.fetch :file, nil
17
+ raise 'Must pass file' unless file
18
+ verbose = opts.fetch :verbose, false
19
+ # Check for env vars in .txt
20
+ toml = File.expand_path File.join File.dirname(file), 'appium.txt'
21
+ puts "appium.txt path: #{toml}" if verbose
22
+ # @private
23
+ def update data, *args
24
+ args.each do |name|
25
+ var = data[name]
26
+ ENV[name] = var if var
27
+ end
28
+ end
29
+
30
+ toml_exists = File.exists? toml
31
+ puts "Exists? #{toml_exists}" if verbose
32
+
33
+ if toml_exists
34
+ require 'toml'
35
+ require 'ap'
36
+ puts "Loading #{toml}" if verbose
37
+
38
+ # bash requires A="OK"
39
+ # toml requires A = "OK"
40
+ #
41
+ # A="OK" => A = "OK"
42
+ data = File.read(toml).gsub /([^\s])\=(")/, "\\1 = \\2"
43
+ data = TOML::Parser.new(data).parsed
44
+ ap data unless data.empty?
45
+
46
+ update data, 'APP_PATH', 'APP_APK', 'APP_PACKAGE',
47
+ 'APP_ACTIVITY', 'APP_WAIT_ACTIVITY',
48
+ 'SELENDROID'
49
+
50
+ # Ensure app path is absolute
51
+ ENV['APP_PATH'] = File.expand_path ENV['APP_PATH'] if ENV['APP_PATH']
52
+ end
53
+ nil
54
+ end
55
+
7
56
  module Appium
8
57
  add_to_path __FILE__
9
58
 
@@ -13,7 +62,6 @@ module Appium
13
62
  require 'common/helper'
14
63
  require 'common/patch'
15
64
  require 'common/version'
16
- require 'common/dynamic'
17
65
  require 'common/element/button'
18
66
  require 'common/element/text'
19
67
  require 'common/element/window'
@@ -26,6 +74,7 @@ module Appium
26
74
  require 'ios/element/textfield'
27
75
 
28
76
  # android
77
+ require 'android/dynamic'
29
78
  require 'android/helper'
30
79
  require 'android/patch'
31
80
  require 'android/element/alert'
@@ -35,9 +84,9 @@ module Appium
35
84
  class Driver
36
85
  @@loaded = false
37
86
 
38
- attr_reader :app_path, :app_name, :app_package, :app_activity,
39
- :app_wait_activity, :sauce_username, :sauce_access_key,
40
- :port, :os, :debug
87
+ attr_reader :default_wait, :app_path, :app_name, :selendroid,
88
+ :app_package, :app_activity, :app_wait_activity,
89
+ :sauce_username, :sauce_access_key, :port, :os, :debug
41
90
  # Creates a new driver.
42
91
  #
43
92
  # ```ruby
@@ -63,17 +112,17 @@ module Appium
63
112
  # Appium::Driver.new(apk).start_driver
64
113
  # ```
65
114
  #
66
- # @param options [Object] A hash containing various options.
115
+ # @param opts [Object] A hash containing various options.
67
116
  # @return [Driver]
68
- def initialize options={}
117
+ def initialize opts={}
69
118
  # quit last driver
70
119
  $driver.driver_quit if $driver
71
-
72
- opts = {}
120
+ opts = {} if opts.nil?
73
121
  # convert to downcased symbols
74
- options.each_pair { |k,v| opts[k.to_s.downcase.strip.intern] = v }
122
+ opts.each_pair { |k,v| opts[k.to_s.downcase.strip.intern] = v }
123
+
124
+ @default_wait = opts.fetch :wait, 30
75
125
 
76
- opts = {} if opts.nil?
77
126
  # Path to the .apk, .app or .app.zip.
78
127
  # The path can be local or remote for Sauce.
79
128
  @app_path = opts.fetch :app_path, ENV['APP_PATH']
@@ -122,9 +171,11 @@ module Appium
122
171
  patch_webdriver_element
123
172
 
124
173
  # enable debug patch
125
- @debug = opts.fetch :debug, defined?(Pry)
126
-
174
+ # !!'constant' == true
175
+ @debug = opts.fetch :debug, !!defined?(Pry)
176
+ puts "Debug is: #{@debug}"
127
177
  if @debug
178
+ ap opts unless opts.empty?
128
179
  puts "OS is: #{@os}"
129
180
  patch_webdriver_bridge
130
181
  end
@@ -198,15 +249,15 @@ module Appium
198
249
  # Converts environment variable APP_PATH to an absolute path.
199
250
  # @return [String] APP_PATH as an absolute path
200
251
  def absolute_app_path
201
- raise 'APP_PATH environment variable not set!' if @app_path.nil? || @app_path.empty?
202
- return @app_path if @app_path.match(/^http/) # public URL for Sauce
203
- if @app_path.match(/^\//) # absolute file path
204
- raise "App doesn't exist. #{@app_path}" unless File.exist? @app_path
205
- return @app_path
206
- end
207
- file = File.join(File.dirname(__FILE__), @app_path)
208
- raise "App doesn't exist #{file}" unless File.exist? file
209
- file
252
+ raise 'APP_PATH environment variable not set!' if @app_path.nil? || @app_path.empty?
253
+ return @app_path if @app_path.match(/^http/) # public URL for Sauce
254
+ if @app_path.match(/^\//) # absolute file path
255
+ raise "App doesn't exist. #{@app_path}" unless File.exist? @app_path
256
+ return @app_path
257
+ end
258
+ file = File.join(File.dirname(__FILE__), @app_path)
259
+ raise "App doesn't exist #{file}" unless File.exist? file
260
+ file
210
261
  end
211
262
 
212
263
  # Get the server url for sauce or local based on env vars.
@@ -234,6 +285,8 @@ module Appium
234
285
 
235
286
  # Takes a png screenshot and saves to the target path.
236
287
  #
288
+ # Example: screenshot '/tmp/hi.png'
289
+ #
237
290
  # @param png_save_path [String] the full path to save the png
238
291
  # @return [void]
239
292
  def screenshot png_save_path
@@ -249,14 +302,11 @@ module Appium
249
302
 
250
303
  # Creates a new global driver and quits the old one if it exists.
251
304
  #
252
- # @param wait [Integer] seconds to wait before timing out a command. defaults to 30 seconds
253
305
  # @return [Selenium::WebDriver] the new global driver
254
- def start_driver wait=30
306
+ def start_driver
255
307
  @client = @client || Selenium::WebDriver::Remote::Http::Default.new
256
308
  @client.timeout = 999999
257
309
 
258
- @default_wait = wait
259
-
260
310
  begin
261
311
  @driver = Selenium::WebDriver.for :remote, http_client: @client, desired_capabilities: capabilities, url: server_url
262
312
  # Load touch methods. Required for Selendroid.
@@ -301,12 +351,13 @@ module Appium
301
351
  #
302
352
  # exists { button('sign in') } ? puts('true') : puts('false')
303
353
  #
354
+ # @param pre_check [Integer] the amount in seconds to set the
355
+ # wait to before checking existance
356
+ # @param post_check [Integer] the amount in seconds to set the
357
+ # wait to after checking existance
304
358
  # @param search_block [Block] the block to call
305
359
  # @return [Boolean]
306
- def exists &search_block
307
- pre_check = 0
308
- post_check = @default_wait
309
-
360
+ def exists pre_check=0, post_check=@default_wait, &search_block
310
361
  set_wait pre_check # set wait to zero
311
362
 
312
363
  # the element exists unless an error is raised.
@@ -319,7 +370,7 @@ module Appium
319
370
  end
320
371
 
321
372
  # restore wait
322
- set_wait post_check
373
+ set_wait post_check if post_check != pre_check
323
374
 
324
375
  exists
325
376
  end
@@ -1,3 +1,10 @@
1
+ #### v0.4.2 2013-05-20
2
+
3
+ - [be814c2](https://github.com/appium/ruby_lib/commit/be814c286bd55fb133f333738da9b0dcd6146b69) Release 0.4.2
4
+ - [9d2cfe8](https://github.com/appium/ruby_lib/commit/9d2cfe86b3367fd3f4551962a042fe25da1e31bd) Add page_window for Apptentive
5
+ - [e9b5e97](https://github.com/appium/ruby_lib/commit/e9b5e97baf7b6a417dc3865b7cc0c163c0165d70) Update docs
6
+
7
+
1
8
  #### v0.4.1 2013-05-20
2
9
 
3
10
  - [cd8dd73](https://github.com/appium/ruby_lib/commit/cd8dd73461d6bdb8903a8b3f5bba9ce554a44789) Release 0.4.1
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.4.2
4
+ version: 0.5.0
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-05-20 00:00:00.000000000 Z
11
+ date: 2013-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: selenium-webdriver
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: 1.8.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: toml
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.0.4
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 0.0.4
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rake
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -84,12 +98,12 @@ files:
84
98
  - docs_gen/docs_from_js.md
85
99
  - docs_gen/make_docs.rb
86
100
  - lib/appium_lib.rb
101
+ - lib/appium_lib/android/dynamic.rb
87
102
  - lib/appium_lib/android/element/alert.rb
88
103
  - lib/appium_lib/android/element/generic.rb
89
104
  - lib/appium_lib/android/element/textfield.rb
90
105
  - lib/appium_lib/android/helper.rb
91
106
  - lib/appium_lib/android/patch.rb
92
- - lib/appium_lib/common/dynamic.rb
93
107
  - lib/appium_lib/common/element/button.rb
94
108
  - lib/appium_lib/common/element/text.rb
95
109
  - lib/appium_lib/common/element/window.rb